Skip to content

Commit bc222cd

Browse files
authored
Merge pull request #34 from buildplan/distro_support
Provide distro-specific guidance for any dependencies that are missing.
2 parents 10658de + 73e12df commit bc222cd

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

restic-backup.sh

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22

33
# =================================================================
4-
# Restic Backup Script v0.40 - 2025.11.18
4+
# Restic Backup Script v0.41 - 2025.11.24
55
# =================================================================
66

77
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
88
set -euo pipefail
99
umask 077
1010

1111
# --- Script Constants ---
12-
SCRIPT_VERSION="0.40"
12+
SCRIPT_VERSION="0.41"
1313
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
1414
PROG_NAME=$(basename "$0"); readonly PROG_NAME
1515
CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf"
@@ -76,7 +76,7 @@ import_restic_key() {
7676
fi
7777
done
7878

79-
# 4. Check Debian/Ubuntu system keyring (Fallback for apt-installed systems)
79+
# 4. Check System Keyring (Distro specific)
8080
debian_keyring="/usr/share/keyrings/restic-archive-keyring.gpg"
8181
if [[ -f "$debian_keyring" ]]; then
8282
echo "Checking system keyring..."
@@ -111,9 +111,9 @@ check_and_install_restic() {
111111
echo -e "${C_BOLD}--- Checking Restic Version ---${C_RESET}"
112112
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
113113
echo
114-
echo -e "${C_RED}ERROR: 'less', 'bzip2', 'curl', 'gpg', and 'jq' are required for secure auto-installation.${C_RESET}" >&2
114+
echo -e "${C_RED}ERROR: Missing dependencies.${C_RESET}" >&2
115115
echo
116-
echo -e "${C_YELLOW}On Debian based systems install with: sudo apt-get install less bzip2 curl gnupg jq${C_RESET}" >&2
116+
echo -e "${C_YELLOW}Install with: ${MISSING_PKG_HINT}${C_RESET}" >&2
117117
echo
118118
exit 1
119119
fi
@@ -194,7 +194,11 @@ check_and_install_restic() {
194194
echo "Decompressing and installing to /usr/local/bin/restic..."
195195
if bunzip2 -c "$temp_binary" > /usr/local/bin/restic.tmp; then
196196
chmod +x /usr/local/bin/restic.tmp
197-
mv /usr/local/bin/restic.tmp /usr/local/bin/restic
197+
mv /usr/local/bin/restic.tmp /usr/local/bin/restic
198+
if [[ "$IS_SELINUX_DISTRO" == "true" ]] && command -v restorecon &>/dev/null; then
199+
echo "Applying SELinux context to binary..."
200+
restorecon -v /usr/local/bin/restic || true
201+
fi
198202
echo -e "${C_GREEN}✅ Restic version $latest_version installed successfully.${C_RESET}"
199203
else
200204
echo -e "${C_RED}Installation failed.${C_RESET}" >&2
@@ -348,6 +352,48 @@ display_help() {
348352
echo
349353
}
350354

355+
detect_distro() {
356+
if [ -f /etc/os-release ]; then
357+
# shellcheck source=/dev/null
358+
. /etc/os-release
359+
OS_NAME=$ID
360+
else
361+
OS_NAME=$(uname -s)
362+
fi
363+
case "$OS_NAME" in
364+
fedora|rhel|centos|almalinux|rocky|amzn)
365+
# RHEL / Fedora based
366+
MISSING_PKG_HINT="sudo dnf install restic curl gnupg bzip2 less jq util-linux"
367+
IS_SELINUX_DISTRO=true
368+
;;
369+
debian|ubuntu|pop|mint|kali|raspbian|elementary)
370+
# Debian / Ubuntu based
371+
MISSING_PKG_HINT="sudo apt-get install restic curl gnupg bzip2 less jq"
372+
IS_SELINUX_DISTRO=false
373+
;;
374+
arch|manjaro|endeavouros|garuda)
375+
# Arch based ( # i don't use arch btw :)
376+
MISSING_PKG_HINT="sudo pacman -S restic curl gnupg bzip2 less jq"
377+
IS_SELINUX_DISTRO=false
378+
;;
379+
opensuse*|sles)
380+
# OpenSUSE
381+
MISSING_PKG_HINT="sudo zypper install restic curl gpg2 bzip2 less jq"
382+
IS_SELINUX_DISTRO=false
383+
;;
384+
alpine)
385+
# Alpine
386+
MISSING_PKG_HINT="sudo apk add restic curl gnupg bzip2 less jq util-linux # (Ensure community repo is enabled)"
387+
IS_SELINUX_DISTRO=false
388+
;;
389+
*)
390+
# Fallback for unknown systems
391+
MISSING_PKG_HINT="Please install manually: restic curl gnupg bzip2 less jq util-linux"
392+
IS_SELINUX_DISTRO=false
393+
;;
394+
esac
395+
}
396+
351397
log_message() {
352398
local message="$1"
353399
local timestamp
@@ -791,13 +837,7 @@ run_preflight_checks() {
791837
local required_cmds=(restic curl flock jq less gpg bzip2)
792838
for cmd in "${required_cmds[@]}"; do
793839
if ! command -v "$cmd" &>/dev/null; then
794-
local install_hint="On Debian-based systems, try: sudo apt install $cmd"
795-
case "$cmd" in
796-
gpg) install_hint="On Debian-based systems, try: sudo apt install gnupg";;
797-
bzip2) install_hint="On Debian-based systems, try: sudo apt install bzip2";;
798-
less) install_hint="On Debian-based systems, try: sudo apt install less";;
799-
esac
800-
handle_failure "Required command '$cmd' not found. $install_hint" "10"
840+
handle_failure "Required command '$cmd' not found. Try: $MISSING_PKG_HINT" "10"
801841
fi
802842
done
803843
if [[ "$verbosity" == "verbose" ]]; then echo -e "[${C_GREEN} OK ${C_RESET}]"; fi
@@ -1722,6 +1762,7 @@ fi
17221762
LOCK_FD=200
17231763

17241764
# 4. After lock, it's safe to run updates.
1765+
detect_distro
17251766
check_for_script_update
17261767
check_and_install_restic
17271768

restic-backup.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7a80f69fd6b2c4f9c4073abbe1f75504f69345634190a43cd4400975880fba15 restic-backup.sh
1+
13de8cc2e5874e419ddc4a10f80ab56b76c5d4a6ba28af3b05fe79e6cf51173e restic-backup.sh

0 commit comments

Comments
 (0)