diff options
author | EuAndreh <eu@euandre.org> | 2024-08-16 09:46:30 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-08-16 09:46:30 -0300 |
commit | 3e9c89562d566e72cbaa53db3b1d0dfa8050b1f9 (patch) | |
tree | 1f13caf377e957d6151ba2647e3af902a9d879a3 | |
parent | Add imported code from dotfiles (diff) | |
download | backupit-3e9c89562d566e72cbaa53db3b1d0dfa8050b1f9.tar.gz backupit-3e9c89562d566e72cbaa53db3b1d0dfa8050b1f9.tar.xz |
src/backupit: Early exit on missing file
-rwxr-xr-x | src/backupit | 27 |
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") |