create tmp dir and clean up after

This commit is contained in:
Asif Bacchus 2020-03-26 03:56:23 -06:00
parent 515e57e4f3
commit 5254dba0bf
1 changed files with 21 additions and 0 deletions

View File

@ -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"