LibrePortal/scripts/system/libreportal-bininstall
librelad afe0ef1c7e chore: drop duplicate doc files + fix wrong/stale comments
- docs: remove the docs/README.md index and docs/CONTRIBUTING.md pointer
  (duplicate filenames); the canonical contributing guide stays at
  docs/contributing/contributing.md. Clean tree, no name collisions.
- scripts/system/*: 6 helper headers + host_access.sh said the helpers
  install to /usr/local/sbin, but init.sh installs all of them to
  /usr/local/lib/libreportal/ (verified via initRootHelpers + the sudoers
  Cmnd_Alias). Corrected. The only remaining /usr/local/sbin is the legit
  PATH export in the task processor.
- frontend kernel: drop migration-era comments that are now false post-
  modularization (feature-registry 'passive/phase 0/unused', lifecycle
  'ctx.services lands with Phase 2', manifest 'scan generator lands') —
  describe current behaviour instead.

Comment-only edits to scripts/system/* — no footprint_version bump (no
behavioural change; bumping would force needless reinstalls).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-31 01:05:16 +01:00

77 lines
3.2 KiB
Bash

#!/bin/bash
# LibrePortal backup-engine installer helper — the only root-privileged install of
# the restic/kopia binaries the manager may trigger (they're installed on demand
# when a backup location is first set up). Installed root:root 0755 to
# /usr/local/lib/libreportal/ by init.sh. Self-contained: it does the WHOLE install itself
# (package manager or signed-release download) for a FIXED, validated engine name,
# so the scoped sudoers needn't grant blanket `sudo apt-get`/`sudo install`
# (both root-equivalent — install writes anywhere, apt runs maintainer scripts).
set -u
[[ $EUID -eq 0 ]] || { echo "libreportal-bininstall: must run as root" >&2; exit 1; }
action="${1:-}"
engine="${2:-}"
[[ "$action" == "install" ]] || { echo "usage: libreportal-bininstall install <restic|kopia>" >&2; exit 2; }
case "$engine" in
restic|kopia) ;;
*) echo "libreportal-bininstall: unknown engine '$engine'" >&2; exit 2 ;;
esac
arch=$(uname -m)
install_restic() {
command -v restic >/dev/null 2>&1 && return 0
if command -v apt-get >/dev/null 2>&1; then
apt-get update -qq >/dev/null 2>&1
if apt-get install -y restic >/dev/null 2>&1; then
restic self-update >/dev/null 2>&1 || true
return 0
fi
elif command -v dnf >/dev/null 2>&1; then
dnf install -y restic >/dev/null 2>&1 && return 0
elif command -v pacman >/dev/null 2>&1; then
pacman -S --noconfirm restic >/dev/null 2>&1 && return 0
fi
local a
case "$arch" in
x86_64) a=amd64 ;; aarch64) a=arm64 ;; armv7l) a=arm ;;
*) echo "libreportal-bininstall: unsupported arch '$arch'" >&2; return 1 ;;
esac
local tmp; tmp=$(mktemp -d)
if curl -sL "https://github.com/restic/restic/releases/latest/download/restic_linux_${a}.bz2" -o "$tmp/restic.bz2" \
&& bunzip2 "$tmp/restic.bz2" \
&& install -m 0755 "$tmp/restic" /usr/local/bin/restic; then
rm -rf "$tmp"; return 0
fi
rm -rf "$tmp"; echo "libreportal-bininstall: restic download failed" >&2; return 1
}
install_kopia() {
command -v kopia >/dev/null 2>&1 && return 0
local a
case "$arch" in
x86_64) a=x64 ;; aarch64) a=arm64 ;; armv7l) a=arm ;;
*) echo "libreportal-bininstall: unsupported arch '$arch'" >&2; return 1 ;;
esac
local version
version=$(curl -sL https://api.github.com/repos/kopia/kopia/releases/latest 2>/dev/null \
| grep -oE '"tag_name":[[:space:]]*"v[0-9.]+"' | head -1 | grep -oE '[0-9.]+')
[[ -n "$version" ]] || { echo "libreportal-bininstall: kopia version lookup failed" >&2; return 1; }
local url="https://github.com/kopia/kopia/releases/download/v${version}/kopia-${version}-linux-${a}.tar.gz"
local tmp; tmp=$(mktemp -d)
if curl -sL "$url" -o "$tmp/kopia.tgz" && tar xzf "$tmp/kopia.tgz" -C "$tmp"; then
local bin; bin=$(find "$tmp" -name kopia -type f -executable | head -1)
if [[ -n "$bin" ]] && install -m 0755 "$bin" /usr/local/bin/kopia; then
rm -rf "$tmp"; return 0
fi
fi
rm -rf "$tmp"; echo "libreportal-bininstall: kopia install failed" >&2; return 1
}
case "$engine" in
restic) install_restic ;;
kopia) install_kopia ;;
esac