From: Thanh Ha Date: Tue, 29 Aug 2017 19:57:07 +0000 (-0400) Subject: Use gpg2 if available X-Git-Tag: v0.9.0~2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F6225%2F1;p=releng%2Flftools.git Use gpg2 if available Prefer gpg2 over gpg if it is available. In some systems such as Arch Linux gpg is gpg2. We really only support gpg2 for signing. Minor fix indentation to 4 spaces like the rest of the script. Change-Id: I6733521838c78da94b67ab81d9397f5b0622e283 Signed-off-by: Thanh Ha --- diff --git a/shell/sign b/shell/sign index dbd421f5..ed5c81e5 100755 --- a/shell/sign +++ b/shell/sign @@ -9,7 +9,12 @@ # http://www.eclipse.org/legal/epl-v10.html ############################################################################## -# Signs artifacts with gpg +# Sign artifacts with gpg + +GPG_BIN="gpg" +if hash gpg2 2>/dev/null; then + GPG_BIN="gpg2" +fi sign() { @@ -65,7 +70,7 @@ sign_dir() { for f in "${files_to_sign[@]}" do echo "Signing $f" - gpg --batch -abq "$f" + "$GPG_BIN" --batch -abq "$f" done set +e } @@ -164,18 +169,18 @@ sign_nexus() { test_gpg_key() { - # Test that our GPG key works by signing a test file. - - local test_file - test_file=$(mktemp) - echo "Test Signature" > "$test_file" - gpg --batch -abq "$test_file" - if ! gpg --verify "$test_file".asc "$test_file" > /dev/null 2>&1; then - echo "ERROR: Failed to validate signature." - rm "$test_file" "$test_file".asc # Cleanup before we exit - exit 1 - fi - rm "$test_file" "$test_file".asc # Cleanup tmp files + # Test that our GPG key works by signing a test file. + + local test_file + test_file=$(mktemp) + echo "Test Signature" > "$test_file" + "$GPG_BIN" --batch -abq "$test_file" + if ! "$GPG_BIN" --verify "$test_file".asc "$test_file" > /dev/null 2>&1; then + echo "ERROR: Failed to validate signature." + rm "$test_file" "$test_file".asc # Cleanup before we exit + exit 1 + fi + rm "$test_file" "$test_file".asc # Cleanup tmp files }