Merge "flake 8 fix + add logger"
[releng.git] / utils / gpg_import_key.sh
1 #!/bin/bash -e
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 NEC and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 function isinstalled {
12 if rpm -q "$@" >/dev/null 2>&1; then
13   true
14     else
15       echo installing "$1"
16       sudo yum install "$1"
17   false
18 fi
19 }
20
21 if ! isinstalled gnupg2; then
22   echo "error with install"
23   exit 1
24 fi
25
26 if ! which gsutil;
27   then echo "error gsutil not installed";
28   exit 1
29 fi
30
31 if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
32   echo "Key Already available"
33 else
34   if [ -z "$NODE_NAME" ];
35     then echo "Cannot find node name"
36       exit 1
37     else echo "Importing key for '$NODE_NAME'";
38      gsutil cp gs://opnfv-signing-keys/"$NODE_NAME"-subkey .
39      gpg2 --import "$NODE_NAME"-subkey
40      rm -f "$NODE_NAME"-subkey
41    fi
42 fi