Skip to content

Commit 93cfc1d

Browse files
committed
Move backup.config file finding around a bit
1 parent 63990de commit 93cfc1d

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

share/github-backup-utils/ghe-backup-config

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH"
2020

2121
# The backup config file. This may be set in the environment.
2222
: ${GHE_BACKUP_CONFIG:="$GHE_BACKUP_ROOT/backup.config"}
23-
if [ ! -f $GHE_BACKUP_CONFIG ]; then
24-
GHE_BACKUP_CONFIG="/etc/github-backup-utils/backup.config"
25-
fi
2623

2724
# Parse out -v (verbose) argument
2825
if [ "$1" = "-v" ]; then
@@ -39,20 +36,29 @@ else
3936
exec 3>/dev/null
4037
fi
4138

42-
# Check that the config file exists before we source it in.
43-
if [ ! -f "$GHE_BACKUP_CONFIG" ]; then
44-
echo "Error: No backup configuration file found. Tried:"
45-
echo " - $GHE_BACKUP_ROOT/backup.config"
46-
echo " - /etc/github-backup-utils/backup.config"
47-
exit 2
48-
fi
49-
5039
# Save off GHE_HOSTNAME from the environment since we want it to override the
5140
# backup.config value when set.
5241
GHE_HOSTNAME_PRESERVE="$GHE_HOSTNAME"
5342

54-
# Source in the backup config file.
55-
. "$GHE_BACKUP_CONFIG"
43+
# Source in the backup config file from the local working copy location first
44+
# and then falling back to the system location.
45+
config_found=false
46+
for f in "$GHE_BACKUP_CONFIG" "/etc/github-backup-utils/backup.config"; do
47+
if [ -f "$f" ]; then
48+
GHE_BACKUP_CONFIG="$f"
49+
. "$GHE_BACKUP_CONFIG"
50+
config_found=true
51+
break
52+
fi
53+
done
54+
55+
# Check that the config file exists before we source it in.
56+
if ! $config_found; then
57+
echo "Error: No backup configuration file found. Tried:" 1>&2
58+
echo " - $GHE_BACKUP_CONFIG" 1>&2
59+
echo " - /etc/github-backup-utils/backup.config" 1>&2
60+
exit 2
61+
fi
5662

5763
# Restore saved of hostname.
5864
[ -n "$GHE_HOSTNAME_PRESERVE" ] && GHE_HOSTNAME="$GHE_HOSTNAME_PRESERVE"

0 commit comments

Comments
 (0)