From 48cfeb90b3c7aff1d9b2206de07658a2508a9ce2 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 24 Nov 2025 11:41:48 +0000 Subject: [PATCH 1/4] distro specific hints --- restic-backup.sh | 52 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/restic-backup.sh b/restic-backup.sh index c7f4e59..cd4bcb2 100644 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ================================================================= -# Restic Backup Script v0.40 - 2025.11.18 +# Restic Backup Script v0.41 - 2025.11.24 # ================================================================= export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin @@ -9,7 +9,7 @@ set -euo pipefail umask 077 # --- Script Constants --- -SCRIPT_VERSION="0.40" +SCRIPT_VERSION="0.41" SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) PROG_NAME=$(basename "$0"); readonly PROG_NAME CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf" @@ -76,7 +76,7 @@ import_restic_key() { fi done - # 4. Check Debian/Ubuntu system keyring (Fallback for apt-installed systems) + # 4. Check System Keyring (Distro specific) debian_keyring="/usr/share/keyrings/restic-archive-keyring.gpg" if [[ -f "$debian_keyring" ]]; then echo "Checking system keyring..." @@ -111,9 +111,9 @@ check_and_install_restic() { echo -e "${C_BOLD}--- Checking Restic Version ---${C_RESET}" if ! command -v less &>/dev/null || ! command -v bzip2 &>/dev/null || ! command -v curl &>/dev/null || ! command -v gpg &>/dev/null || ! command -v jq &>/dev/null; then echo - echo -e "${C_RED}ERROR: 'less', 'bzip2', 'curl', 'gpg', and 'jq' are required for secure auto-installation.${C_RESET}" >&2 + echo -e "${C_RED}ERROR: Missing dependencies.${C_RESET}" >&2 echo - echo -e "${C_YELLOW}On Debian based systems install with: sudo apt-get install less bzip2 curl gnupg jq${C_RESET}" >&2 + echo -e "${C_YELLOW}Install with: ${MISSING_PKG_HINT}${C_RESET}" >&2 echo exit 1 fi @@ -194,7 +194,11 @@ check_and_install_restic() { echo "Decompressing and installing to /usr/local/bin/restic..." if bunzip2 -c "$temp_binary" > /usr/local/bin/restic.tmp; then chmod +x /usr/local/bin/restic.tmp - mv /usr/local/bin/restic.tmp /usr/local/bin/restic + mv /usr/local/bin/restic.tmp /usr/local/bin/restic + if [[ "$IS_SELINUX_DISTRO" == "true" ]] && command -v restorecon &>/dev/null; then + echo "Applying SELinux context to binary..." + restorecon -v /usr/local/bin/restic || true + fi echo -e "${C_GREEN}✅ Restic version $latest_version installed successfully.${C_RESET}" else echo -e "${C_RED}Installation failed.${C_RESET}" >&2 @@ -348,6 +352,33 @@ display_help() { echo } +detect_distro() { + if [ -f /etc/os-release ]; then + # shellcheck source=/dev/null + . /etc/os-release + OS_NAME=$ID + else + OS_NAME=$(uname -s) + fi + case "$OS_NAME" in + fedora|rhel|centos|almalinux|rocky) + # Fedora/RedHat settings + MISSING_PKG_HINT="sudo dnf install restic curl gnupg bzip2 less jq util-linux" + IS_SELINUX_DISTRO=true + ;; + debian|ubuntu|pop|mint|kali) + # Debian/Ubuntu settings + MISSING_PKG_HINT="sudo apt-get install restic curl gnupg bzip2 less jq" + IS_SELINUX_DISTRO=false + ;; + *) + # Fallback for Arch, Suse, Alpine, macOS, etc. + MISSING_PKG_HINT="Please install manually: restic curl gnupg bzip2 less jq" + IS_SELINUX_DISTRO=false + ;; + esac +} + log_message() { local message="$1" local timestamp @@ -791,13 +822,7 @@ run_preflight_checks() { local required_cmds=(restic curl flock jq less gpg bzip2) for cmd in "${required_cmds[@]}"; do if ! command -v "$cmd" &>/dev/null; then - local install_hint="On Debian-based systems, try: sudo apt install $cmd" - case "$cmd" in - gpg) install_hint="On Debian-based systems, try: sudo apt install gnupg";; - bzip2) install_hint="On Debian-based systems, try: sudo apt install bzip2";; - less) install_hint="On Debian-based systems, try: sudo apt install less";; - esac - handle_failure "Required command '$cmd' not found. $install_hint" "10" + handle_failure "Required command '$cmd' not found. Try: $MISSING_PKG_HINT" "10" fi done if [[ "$verbosity" == "verbose" ]]; then echo -e "[${C_GREEN} OK ${C_RESET}]"; fi @@ -1722,6 +1747,7 @@ fi LOCK_FD=200 # 4. After lock, it's safe to run updates. +detect_distro check_for_script_update check_and_install_restic From 923050822e0222e5893aa82fe33a3977ab366c45 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 24 Nov 2025 11:43:25 +0000 Subject: [PATCH 2/4] checksum v0.41 --- restic-backup.sh.sha256 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restic-backup.sh.sha256 b/restic-backup.sh.sha256 index 352be10..1528287 100644 --- a/restic-backup.sh.sha256 +++ b/restic-backup.sh.sha256 @@ -1 +1 @@ -7a80f69fd6b2c4f9c4073abbe1f75504f69345634190a43cd4400975880fba15 restic-backup.sh +620b285909ab5b31b954f74890cb32a0f45438bd88501da14330d7b1552db098 restic-backup.sh From 22cb6f31b17b0b17804d87662529cae98c355182 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 24 Nov 2025 12:13:29 +0000 Subject: [PATCH 3/4] improve distro specific hints --- restic-backup.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/restic-backup.sh b/restic-backup.sh index cd4bcb2..547a99a 100644 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -361,19 +361,34 @@ detect_distro() { OS_NAME=$(uname -s) fi case "$OS_NAME" in - fedora|rhel|centos|almalinux|rocky) - # Fedora/RedHat settings + fedora|rhel|centos|almalinux|rocky|amzn) + # RHEL / Fedora based MISSING_PKG_HINT="sudo dnf install restic curl gnupg bzip2 less jq util-linux" IS_SELINUX_DISTRO=true ;; - debian|ubuntu|pop|mint|kali) - # Debian/Ubuntu settings + debian|ubuntu|pop|mint|kali|raspbian|elementary) + # Debian / Ubuntu based MISSING_PKG_HINT="sudo apt-get install restic curl gnupg bzip2 less jq" IS_SELINUX_DISTRO=false ;; + arch|manjaro|endeavouros|garuda) + # Arch based ( # i don't use arch btw :) + MISSING_PKG_HINT="sudo pacman -S restic curl gnupg bzip2 less jq" + IS_SELINUX_DISTRO=false + ;; + opensuse*|sles) + # OpenSUSE + MISSING_PKG_HINT="sudo zypper install restic curl gpg2 bzip2 less jq" + IS_SELINUX_DISTRO=false + ;; + alpine) + # Alpine + MISSING_PKG_HINT="sudo apk add restic curl gnupg bzip2 less jq util-linux # (Ensure community repo is enabled)" + IS_SELINUX_DISTRO=false + ;; *) - # Fallback for Arch, Suse, Alpine, macOS, etc. - MISSING_PKG_HINT="Please install manually: restic curl gnupg bzip2 less jq" + # Fallback for unknown systems + MISSING_PKG_HINT="Please install manually: restic curl gnupg bzip2 less jq util-linux" IS_SELINUX_DISTRO=false ;; esac From 73e12dfbd90bbde31e181811b263b51878b2bae9 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 24 Nov 2025 12:16:08 +0000 Subject: [PATCH 4/4] checksum v0.41 --- restic-backup.sh.sha256 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restic-backup.sh.sha256 b/restic-backup.sh.sha256 index 1528287..47e93c4 100644 --- a/restic-backup.sh.sha256 +++ b/restic-backup.sh.sha256 @@ -1 +1 @@ -620b285909ab5b31b954f74890cb32a0f45438bd88501da14330d7b1552db098 restic-backup.sh +13de8cc2e5874e419ddc4a10f80ab56b76c5d4a6ba28af3b05fe79e6cf51173e restic-backup.sh