Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created May 12, 2021 04:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnakamur/bfcdc6ad924f3bfe266c1d8dcb171efa to your computer and use it in GitHub Desktop.
Save hnakamur/bfcdc6ad924f3bfe266c1d8dcb171efa to your computer and use it in GitHub Desktop.
Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
#!/bin/bash
# apt-key-add - Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
#
# example:
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key-add - nodesource
# instead of
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
#
set -e
if [ $# -ne 2 -o $UID -ne 0 ]; then
cat <<EOF >&2
Usage: my-apt-key-add src dest_basename
Specify - for src to use stdin as input.
The imported key filename will be "/etc/apt/trusted.gpg.d/\${dest_basename}.gpg".
This script must be executed by root.
EOF
exit 2
fi
src="$1"
dest="/etc/apt/trusted.gpg.d/$2.gpg"
if [ -f "$dest" ]; then
echo "Exiting without adding key since destination file $dest already exists." >&2
exit 1
fi
gpg --no-default-keyring --keyring "gnupg-ring:$dest" --import "$src"
chmod 644 "$dest"
rm "$dest~"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment