#!/bin/bash

APT_KEYRING_FILE="/etc/apt/trusted.gpg"
DOCKER_KEYRING_FILE="/etc/apt/trusted.gpg.d/download.docker.com.gpg"


is_key_installed=$(gpg --batch --no-tty --keyring ${DOCKER_KEYRING_FILE} --list-keys --with-colons|grep -q "0EBFCD88"; echo $?)
if [ $is_key_installed -eq 0 ]; then
    is_key_installed_in_old_location=$(gpg --batch --no-tty --keyring ${APT_KEYRING_FILE} --list-keys --with-colons|grep -q "0EBFCD88"; echo $?)
    if [ $is_key_installed_in_old_location -eq 0 ]; then
        echo "Remove Docker GPG key from default apt keyring file..."
        gpg --batch --no-tty --keyring ${APT_KEYRING_FILE} --yes --delete-keys 0EBFCD88
    fi
fi