30

Related to this question. But my concern is that over the past year, most of my more interesting (or used) applications are from PPAs, and just backing up my sources list won't add the associated launchpad keys the way that add-apt-repository does.

So I'm looking for a way to list all the PPA urls (like ppa:chromium-daily/stable) so that I can easily script a series of add-apt-repository commands to add them into a new installation gracefully.

Short of dumping my bash history of course. Which might be feasible, depending on how far back that file goes back?

5 Answers 5

44

Well because I like mucking around with command line scripting, I've written the following. It generates a list of PPA strings that you could backup and then script into add-apt-repository:

grep -RoPish '(?<=ppa.launchpad.net/)[^/]+/[^/ ]+' /etc/apt | sort -u | sed 's/^/ppa:/'

That'll generate something like:

ppa:ubuntu-wine/ppa
ppa:am-monkeyd/nautilus-elementary-ppa
ppa:nilarimogard/webupd8
ppa:ubuntu-x-swat/x-updates
ppa:tualatrix/ppa
ppa:banshee-team/banshee-unstable
ppa:chromium-daily/beta
ppa:libreoffice/ppa
ppa:banshee-team/ppa

If you ever wanted to blanket-restore those, you could pipe them back into the system like so (assuming we saved the PPAs to ~/ppa-backup.txt:

<~/ppa-backup.txt xargs -I % sudo add-apt-repository %

I would probably suggest you don't just restore them all. Look through the backup and make sure you know what each PPA contains.

3
  • Thanks Oli. I'll test that tonight and accept this once tested!
    – Scaine
    Mar 2, 2011 at 9:22
  • 1
    My god I have a lot of PPAs on my system. This is perfect, Oli. Thanks for your effort!
    – Scaine
    Mar 2, 2011 at 21:09
  • Doesn't work as written.
    – user447607
    May 20, 2016 at 0:58
6

What I do is that I copy the whole /etc/apt directory to a safe place. If you have to reinstall or clone your install, just copy back that directory. It'll save even the gpg trusted keys.

5

If importing all the GPG keys is what you're looking for, you can use my script (comes in a .deb) to import all missing GPG keys at once. Download

To use, simply run:

sudo launchpad-getkeys

You can take a look inside the .deb if you want, the script is really small and easy to understand (in case you don't trust my deb).

Then to back up all the PPAs, all you have to do is copy all the .list files on the new computer / new installation and once you've copied them, run the above command to import all the keys.

1

To backup all list of third-party deb-repositories along with Flatpaks and Snaps one can try my python script named srslsud (Save/Restore Software List Script for Ubuntu and Debian).
It will save all APT repositories, their GPG keys; lists of Snaps, Flatpaks and Ubuntu Make apps to JSON files from the first machine.
Then you can restore this list using same JSON files on the second machine.

# minimal for APT
sudo apt-get install python3 python3-gi python3-apt software-properties-common python3-jsonpickle

# additional for Snap, Flatpak
sudo apt-get install snapd flatpak gir1.2-snapd-1 gir1.2-flatpak-1.0

# additional for Ubuntu Make
sudo apt-get install ubuntu-make

cd ~/Downloads
wget https://raw.githubusercontent.com/N0rbert/srslsud/master/srslsud.py
chmod +x srslsud.py
./srslsud.py all_save

Then copy *.json files along with srslsud.py to the target system and run the following commands there:

./srslsud.py all_load
sudo bash ./apt.sh

And finally enjoy new cloned system.

Note: if you need only APT - use apt_save and apt_load instead.

1
0

From my answer on How can I get a list of all repositories and PPAs from the command line into an install script?

List PPAs in ppa:USER/REPO format:

list_ppas () {
  grep -E '^deb\s' /etc/apt/sources.list /etc/apt/sources.list.d/*.list |\
    cut -f2- -d: |\
    cut -f2 -d' ' |\
    sed -re 's#http://ppa\.launchpad\.net/([^/]+)/([^/]+)(.*?)$#ppa:\1/\2#g' |\
    grep '^ppa:'
}

Generate install script:

list_ppas | xargs printf 'add-apt-repository -y %s\n' > install_ppas.sh

(take out the -y if you don't want non-interactive install)

Run the script:

sudo sh install_ppas.sh

See my answer on the other question for full scripts with a few extra features that you can save and use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.