librelad 0b27ed1072 refactor(desudo): funnel backup-engine privilege drop through runBackupOp
The borg/restic/kopia engines all dropped to the dedicated backup user
via scattered 'sudo -E -u $docker_install_user'. Centralize that into a
single runBackupOp helper so the backup subsystem has one audit point and
the scoped sudoers needs only the (dockerinstall) drop rule.

Also:
- owncloud config heredoc tees -> runSystem (container-UID file)
- webui_display_logins: fix the broken 'command -v sudo sqlite3' guard
  to 'command -v sqlite3' (body already runs sqlite3 via runInstallOp)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 18:01:51 +01:00

51 lines
1.2 KiB
Bash

#!/bin/bash
borgInitLocation()
{
local idx="$1"
if ! resticLocationEnabled "$idx"; then
isNotice "Location $(resticLocationName "$idx") disabled — skipping init"
return 0
fi
borgEnvExport "$idx" || return 1
if [[ "$(resticLocationType "$idx")" == "local" ]]; then
runFileOp mkdir -p "$BORG_REPO"
runFileOp chown -R "$docker_install_user":"$docker_install_user" "$BORG_REPO"
fi
if runBackupOp borg info "$BORG_REPO" >/dev/null 2>&1; then
isNotice "$(resticLocationName "$idx") already initialized at $BORG_REPO"
borgEnvUnset
return 0
fi
isNotice "Initializing $(resticLocationName "$idx") at $BORG_REPO"
if runBackupOp borg init --encryption=repokey-blake2 "$BORG_REPO"; then
isSuccessful "$(resticLocationName "$idx") initialized"
else
isError "Failed to initialize $(resticLocationName "$idx")"
borgEnvUnset
return 1
fi
borgEnvUnset
}
borgEnsureLocationReady()
{
local idx="$1"
[[ -z "$idx" ]] && return 1
if ! resticLocationEnabled "$idx"; then
return 1
fi
if ! command -v borg >/dev/null 2>&1; then
borgInstall || return 1
fi
borgInitLocation "$idx"
}