Created
May 12, 2021 04:59
-
-
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
This file contains hidden or 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 | |
# 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