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
+46 -24
View File
@@ -6,7 +6,7 @@
# install.sh - install # install.sh - install
# install.sh --uninstall - remove everything installed by this script # 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) # Tested on: AlmaLinux 8/9, Rocky Linux 8/9 (NS8 supported distros)
# ============================================================================= # =============================================================================
set -euo pipefail set -euo pipefail
@@ -17,7 +17,12 @@ INSTALL_DIR="/opt/ns8-backup-monitor"
CONFIG_DIR="/etc/ns8-backup-monitor" CONFIG_DIR="/etc/ns8-backup-monitor"
CONFIG_FILE="${CONFIG_DIR}/config.yml" CONFIG_FILE="${CONFIG_DIR}/config.yml"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" 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) PYTHON=$(command -v python3 || true)
# --- colours ----------------------------------------------------------------- # --- colours -----------------------------------------------------------------
@@ -38,7 +43,6 @@ do_uninstall() {
read -rp "Continue? [y/N] " confirm read -rp "Continue? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { info "Aborted."; exit 0; } [[ "$confirm" =~ ^[Yy]$ ]] || { info "Aborted."; exit 0; }
# Stop & disable service
if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
info "Stopping service..." info "Stopping service..."
systemctl stop "$SERVICE_NAME" systemctl stop "$SERVICE_NAME"
@@ -48,7 +52,6 @@ do_uninstall() {
systemctl disable "$SERVICE_NAME" systemctl disable "$SERVICE_NAME"
fi fi
# Remove service file
if [[ -f "$SERVICE_FILE" ]]; then if [[ -f "$SERVICE_FILE" ]]; then
info "Removing systemd unit..." info "Removing systemd unit..."
rm -f "$SERVICE_FILE" rm -f "$SERVICE_FILE"
@@ -56,14 +59,12 @@ do_uninstall() {
ok "Systemd unit removed." ok "Systemd unit removed."
fi fi
# Remove install dir
if [[ -d "$INSTALL_DIR" ]]; then if [[ -d "$INSTALL_DIR" ]]; then
info "Removing ${INSTALL_DIR}..." info "Removing ${INSTALL_DIR}..."
rm -rf "$INSTALL_DIR" rm -rf "$INSTALL_DIR"
ok "Install directory removed." ok "Install directory removed."
fi fi
# Ask about config
if [[ -d "$CONFIG_DIR" ]]; then if [[ -d "$CONFIG_DIR" ]]; then
read -rp "Remove config directory ${CONFIG_DIR}? [y/N] " rmcfg read -rp "Remove config directory ${CONFIG_DIR}? [y/N] " rmcfg
if [[ "$rmcfg" =~ ^[Yy]$ ]]; then if [[ "$rmcfg" =~ ^[Yy]$ ]]; then
@@ -77,16 +78,42 @@ do_uninstall() {
echo -e "${GREEN}${BOLD}Uninstall complete.${RESET}" 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 # INSTALL
# ============================================================================= # =============================================================================
do_install() { do_install() {
echo -e "${BOLD}=== ns8-backup-monitor INSTALLER ===${RESET}\n" echo -e "${BOLD}=== ns8-backup-monitor INSTALLER ===${RESET}\n"
# --- pre-flight checks --------------------------------------------------- # --- pre-flight ----------------------------------------------------------
[[ $EUID -eq 0 ]] || error "Run as root (or with sudo)." [[ $EUID -eq 0 ]] || error "Run as root (or with sudo)."
[[ -n "$PYTHON" ]] || error "python3 not found." [[ -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 || \ command -v ns8-sendmail &>/dev/null || \
warn "ns8-sendmail not found in PATH - make sure this runs on an NS8 node." 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 -e "Email delivery uses ${BLUE}ns8-sendmail${RESET} (NS8 configured relay)."
echo echo
# mail from
local default_from="ns8-backup-monitor@$(hostname -f 2>/dev/null || echo localhost)" local default_from="ns8-backup-monitor@$(hostname -f 2>/dev/null || echo localhost)"
read -rp "Sender address (From) [${default_from}]: " MAIL_FROM read -rp "Sender address (From) [${default_from}]: " MAIL_FROM
MAIL_FROM="${MAIL_FROM:-$default_from}" MAIL_FROM="${MAIL_FROM:-$default_from}"
# mail to - loop until at least one address is entered
local MAIL_TO_LIST=() 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 while true; do
read -rp " Recipient: " addr read -rp " Recipient: " addr
[[ -z "$addr" ]] && break [[ -z "$addr" ]] && break
@@ -110,7 +135,6 @@ do_install() {
done done
[[ ${#MAIL_TO_LIST[@]} -gt 0 ]] || error "At least one recipient is required." [[ ${#MAIL_TO_LIST[@]} -gt 0 ]] || error "At least one recipient is required."
# subject prefix
read -rp "Subject prefix [[NS8 Backup]]: " SUBJECT_PREFIX read -rp "Subject prefix [[NS8 Backup]]: " SUBJECT_PREFIX
SUBJECT_PREFIX="${SUBJECT_PREFIX:-[NS8 Backup]}" SUBJECT_PREFIX="${SUBJECT_PREFIX:-[NS8 Backup]}"
@@ -123,23 +147,20 @@ do_install() {
[[ "$go" =~ ^[Nn]$ ]] && { info "Aborted."; exit 0; } [[ "$go" =~ ^[Nn]$ ]] && { info "Aborted."; exit 0; }
echo echo
# --- clone / update source ----------------------------------------------- # --- download source -----------------------------------------------------
if [[ -d "${INSTALL_DIR}/.git" ]]; then if [[ -d "$INSTALL_DIR" ]]; then
info "Updating existing clone in ${INSTALL_DIR}..." info "${INSTALL_DIR} already exists - updating source..."
git -C "$INSTALL_DIR" pull --ff-only rm -rf "$INSTALL_DIR"
else
info "Cloning into ${INSTALL_DIR}..."
git clone "$REPO_URL" "$INSTALL_DIR"
fi fi
ok "Source ready." download_source
# --- config directory ---------------------------------------------------- # --- config directory ----------------------------------------------------
mkdir -p "$CONFIG_DIR" mkdir -p "$CONFIG_DIR"
chmod 750 "$CONFIG_DIR" chmod 750 "$CONFIG_DIR"
if [[ -f "$CONFIG_FILE" ]]; then if [[ -f "$CONFIG_FILE" ]]; then
warn "Config file ${CONFIG_FILE} already exists - keeping it." warn "Config ${CONFIG_FILE} already exists - keeping it."
warn "Edit it manually if you need to change mail settings." warn "Edit it manually to change mail settings."
else else
info "Writing ${CONFIG_FILE}..." info "Writing ${CONFIG_FILE}..."
@@ -149,7 +170,7 @@ do_install() {
to_yaml+=" - \"${addr}\"\n" to_yaml+=" - \"${addr}\"\n"
done done
cat > "$CONFIG_FILE" <<EOF cat > "$CONFIG_FILE" << EOF
# ns8-backup-monitor configuration # ns8-backup-monitor configuration
# Generated by install.sh on $(date -u '+%Y-%m-%d %H:%M UTC') # Generated by install.sh on $(date -u '+%Y-%m-%d %H:%M UTC')
@@ -194,10 +215,11 @@ EOF
echo echo
echo -e "${GREEN}${BOLD}Installation complete.${RESET}" echo -e "${GREEN}${BOLD}Installation complete.${RESET}"
echo -e " Config: ${CONFIG_FILE}" echo -e " Config: ${CONFIG_FILE}"
echo -e " Logs: journalctl -u ${SERVICE_NAME} -f"
echo -e " Status: systemctl status ${SERVICE_NAME}" echo -e " Status: systemctl status ${SERVICE_NAME}"
echo -e " Logs: journalctl -u ${SERVICE_NAME} -f"
echo 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}"
} }
# ============================================================================= # =============================================================================