#!/bin/bash set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' info() { echo -e "${GREEN}[*]${NC} $1"; } warn() { echo -e "${YELLOW}[!]${NC} $1"; } error() { echo -e "${RED}[x]${NC} $1"; exit 1; } SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" echo "===================================" echo " x3-Backup Install Script" echo "===================================" echo "" # ── Detect distro ── detect_distro() { if [ -f /etc/os-release ]; then . /etc/os-release echo "$ID" elif command -v pacman &>/dev/null; then echo "arch" elif command -v emerge &>/dev/null; then echo "gentoo" elif command -v zypper &>/dev/null; then echo "opensuse" elif command -v dnf &>/dev/null; then echo "fedora" else echo "unknown" fi } DISTRO=$(detect_distro) info "Detected distro: $DISTRO" # ── Check if running as root ── if [ "$EUID" -eq 0 ]; then SUDO="" else SUDO="sudo" fi # ── Install dependencies ── install_deps() { info "Installing build dependencies..." case "$DISTRO" in arch|manjaro) $SUDO pacman -S --needed --noconfirm \ base-devel autoconf autoconf-archive automake libtool \ gtk3 json-glib rsync pkg-config ;; ubuntu|debian|linuxmint|pop) $SUDO apt update $SUDO apt install -y \ build-essential autoconf automake pkg-config \ libgtk-3-dev libjson-glib-dev rsync ;; fedora) $SUDO dnf install -y \ gcc-c++ autoconf automake pkgconfig \ gtk3-devel json-glib-devel rsync ;; opensuse*) $SUDO zypper install -y \ gcc-c++ autoconf automake pkg-config \ gtk3-devel json-glib-devel rsync ;; gentoo) $SUDO emerge --ask dev-build/autoconf dev-build/automake \ dev-util/pkgconfig x11-libs/gtk+:3 \ dev-libs/json-glib net-misc/rsync ;; *) warn "Unknown distro. Please install manually:" warn " autoconf automake pkg-config libgtk-3-dev libjson-glib-dev rsync" echo -n "Press Enter when done, or 'q' to quit: " read -r answer [ "$answer" = "q" ] && exit 1 ;; esac info "Dependencies installed." } # ── Build ── build() { info "Building x3-backup..." cd "$SCRIPT_DIR" # Clean previous build if [ -f Makefile ]; then make distclean 2>/dev/null || true fi autoreconf -fi ./configure make -j"$(nproc)" info "Build successful." } # ── Install ── install_app() { info "Installing x3-backup..." cd "$SCRIPT_DIR" $SUDO make install info "Installed to /usr/local/bin/x3-backup" } # ── Main ── case "${1:-all}" in deps) install_deps ;; build) build ;; install) install_app ;; all) install_deps build install_app echo "" info "===================================" info " x3-Backup installed successfully!" info "===================================" echo "" info "Run: x3-backup" info "Or: ./src/x3-backup (local build)" ;; *) echo "Usage: $0 [deps|build|install|all]" echo "" echo " deps Install dependencies only" echo " build Build only" echo " install Install to /usr/local" echo " all Do everything (default)" exit 1 ;; esac