123 lines
3.1 KiB
Bash
Executable File
123 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install TA-ProxMenu on a Proxmox VE host.
|
|
|
|
set -Eeuo pipefail
|
|
|
|
readonly INSTALL_ROOT='/opt/idssys'
|
|
readonly TAPM_DIR="${INSTALL_ROOT}/ta-proxmenu"
|
|
readonly DEFAULTS_DIR="${INSTALL_ROOT}/defaults"
|
|
readonly TAPM_REPOSITORY='https://git.scity.us/TAI/TA-ProxMenu.git'
|
|
readonly DEFAULTS_REPOSITORY='https://git.scity.us/voltron/iDS-Defaults.git'
|
|
readonly TAPM_LAUNCHER='/usr/local/bin/tapm'
|
|
readonly REQUESTED_BRANCH="${TAPM_BRANCH:-}"
|
|
|
|
declare -a TEMP_PATHS=()
|
|
|
|
cleanup() {
|
|
local path
|
|
|
|
for path in "${TEMP_PATHS[@]}"; do
|
|
[[ -e "$path" ]] && rm -rf -- "$path"
|
|
done
|
|
}
|
|
|
|
fail() {
|
|
printf 'ERROR: %s\n' "$*" >&2
|
|
exit 1
|
|
}
|
|
|
|
clone_repository() {
|
|
local repository="$1"
|
|
local destination="$2"
|
|
local label="$3"
|
|
local branch="${4:-}"
|
|
local temporary
|
|
|
|
if [[ -d "${destination}/.git" ]]; then
|
|
printf '%s is already installed at %s; leaving it unchanged.\n' \
|
|
"$label" "$destination"
|
|
return
|
|
fi
|
|
|
|
[[ ! -e "$destination" ]] ||
|
|
fail "${destination} already exists but is not a Git repository."
|
|
|
|
temporary="${destination}.install.$$"
|
|
TEMP_PATHS+=("$temporary")
|
|
|
|
printf 'Cloning %s...\n' "$label"
|
|
if [[ -n "$branch" ]]; then
|
|
git clone --branch "$branch" --single-branch \
|
|
"$repository" "$temporary"
|
|
else
|
|
git clone "$repository" "$temporary"
|
|
fi
|
|
|
|
mv "$temporary" "$destination"
|
|
}
|
|
|
|
install_launcher() {
|
|
local current_target=''
|
|
|
|
if [[ -L "$TAPM_LAUNCHER" ]]; then
|
|
current_target="$(readlink "$TAPM_LAUNCHER")"
|
|
if [[ "$current_target" == "${TAPM_DIR}/run.sh" ]]; then
|
|
return
|
|
fi
|
|
|
|
fail "${TAPM_LAUNCHER} points to ${current_target}; it was not replaced."
|
|
fi
|
|
|
|
[[ ! -e "$TAPM_LAUNCHER" ]] ||
|
|
fail "${TAPM_LAUNCHER} already exists and was not replaced."
|
|
|
|
ln -s "${TAPM_DIR}/run.sh" "$TAPM_LAUNCHER"
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
(( EUID == 0 )) || fail 'Run this installer as root.'
|
|
command -v pveversion >/dev/null 2>&1 ||
|
|
fail 'This installer must be run on a Proxmox VE host.'
|
|
|
|
if [[ -n "$REQUESTED_BRANCH" ]] &&
|
|
[[ ! "$REQUESTED_BRANCH" =~ ^[A-Za-z0-9._/-]+$ ]]; then
|
|
fail "Invalid TAPM_BRANCH value: ${REQUESTED_BRANCH}"
|
|
fi
|
|
|
|
printf '\nTA-ProxMenu Installation Script\n\n'
|
|
|
|
apt-get update
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
ca-certificates curl git jq python3 wget
|
|
|
|
mkdir -p "$INSTALL_ROOT"
|
|
|
|
clone_repository \
|
|
"$DEFAULTS_REPOSITORY" "$DEFAULTS_DIR" 'iDSSYS Defaults'
|
|
clone_repository \
|
|
"$TAPM_REPOSITORY" "$TAPM_DIR" 'TA-ProxMenu' "$REQUESTED_BRANCH"
|
|
|
|
[[ -x "${TAPM_DIR}/run.sh" ]] ||
|
|
fail "${TAPM_DIR}/run.sh is missing or is not executable."
|
|
[[ -r "${DEFAULTS_DIR}/colors.inc" ]] ||
|
|
fail "${DEFAULTS_DIR}/colors.inc is missing."
|
|
[[ -r "${DEFAULTS_DIR}/default.inc" ]] ||
|
|
fail "${DEFAULTS_DIR}/default.inc is missing."
|
|
|
|
install_launcher
|
|
|
|
# Load the standard colors only after the trusted defaults repository exists.
|
|
# shellcheck disable=SC1091
|
|
source "${DEFAULTS_DIR}/colors.inc"
|
|
|
|
printf '\n%bTA-ProxMenu has been installed.%b\n\n' \
|
|
"${idsCL[Yellow]}" "${idsCL[Default]}"
|
|
printf 'Run it with: %btapm%b\n\n' \
|
|
"${idsCL[Green]}" "${idsCL[Default]}"
|
|
|
|
if [[ -n "$REQUESTED_BRANCH" ]]; then
|
|
printf 'Installed branch: %b%s%b\n\n' \
|
|
"${idsCL[Green]}" "$REQUESTED_BRANCH" "${idsCL[Default]}"
|
|
fi
|