Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Created December 5, 2022 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eusonlito/e8d547ebf039be5f1bba10233f75005b to your computer and use it in GitHub Desktop.
Save eusonlito/e8d547ebf039be5f1bba10233f75005b to your computer and use it in GitHub Desktop.
Batch migration from /etc/apt/trusted.gpg to custom keyring
#!/bin/bash
for KEY in $(apt-key --keyring /etc/apt/trusted.gpg list | grep -E "(([ ]{1,2}(([0-9A-F]{4}))){10})" | tr -d " " | grep -E "([0-9A-F]){8}\b" ); do K=${KEY:(-8)}; apt-key export $K | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/imported-from-trusted-gpg-$K.gpg; done
Came across this problem after moving to Ubuntu 22.04 and wanted to add my solution. I had a lot of keys that needed to be updated/converted. This is not an optimal solution, but works well.
This solution is specific to Ubuntu 22.04, with bash 5.2.16. Other distributions and versions may not work.
A one-liner to convert all those deprecated keys to the new format.
PLEASE TAKE THE TIME TO UNDERSTAND WHAT YOUR DOING HERE BEFORE RUNNING IT!! Also make sure your bash is not too old. My bash version: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Source: https://askubuntu.com/a/1415702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment