From 6be503b70030c9f65f227650d3c7de3264bc00d1 Mon Sep 17 00:00:00 2001 From: velvettear Date: Fri, 30 Aug 2024 10:18:26 +0200 Subject: [PATCH] use sudo to run actions with a different user, check for subshell --- scripts/restic/backup.sh | 4 ++-- scripts/restic/prune.sh | 4 ++-- scripts/restic/restic.env | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/restic/backup.sh b/scripts/restic/backup.sh index 451a66e..a0fd25e 100755 --- a/scripts/restic/backup.sh +++ b/scripts/restic/backup.sh @@ -3,8 +3,8 @@ # author: Daniel Sommer # license: MIT -# check permissions -[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" >&2 && exit 1 +# check if we're running in a subshell, forbid direct execution +[[ "$ZSH_EVAL_CONTEXT" == "toplevel" ]] && printf "error: direct execution of this script is forbidden!\n" >&2 && exit 1 # get the "home" directory home="$(dirname $(realpath "$0"))" diff --git a/scripts/restic/prune.sh b/scripts/restic/prune.sh index 15e7686..0c666ac 100755 --- a/scripts/restic/prune.sh +++ b/scripts/restic/prune.sh @@ -3,8 +3,8 @@ # author: Daniel Sommer # license: MIT -# check permissions -[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" >&2 && exit 1 +# check if we're running in a subshell, forbid direct execution +[[ "$ZSH_EVAL_CONTEXT" == "toplevel" ]] && printf "error: direct execution of this script is forbidden!\n" >&2 && exit 1 # define title and icon for the notification export RESTIC_NTFY_TITLE="prune" diff --git a/scripts/restic/restic.env b/scripts/restic/restic.env index 7a89e5e..06f73b8 100644 --- a/scripts/restic/restic.env +++ b/scripts/restic/restic.env @@ -3,6 +3,9 @@ # author: Daniel Sommer # license: MIT +# define user +export RESTIC_USER="restic" + # override default repository export RESTIC_REPOSITORY="/mnt/restic"