Skip to content

Commit 69cf114

Browse files
authored
Merge pull request #286 from github/kathodos/utils-on-ghe-host-check
Check backup-utils are not being run on GitHub Enterprise host
2 parents cd67920 + 4a6b487 commit 69cf114

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ if [ ${GHE_DATA_DIR:0:1} != "/" ]; then
8383
GHE_DATA_DIR="$( cd "$GHE_BACKUP_ROOT" && readlink -m "$GHE_DATA_DIR" 2> /dev/null || echo "$GHE_BACKUP_ROOT/$GHE_DATA_DIR" )"
8484
fi
8585

86+
# Assign the Release File path if it hasn't been provided (eg: by test suite)
87+
: ${GHE_RELEASE_FILE:="/etc/github/enterprise-release"}
88+
89+
# Check that utils are not being run directly on GHE appliance.
90+
if [ -f "$GHE_RELEASE_FILE" ]; then
91+
echo "Error: Backup Utils cannot be run on the GitHub Enterprise host." 1>&2
92+
echo " The backup utilities should be run on a host dedicated to" 1>&2
93+
echo " long-term permanent storage and must have network connectivity" 1>&2
94+
echo " with the GitHub Enterprise appliance." 1>&2
95+
exit 1
96+
fi
97+
8698
GHE_CREATE_DATA_DIR=${GHE_CREATE_DATA_DIR:-yes}
8799

88100
# Check that the data directory is set and create it if it doesn't exist.

test/test-ghe-backup-config.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ begin_test "ghe-backup-config GHE_CREATE_DATA_DIR disabled"
4141
)
4242
end_test
4343

44+
begin_test "ghe-backup-config run on GHE appliance"
45+
(
46+
set -e
47+
48+
export GHE_RELEASE_FILE="$TRASHDIR/enterprise-release"
49+
touch "$GHE_RELEASE_FILE"
50+
set +e
51+
error=$(. share/github-backup-utils/ghe-backup-config 2>&1)
52+
# should exit 1
53+
if [ $? != 1 ]; then
54+
exit 1
55+
fi
56+
set -e
57+
echo "$error" | grep -q "Error: Backup Utils cannot be run on the GitHub Enterprise host."
58+
59+
test -f "$GHE_RELEASE_FILE"
60+
rm -rf "$GHE_RELEASE_FILE"
61+
)
62+
end_test
63+
4464
begin_test "ghe-backup-config ssh_host_part"
4565
(
4666
set -e
@@ -51,7 +71,6 @@ begin_test "ghe-backup-config ssh_host_part"
5171
)
5272
end_test
5373

54-
5574
begin_test "ghe-backup-config ssh_port_part"
5675
(
5776
set -e

0 commit comments

Comments
 (0)