Skip to content

Replace "sed -E" in ghe-host-check with a more portable solution#509

Merged
lildude merged 2 commits into
masterfrom
taz/fix-host-check-portability
Aug 20, 2019
Merged

Replace "sed -E" in ghe-host-check with a more portable solution#509
lildude merged 2 commits into
masterfrom
taz/fix-host-check-portability

Conversation

@taz

@taz taz commented Aug 16, 2019

Copy link
Copy Markdown
Member

On older backup hosts, sed doesn't include the -E option which results in a ghe-host-check failure. While replacing sed with a newer option would be ideal, it's not always achievable in a short timeframe.

The proposed solution requires the version string to be at the end of the first string returned—is that a valid long term assumption? It will cope with any future product name changes more gracefully however, which is what sed -E was added to accomodate.

Comment thread bin/ghe-host-check Outdated
fi

version=$(echo "$output" | sed -E -n 's/GitHub Enterprise( Server)? version (.*)/\2/p')
version=$(echo "$output" | head -1 | awk '{print $NF}')

@snh snh Aug 16, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can output various error messages that would get incorrectly matched here. An alternative approach (that avoids using -E in grep too) would be:

Suggested change
version=$(echo "$output" | head -1 | awk '{print $NF}')
version=$(echo "$output" | grep '^GitHub Enterprise\( Server\)\? version [^ ]*$' | awk '{print $NF}')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch there @snh, it didn't turn up in my earlier testing. It looks like the test suite is cranky too. I'll adjust, re-test, and then see if the tests are still failing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I've not tested, but is there a risk this grep is moving the assumption of using a modern variant of sed to grep? I'm thinking some old versions of grep may behave like fgrep so can only use fixed strings.

An alternate solution is the one posed at #480 (comment) (also not tested)

version=$(echo "$output" | sed -n 's/GitHub Enterprise\( Server\)\{0,1\} version \(.*\)/\2/p')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the alternative solution above on MacOS and it works as expected, but I can't vouch for its portability either—I can probably find out though if we'd prefer to go down that path.

However are we backing ourselves into a corner re: options here by:

  1. Trying to do the check in one operation; and
  2. Looking for the word "Server"?

Can we assume that as long as "GitHub Enterprise" is present, it doesn't matter if "Server" is also there?

Why not pull the "GitHub Enterprise" string out first, and then manipulate the result to get the version number. eg:

echo "$output" | grep "GitHub Enterprise" | awk '{print $NF}'

That's a fixed string grep followed by an awk variable that I'm pretty sure has been there for a long time...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that would be safe to do.

@lildude lildude merged commit c2e1e64 into master Aug 20, 2019
@lildude lildude deleted the taz/fix-host-check-portability branch August 20, 2019 15:08
dooleydevin added a commit that referenced this pull request Oct 2, 2023
…mbigious-naming

Backport 488 for 3.9: transfer_size are estimated data transfer sizes
@dooleydevin dooleydevin mentioned this pull request Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants