#!/usr/bin/env bash # gniza installer — single-line install: # bash <(curl -sSL http://192.168.100.100:3001/shukivaknin/gniza/raw/branch/main/scripts/install.sh) # # Or from a local clone: # bash scripts/install.sh set -eo pipefail INSTALL_DIR="/usr/local/gniza" BIN_LINK="/usr/local/bin/gniza" REPO_HTTP="http://192.168.100.100:3001/shukivaknin/gniza.git" TMPDIR_CLONE="" if [[ $EUID -ne 0 ]]; then echo "Error: install.sh must be run as root" >&2 exit 1 fi # Determine source directory — local clone or fresh git clone SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-}")" 2>/dev/null && pwd)" || true if [[ -n "${SCRIPT_DIR:-}" && -f "$SCRIPT_DIR/../bin/gniza" ]]; then SOURCE_DIR="$(dirname "$SCRIPT_DIR")" else echo "Cloning gniza..." TMPDIR_CLONE="$(mktemp -d)" git clone --depth 1 "$REPO_HTTP" "$TMPDIR_CLONE" 2>&1 SOURCE_DIR="$TMPDIR_CLONE" fi cleanup() { [[ -n "${TMPDIR_CLONE:-}" ]] && rm -rf "$TMPDIR_CLONE"; } trap cleanup EXIT echo "Installing gniza to $INSTALL_DIR..." # Create install directory mkdir -p "$INSTALL_DIR" # Copy files cp -r "$SOURCE_DIR/bin" "$INSTALL_DIR/" cp -r "$SOURCE_DIR/lib" "$INSTALL_DIR/" cp -r "$SOURCE_DIR/etc" "$INSTALL_DIR/" # Make bin executable chmod +x "$INSTALL_DIR/bin/gniza" # Create symlink ln -sf "$INSTALL_DIR/bin/gniza" "$BIN_LINK" # Create working directory mkdir -p "$INSTALL_DIR/workdir" # Create config directory structure mkdir -p /etc/gniza/remotes.d /etc/gniza/schedules.d # Copy example configs if no config exists if [[ ! -f /etc/gniza/gniza.conf ]]; then cp "$INSTALL_DIR/etc/gniza.conf.example" /etc/gniza/gniza.conf.example echo "Example config copied to /etc/gniza/gniza.conf.example" fi cp "$INSTALL_DIR/etc/remote.conf.example" /etc/gniza/remote.conf.example cp "$INSTALL_DIR/etc/schedule.conf.example" /etc/gniza/schedule.conf.example # Create log directory mkdir -p /var/log/gniza echo "gniza installed successfully!" # ── WHM Plugin (if cPanel/WHM is present) ───────────────────── WHM_CGI_DIR="/usr/local/cpanel/whostmgr/docroot/cgi" if [[ -d "$WHM_CGI_DIR" ]]; then echo "Installing WHM plugin..." # Remove old assets cruft (node_modules, src) if upgrading rm -rf "$WHM_CGI_DIR/gniza-whm/assets/node_modules" \ "$WHM_CGI_DIR/gniza-whm/assets/src" \ "$WHM_CGI_DIR/gniza-whm/assets/package.json" \ "$WHM_CGI_DIR/gniza-whm/assets/package-lock.json" 2>/dev/null || true cp -r "$SOURCE_DIR/whm/gniza-whm" "$WHM_CGI_DIR/" cp "$SOURCE_DIR/whm/gniza-whm.conf" "$WHM_CGI_DIR/gniza-whm/" chmod +x "$WHM_CGI_DIR/gniza-whm/"*.cgi # Remove build artifacts that shouldn't be on the server rm -rf "$WHM_CGI_DIR/gniza-whm/assets/node_modules" \ "$WHM_CGI_DIR/gniza-whm/assets/src" \ "$WHM_CGI_DIR/gniza-whm/assets/package.json" \ "$WHM_CGI_DIR/gniza-whm/assets/package-lock.json" 2>/dev/null || true /usr/local/cpanel/bin/register_appconfig "$WHM_CGI_DIR/gniza-whm/gniza-whm.conf" echo "WHM plugin installed — access via WHM > Plugins > gniza Backup Manager" else echo "WHM not detected, skipping WHM plugin installation." fi echo "" echo "Next steps:" echo " 1. Run 'gniza init' to create your configuration" echo " 2. Or copy /etc/gniza/gniza.conf.example to /etc/gniza/gniza.conf" echo " 3. Run 'gniza status' to verify your setup"