Skip to content

Commit 03b91f8

Browse files
committed
Merge pull request #91 from github/ghe-negotiate-version
Use the new ghe-negotiate-version script
2 parents b0b5041 + 2e59641 commit 03b91f8

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

bin/ghe-host-check

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ port=$(ssh_port_part "$host")
2424
hostname=$(ssh_host_part "$host")
2525

2626
set +e
27-
output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o BatchMode=no $options $host -- /bin/sh 2>&1)
27+
output=$(echo "ghe-negotiate-version backup-utils $BACKUP_UTILS_VERSION" | ghe-ssh -o BatchMode=no $options $host -- /bin/sh 2>&1)
2828
rc=$?
29+
if [ $rc = 127 ]; then
30+
# ghe-negotiate-version not found, fallback to reading version file
31+
legacy_version_output="1"
32+
output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o BatchMode=no $options $host -- /bin/sh 2>&1)
33+
rc=$?
34+
fi
2935
set -e
3036

3137
if [ $rc -ne 0 ]; then
@@ -55,9 +61,14 @@ if [ $rc -ne 0 ]; then
5561
exit $rc
5662
fi
5763

58-
version=$(echo "$output" | grep version | cut -d'"' -f4)
64+
if [ -z "$legacy_version_output" ]; then
65+
version=$(echo "$output" | sed -n 's/GitHub Enterprise version \(.*\)/\1/p')
66+
else
67+
version=$(echo "$output" | grep version | cut -d'"' -f4)
68+
fi
69+
5970
if [ -z "$version" ]; then
60-
echo "Error: failed to parse version from $GHE_REMOTE_METADATA_FILE on '$host' or this isn't a GitHub appliance." 1>&2
71+
echo "Error: failed to parse version on '$host' or this isn't a GitHub appliance." 1>&2
6172
exit 2
6273
fi
6374

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# scripts source us in according to the instructions above.
1616
GHE_BACKUP_ROOT="$(pwd)"
1717

18+
# Get the version from the version file.
19+
BACKUP_UTILS_VERSION="$(cat share/github-backup-utils/version)"
20+
1821
# Add the bin and share/github-backup-utils dirs to PATH
1922
PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH"
2023

@@ -109,8 +112,9 @@ GHE_SNAPSHOT_DIR="$GHE_DATA_DIR"/"$GHE_SNAPSHOT_TIMESTAMP"
109112
# allows the location to be overridden in tests.
110113
: ${GHE_REMOTE_LICENSE_FILE:="$GHE_REMOTE_DATA_DIR/enterprise/enterprise.ghl"}
111114

112-
# The location of the metadata file on the remote side. This is always
113-
# "/data/enterprise/chef_metadata.json" for GitHub instances. Use of this variable
115+
# The legacy location of the metadata file on the remote side. Only used if
116+
# the newer "ghe-negotiate-version" script cannot be found or fails. This was
117+
# "/data/enterprise/metadata.json" for GitHub instances. Use of this variable
114118
# allows the location to be overridden in tests.
115119
: ${GHE_REMOTE_METADATA_FILE:="$GHE_REMOTE_DATA_DIR/enterprise/chef_metadata.json"}
116120

share/github-backup-utils/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0.1

test/test-ghe-backup-config.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ GHE_REMOTE_DATA_DIR="$TRASHDIR/remote"
1212
export GHE_DATA_DIR GHE_REMOTE_DATA_DIR
1313

1414
# Source in the config script
15-
. "$ROOTDIR/share/github-backup-utils/ghe-backup-config"
15+
cd "$ROOTDIR"
16+
. "share/github-backup-utils/ghe-backup-config"
1617

1718
begin_test "ghe-backup-config ssh_host_part"
1819
(

0 commit comments

Comments
 (0)