online bottlenecks soak throughtputs
[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 function isinstalled {
11
12 source /etc/os-release; echo ${ID/*, /}
13
14 if [[ ${ID/*, /} =~ "centos" ]]; then
15   if rpm -q "$@" >/dev/null 2>&1; then
16     true
17       else
18         echo installing "$1"
19         sudo yum install "$1"
20     false
21   fi
22
23 elif [[ ${ID/*, /} =~ "ubuntu" ]]; then
24   if dpkg-query -W -f'${Status}' "$@" 2>/dev/null | grep -q "ok installed"; then
25     true
26       else
27         echo installing "$1"
28         sudo apt-get install -y "$1"
29     false
30   fi
31 else
32   echo "Distro not supported"
33   exit 0
34 fi
35
36 }
37
38 if ! isinstalled gnupg2; then
39   echo "error with install"
40   exit 0
41 fi
42
43 if ! which gsutil;
44   then echo "error gsutil not installed";
45   exit 0
46 fi
47
48 if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
49   echo "Key Already available"
50 else
51   if [ -z "$NODE_NAME" ];
52     then echo "Cannot find node name"
53       exit 0
54     else echo "Importing key for '$NODE_NAME'";
55      gsutil cp gs://opnfv-signing-keys/"$NODE_NAME"-subkey .
56      gpg2 --import "$NODE_NAME"-subkey
57      rm -f "$NODE_NAME"-subkey
58    fi
59 fi
60