Last active
July 15, 2023 01:21
-
-
Save pacmac/1395f3e8a32137c4bfdf5faeb8164f9b to your computer and use it in GitHub Desktop.
Fix Missing Keys when running apt update.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## bash <(curl -Ls https://gist.githubusercontent.com/pacmac/1395f3e8a32137c4bfdf5faeb8164f9b/raw/apt-keyfix.sh) | |
# Run apt update and capture the error output | |
error_output=$(apt update 2>&1) | |
# Check if the error output contains the key verification error message | |
if [[ $error_output =~ "The following signatures couldn't be verified because the public key is not available" ]]; then | |
# Retrieve the missing keys and run the apt-key command for each one | |
keys=$(grep -oE "NO_PUBKEY [0-9A-Fa-f]+" <<< "$error_output" | awk '{print $NF}') | |
for key in $keys; do | |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$key" | |
done | |
# Run apt update again to refresh the package lists | |
apt update | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment