Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new ghe-negotiate-version script #91

Merged
merged 10 commits into from
Jan 15, 2015
17 changes: 14 additions & 3 deletions bin/ghe-host-check
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ port=$(ssh_port_part "$host")
hostname=$(ssh_host_part "$host")

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

if [ $rc -ne 0 ]; then
Expand Down Expand Up @@ -55,9 +61,14 @@ if [ $rc -ne 0 ]; then
exit $rc
fi

version=$(echo "$output" | grep version | cut -d'"' -f4)
if [ -z "$legacy_version_output" ]; then
version=$(echo "$output" | sed -n 's/GitHub Enterprise version \(.*\)/\1/p')
else
version=$(echo "$output" | grep version | cut -d'"' -f4)
fi

if [ -z "$version" ]; then
echo "Error: failed to parse version from $GHE_REMOTE_METADATA_FILE on '$host' or this isn't a GitHub appliance." 1>&2
echo "Error: failed to parse version on '$host' or this isn't a GitHub appliance." 1>&2
exit 2
fi

Expand Down
8 changes: 6 additions & 2 deletions share/github-backup-utils/ghe-backup-config
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# scripts source us in according to the instructions above.
GHE_BACKUP_ROOT="$(pwd)"

# Get the version from the version file.
BACKUP_UTILS_VERSION="$(cat share/github-backup-utils/version)"

# Add the bin and share/github-backup-utils dirs to PATH
PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH"

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

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

Expand Down
1 change: 1 addition & 0 deletions share/github-backup-utils/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.1
3 changes: 2 additions & 1 deletion test/test-ghe-backup-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ GHE_REMOTE_DATA_DIR="$TRASHDIR/remote"
export GHE_DATA_DIR GHE_REMOTE_DATA_DIR

# Source in the config script
. "$ROOTDIR/share/github-backup-utils/ghe-backup-config"
cd "$ROOTDIR"
. "share/github-backup-utils/ghe-backup-config"

begin_test "ghe-backup-config ssh_host_part"
(
Expand Down