From 7cc69a616a5e06ccfe89646f20b6e1a19ea6d889 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Thu, 26 Mar 2020 06:44:38 -0600 Subject: [PATCH] create restorePath if it does not exist --- .vscode/numbered-bookmarks.json | 6 +++--- borghelper.sh | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.vscode/numbered-bookmarks.json b/.vscode/numbered-bookmarks.json index a6000cf..04152df 100644 --- a/.vscode/numbered-bookmarks.json +++ b/.vscode/numbered-bookmarks.json @@ -4,15 +4,15 @@ "fsPath": "$ROOTPATH$/borghelper.sh", "bookmarks": [ -1, - 215, - 232, + 268, + 10, -1, -1, -1, -1, -1, -1, - 169 + 384 ] } ] diff --git a/borghelper.sh b/borghelper.sh index 9af2f54..086ef40 100755 --- a/borghelper.sh +++ b/borghelper.sh @@ -266,6 +266,21 @@ fi if [ "$commonOptions" ]; then commonOptions=${commonOptions##[[:space:]]}; fi if [ "$restoreOptions" ]; then restoreOptions=${restoreOptions##[[:space:]]}; fi +# check/create restore path +if [ -d "$restorePath" ]; then + if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then + consoleError 5 'Cannot write to specified restore directory.' + fi +else + if ! mkdir -p "${restorePath}" > /dev/null 2>&1; then + consoleError 5 'Cannot create specified restore directory.' + else + if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then + consoleError 5 'Cannot write to specified restore directory.' + fi + fi +fi + ### read borg information file @@ -372,6 +387,7 @@ exit 0 # 1: parameter error (missing, non-existant or invalid input) # 2: parameter missing/invalid in .borgvars file # 3: could not create/remove borg tmp directory +# 4: could not write sample borgvars file (permissions?) +# 5: cannot create/write to restore path or could not remove touch.test file -#EOF# 4: could not write sample borgvars file (permissions?) -# 5: cannot create/write to restore path +#EOF \ No newline at end of file