#!/usr/bin/env bash # Exit immediately if a command exits with a non-zero status set -e # Check for administrative privileges if [[ "$EUID" -ne 0 ]]; then echo "Error: This script must be run as root." >&2 exit 1 fi # Detect architecture ARCH=$(uname -m) if [[ "$ARCH" == "x86_64" ]]; then ARCH="x86_64" elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then ARCH="arm64" else echo "Unsupported architecture: $ARCH" exit 1 fi # Create a temporary directory and ensure it is deleted on exit TMP_DIR=$(mktemp -d) trap "rm -rf $TMP_DIR" EXIT echo "Created temporary directory: $TMP_DIR" # Fetch the latest release download URL for the correct architecture DOWNLOAD_URL=$(curl -s https://api.github.com/repos/garethgeorge/backrest/releases/latest | \ grep "browser_download_url.*backrest_Linux_${ARCH}.tar.gz" | \ cut -d '"' -f 4) if [[ -z "$DOWNLOAD_URL" ]]; then echo "Failed to get the download URL for the latest release." exit 1 fi echo "Downloading from: $DOWNLOAD_URL" # Download and extract the tarball wget -qO- "$DOWNLOAD_URL" | tar -xz -C "$TMP_DIR" # Run the installer if [[ -f "$TMP_DIR/install.sh" ]]; then echo "Running install.sh..." bash "$TMP_DIR/install.sh" else echo "Error: install.sh not found in $TMP_DIR." exit 1 fi # Reload systemd and restart the service echo "Reloading systemd daemon..." systemctl daemon-reload echo "Restarting backrest service..." systemctl restart backrest echo "Installation complete."