summaryrefslogtreecommitdiff
path: root/integration/scripts/files/elements/guest-agent/environment.d/99-reliable-apt-key-importing.bash
blob: 9622b29257b3f1a3af3c889294ff427fcd48af98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# sometimes the primary key server is unavailable and we should try an
# alternate.  see
# https://bugs.launchpad.net/percona-server/+bug/907789.  Disable
# shell errexit so we can interrogate the exit code and take action
# based on the exit code. We will reenable it later.
#
# NOTE(zhaochao): we still have this problem from time to time, so it's
# better use more reliable keyservers and just retry on that(for now, 3
# tries should be fine).
# According to:
# [1] https://www.gnupg.org/faq/gnupg-faq.html#new_user_default_keyserver
# [2] https://sks-keyservers.net/overview-of-pools.php
# we'll just the primary suggested pool: pool.sks-keyservers.net.
function get_key_robust() {
    KEY=$1
    set +e

    tries=1
    while [ $tries -le 3 ]; do
        if [ $tries -eq 3 ]; then
            set -e
        fi

        echo "Importing the key, try: $tries"
        # Behind a firewall should use the port 80 instead of the default port 11371
        apt-key adv --keyserver hkp://pool.sks-keyservers.net:80 --recv-keys ${KEY} && break

        tries=$((tries+1))
    done

    set -e
}

export -f get_key_robust