Use gpg2 if available 25/6225/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 29 Aug 2017 19:57:07 +0000 (15:57 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 29 Aug 2017 20:22:34 +0000 (16:22 -0400)
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 <thanh.ha@linuxfoundation.org>
shell/sign

index dbd421f..ed5c81e 100755 (executable)
@@ -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
 }