From 5254dba0bf07c02e7c1bbf7464bdc8713ee018ae Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Thu, 26 Mar 2020 03:56:23 -0600 Subject: [PATCH] create tmp dir and clean up after --- borghelper.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/borghelper.sh b/borghelper.sh index 6aebea0..cddaab0 100755 --- a/borghelper.sh +++ b/borghelper.sh @@ -8,6 +8,13 @@ trap trapExit 1 2 3 6 ### functions +cleanup () { + # remove borg temp directory, if it exists + if [ -d "${borgBaseDir}/tmp" ]; then + rm -rf "${borgBaseDir}/tmp" > /dev/null 2>&1 + fi +} + consoleError() { printf "%s\n%s\n" "$err" "$2" printf "Exiting.\n\n%s" "$norm" @@ -19,6 +26,7 @@ textblock() { } trapExit () { + cleanup printf "%s\nScript execution terminated via signal.\n\n%s" "$err" "$norm" exit 99 } @@ -195,3 +203,16 @@ fi if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi +### create borg temp dir: +## python requires a writable temporary directory when unpacking borg and +## executing commands. This defaults to /tmp but many systems mount /tmp with +## the 'noexec' option for security. Thus, we will use/create a 'tmp' folder +## within the BORG_BASE_DIR and instruct python to use that instead of /tmp + +# check if BORG_BASE_DIR/tmp exists, if not, create it +if [ ! -d "${borgBaseDir}/tmp" ]; then + if ! mkdir "${borgBaseDir}/tmp"; then + consoleError 3 'Unable to create temp working directory for borg.' + fi +fi +export TMPDIR="${borgBaseDir}/tmp"