Skip to content

Instantly share code, notes, and snippets.

@dhasial
Created April 4, 2022 12:20
Show Gist options
  • Save dhasial/b8a74343b1a9904559f5829ecd386088 to your computer and use it in GitHub Desktop.
Save dhasial/b8a74343b1a9904559f5829ecd386088 to your computer and use it in GitHub Desktop.
Alternative script for "apt-key add" which is deprecated in Debian as of April 2022
#!/bin/bash
# apt-key-add - Alternative script for "apt-key add" which is deprecated in Debian as of April 2022
# 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 ] || [ $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