Sunday, February 12, 2017

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


I know how to list all packages installed on my system.


But how could I get a list of all repositories and PPA's into a script that I can run on a new machine to replicate the repository setup including the keys?


I know I can look into /etc/apt/sources.list and /etc/apt/sources.list.d, but I'm looking for a way to generate a script that executes all apt-add-repository commands on a new system (that sorts out getting all keys).


Any ideas?



Thanks for the pointers. With a little cleanup I got a script that lists the PPAs, but not any other repository:


#! /bin/sh
# listppa Script to get all the PPA installed on a system ready to share for reininstall
for APT in `find /etc/apt/ -name \*.list`; do
grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do
USER=`echo $ENTRY | cut -d/ -f4`
PPA=`echo $ENTRY | cut -d/ -f5`
echo sudo apt-add-repository ppa:$USER/$PPA
done
done

When you call it with listppa > installppa.sh you get a script you can copy on a new machine to reinstall all PPA.


Next stop: do that for the other repositories:


#! /bin/sh
# Script to get all the PPA installed on a system
for APT in `find /etc/apt/ -name \*.list`; do
grep -Po "(?<=^deb\s).*?(?=#|$)" $APT | while read ENTRY ; do
HOST=`echo $ENTRY | cut -d/ -f3`
USER=`echo $ENTRY | cut -d/ -f4`
PPA=`echo $ENTRY | cut -d/ -f5`
#echo sudo apt-add-repository ppa:$USER/$PPA
if [ "ppa.launchpad.net" = "$HOST" ]; then
echo sudo apt-add-repository ppa:$USER/$PPA
else
echo sudo apt-add-repository \'${ENTRY}\'
fi
done
done

This should do the trick. I needed a question on superuser to figure out the correct regex.


No comments:

Post a Comment

11.10 - Can&#39;t boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...