summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-08-16 09:46:30 -0300
committerEuAndreh <eu@euandre.org>2024-08-16 09:46:30 -0300
commit3e9c89562d566e72cbaa53db3b1d0dfa8050b1f9 (patch)
tree1f13caf377e957d6151ba2647e3af902a9d879a3
parentAdd imported code from dotfiles (diff)
downloadbackupit-3e9c89562d566e72cbaa53db3b1d0dfa8050b1f9.tar.gz
backupit-3e9c89562d566e72cbaa53db3b1d0dfa8050b1f9.tar.xz
src/backupit: Early exit on missing file
-rwxr-xr-xsrc/backupit27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/backupit b/src/backupit
index 54c9581..ec99c32 100755
--- a/src/backupit
+++ b/src/backupit
@@ -26,9 +26,26 @@ shift $((OPTIND - 1))
TAG="${1:-default}"
ARCHIVE="::{hostname}-{user}-{now}-$TAG"
-F="$XDG_CONFIG_HOME"/backupit.txt
-if [ ! -e "$F" ]; then
- F=/etc/backup.txt
-fi
-borgy $VERBOSE_FLAGS "$ARCHIVE" $(cat "$F")
+
+xdg="${XDG_CONFIG_HOME:-$HOME/.config}"/backupit.txt
+global=/etc/backupit.txt
+f() {
+ if [ -e "$xdg" ]; then
+ printf '%s' "$xdg"
+ return
+ fi
+
+ if [ -e "$global" ]; then
+ printf '%s' "$global"
+ return
+ fi
+
+ printf 'Cannot find either\nlocal (%s) or\nglobal (%s) file.\n\n' \
+ "$xdg" "$global" >&2
+ usage >&2
+ exit 2
+}
+
+F="$(f)"
+exec borgy $VERBOSE_FLAGS "$ARCHIVE" $(cat "$F")