X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Fgpg_import_key.sh;h=94ffbaab58e94ab2f1cbf79a54db231aa6c0afb4;hb=28f7d7c0ef101a6660b743620e0f2d5aa3e8993e;hp=80b7c397eb0a649eb69d5350fa26a74e13953208;hpb=2bfd92884d8f6b754329d639bc4b18e1bbf55303;p=releng.git diff --git a/utils/gpg_import_key.sh b/utils/gpg_import_key.sh index 80b7c397e..94ffbaab5 100755 --- a/utils/gpg_import_key.sh +++ b/utils/gpg_import_key.sh @@ -7,25 +7,42 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## - function isinstalled { -if rpm -q "$@" >/dev/null 2>&1; then - true - else - echo installing "$1" - sudo yum install "$1" - false + +source /etc/os-release; echo ${ID/*, /} + +if [[ ${ID/*, /} =~ "centos" ]]; then + if rpm -q "$@" >/dev/null 2>&1; then + true + else + echo installing "$1" + sudo yum install "$1" + false + fi + +elif [[ ${ID/*, /} =~ "ubuntu" ]]; then + if dpkg-query -W -f'${Status}' "$@" 2>/dev/null | grep -q "ok installed"; then + true + else + echo installing "$1" + sudo apt-get install -y "$1" + false + fi +else + echo "Distro not supported" + exit 0 fi + } if ! isinstalled gnupg2; then echo "error with install" - exit 1 + exit 0 fi if ! which gsutil; then echo "error gsutil not installed"; - exit 1 + exit 0 fi if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then @@ -33,11 +50,15 @@ if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then else if [ -z "$NODE_NAME" ]; then echo "Cannot find node name" - exit 1 - else echo "Importing key for '$NODE_NAME'"; - gsutil cp gs://opnfv-signing-keys/"$NODE_NAME"-subkey . - gpg2 --import "$NODE_NAME"-subkey - rm -f "$NODE_NAME"-subkey - fi + exit 0 + elif gsutil ls gs://opnfv-signing-keys | grep $NODE_NAME; then + echo "Importing key for '$NODE_NAME'" + gsutil cp gs://opnfv-signing-keys/"$NODE_NAME"-subkey . + gpg2 --import "$NODE_NAME"-subkey + rm -f "$NODE_NAME"-subkey + else + echo "No keys found locally or remotely for host, skipping import" + exit 0 + fi fi