fix: installer - replace git clone with curl tarball download, no git required

This commit is contained in:
2026-05-18 20:22:50 +00:00
parent 98d104dcc6
commit 9351a04329
+54 -32
View File
@@ -3,10 +3,10 @@
# ns8-backup-monitor - Installer / Uninstaller
# =============================================================================
# Usage:
# install.sh - install
# install.sh - install
# install.sh --uninstall - remove everything installed by this script
#
# Requires: root, python3, git
# Requires: root, python3, curl (no git needed)
# Tested on: AlmaLinux 8/9, Rocky Linux 8/9 (NS8 supported distros)
# =============================================================================
set -euo pipefail
@@ -17,17 +17,22 @@ INSTALL_DIR="/opt/ns8-backup-monitor"
CONFIG_DIR="/etc/ns8-backup-monitor"
CONFIG_FILE="${CONFIG_DIR}/config.yml"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
REPO_URL="https://repo.lelekaos.com/admin/ns8-backup-monitor.git"
# Gitea raw base URL for downloading individual files
RAW_BASE="https://repo.lelekaos.com/admin/ns8-backup-monitor/raw/branch/main"
# Gitea archive URL (no git needed - just curl)
ARCHIVE_URL="https://repo.lelekaos.com/admin/ns8-backup-monitor/archive/main.tar.gz"
PYTHON=$(command -v python3 || true)
# --- colours -----------------------------------------------------------------
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
BLUE='\033[0;34m'; BOLD='\033[1m'; RESET='\033[0m'
info() { echo -e "${BLUE}[INFO]${RESET} $*"; }
ok() { echo -e "${GREEN}[OK]${RESET} $*"; }
warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
error() { echo -e "${RED}[ERROR]${RESET} $*" >&2; exit 1; }
info() { echo -e "${BLUE}[INFO]${RESET} $*"; }
ok() { echo -e "${GREEN}[OK]${RESET} $*"; }
warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
error() { echo -e "${RED}[ERROR]${RESET} $*" >&2; exit 1; }
# =============================================================================
# UNINSTALL
@@ -38,7 +43,6 @@ do_uninstall() {
read -rp "Continue? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { info "Aborted."; exit 0; }
# Stop & disable service
if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
info "Stopping service..."
systemctl stop "$SERVICE_NAME"
@@ -48,7 +52,6 @@ do_uninstall() {
systemctl disable "$SERVICE_NAME"
fi
# Remove service file
if [[ -f "$SERVICE_FILE" ]]; then
info "Removing systemd unit..."
rm -f "$SERVICE_FILE"
@@ -56,14 +59,12 @@ do_uninstall() {
ok "Systemd unit removed."
fi
# Remove install dir
if [[ -d "$INSTALL_DIR" ]]; then
info "Removing ${INSTALL_DIR}..."
rm -rf "$INSTALL_DIR"
ok "Install directory removed."
fi
# Ask about config
if [[ -d "$CONFIG_DIR" ]]; then
read -rp "Remove config directory ${CONFIG_DIR}? [y/N] " rmcfg
if [[ "$rmcfg" =~ ^[Yy]$ ]]; then
@@ -77,16 +78,42 @@ do_uninstall() {
echo -e "${GREEN}${BOLD}Uninstall complete.${RESET}"
}
# =============================================================================
# DOWNLOAD SOURCE
# =============================================================================
download_source() {
local tmpdir
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' RETURN
info "Downloading source archive..."
curl -fsSL "$ARCHIVE_URL" -o "${tmpdir}/archive.tar.gz" \
|| error "Failed to download archive from ${ARCHIVE_URL}"
info "Extracting..."
mkdir -p "$INSTALL_DIR"
# Gitea archives extract to a subdirectory named <repo>-<branch>/
tar -xzf "${tmpdir}/archive.tar.gz" -C "${tmpdir}"
local extracted_dir
extracted_dir=$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d | head -n1)
[[ -n "$extracted_dir" ]] || error "Could not find extracted directory in archive."
# Sync into INSTALL_DIR (rsync-style, pure bash)
cp -a "${extracted_dir}/." "$INSTALL_DIR/"
ok "Source ready at ${INSTALL_DIR}."
}
# =============================================================================
# INSTALL
# =============================================================================
do_install() {
echo -e "${BOLD}=== ns8-backup-monitor INSTALLER ===${RESET}\n"
# --- pre-flight checks ---------------------------------------------------
# --- pre-flight ----------------------------------------------------------
[[ $EUID -eq 0 ]] || error "Run as root (or with sudo)."
[[ -n "$PYTHON" ]] || error "python3 not found."
command -v git &>/dev/null || error "git not found."
command -v curl &>/dev/null || error "curl not found."
command -v tar &>/dev/null || error "tar not found."
command -v ns8-sendmail &>/dev/null || \
warn "ns8-sendmail not found in PATH - make sure this runs on an NS8 node."
@@ -95,14 +122,12 @@ do_install() {
echo -e "Email delivery uses ${BLUE}ns8-sendmail${RESET} (NS8 configured relay)."
echo
# mail from
local default_from="ns8-backup-monitor@$(hostname -f 2>/dev/null || echo localhost)"
read -rp "Sender address (From) [${default_from}]: " MAIL_FROM
MAIL_FROM="${MAIL_FROM:-$default_from}"
# mail to - loop until at least one address is entered
local MAIL_TO_LIST=()
echo "Recipient addresses (To) - enter one per line, empty line to finish:"
echo "Recipient addresses (To) - one per line, empty line when done:"
while true; do
read -rp " Recipient: " addr
[[ -z "$addr" ]] && break
@@ -110,7 +135,6 @@ do_install() {
done
[[ ${#MAIL_TO_LIST[@]} -gt 0 ]] || error "At least one recipient is required."
# subject prefix
read -rp "Subject prefix [[NS8 Backup]]: " SUBJECT_PREFIX
SUBJECT_PREFIX="${SUBJECT_PREFIX:-[NS8 Backup]}"
@@ -123,23 +147,20 @@ do_install() {
[[ "$go" =~ ^[Nn]$ ]] && { info "Aborted."; exit 0; }
echo
# --- clone / update source -----------------------------------------------
if [[ -d "${INSTALL_DIR}/.git" ]]; then
info "Updating existing clone in ${INSTALL_DIR}..."
git -C "$INSTALL_DIR" pull --ff-only
else
info "Cloning into ${INSTALL_DIR}..."
git clone "$REPO_URL" "$INSTALL_DIR"
# --- download source -----------------------------------------------------
if [[ -d "$INSTALL_DIR" ]]; then
info "${INSTALL_DIR} already exists - updating source..."
rm -rf "$INSTALL_DIR"
fi
ok "Source ready."
download_source
# --- config directory ----------------------------------------------------
mkdir -p "$CONFIG_DIR"
chmod 750 "$CONFIG_DIR"
if [[ -f "$CONFIG_FILE" ]]; then
warn "Config file ${CONFIG_FILE} already exists - keeping it."
warn "Edit it manually if you need to change mail settings."
warn "Config ${CONFIG_FILE} already exists - keeping it."
warn "Edit it manually to change mail settings."
else
info "Writing ${CONFIG_FILE}..."
@@ -149,7 +170,7 @@ do_install() {
to_yaml+=" - \"${addr}\"\n"
done
cat > "$CONFIG_FILE" <<EOF
cat > "$CONFIG_FILE" << EOF
# ns8-backup-monitor configuration
# Generated by install.sh on $(date -u '+%Y-%m-%d %H:%M UTC')
@@ -193,11 +214,12 @@ EOF
# --- done ----------------------------------------------------------------
echo
echo -e "${GREEN}${BOLD}Installation complete.${RESET}"
echo -e " Config: ${CONFIG_FILE}"
echo -e " Logs: journalctl -u ${SERVICE_NAME} -f"
echo -e " Status: systemctl status ${SERVICE_NAME}"
echo -e " Config: ${CONFIG_FILE}"
echo -e " Status: systemctl status ${SERVICE_NAME}"
echo -e " Logs: journalctl -u ${SERVICE_NAME} -f"
echo
echo -e "To uninstall: ${BOLD}bash ${INSTALL_DIR}/deploy/install.sh --uninstall${RESET}"
echo -e "To uninstall: ${BOLD}bash ${INSTALL_DIR}/deploy/install.sh --uninstall${RESET}"
echo -e "To update: ${BOLD}bash <(curl -fsSL ${RAW_BASE}/deploy/install.sh)${RESET}"
}
# =============================================================================