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?
You can show everything with:
Thanks for the pointers. With a little cleanup I got a script that lists the PPAs, but not any other repository:
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:
This should do the trick. I needed a question on superuser to figure out the correct regex.
I am surprised that the simplest but most effective way to get all enabled binary software sources together with the file they're specified in hasn't been posted yet:
From all processed files, this will print every line starting with
deb
. This excludes commented lines as well asdeb-src
lines to enable source code repositories.It searches really only all
*.list
files that will be parsed byapt
, but e.g. no*.list.save
files used for backup or others with illegal names.If you want a shorter but possibly only in 99.9% of all cases correct output that may search too much files (includes all
/etc/apt/sources.list*
files and directories, not only/etc/apt/sources.list
and `/etc/apt/sources.list.d/*), you could also use this:Unless there are files that shouldn't be there, the output will be the same.
An example output on my machine would be this:
If you want prettier output, let's pipe it through
sed
:And we will see this:
Run the following command:
Source
Here is my script, "
list-apt-repositories
", which lists all repositories in "/etc/sources.list"
and "/etc/sources.list.d/*.list
". You can add--ppa-only
to show only the PPAs. PPAs are automatically transformed toppa:USER/REPO
format.The relevant parts are the 5 lines in
list_sources
andlist_ppa
functions, the rest is just boilerplate to wrap it in a handy shell script.list-apt-repositories
:And to make an install script, pipe into another script "
make-apt-repository-install-script
". The generated script supports the-y
/--yes
argument for non-interactive use (seeadd-apt-repository(1)
).make-apt-repository-install-script
:Again, the important part is the
xargs
command on the last line, the rest is boilerplate.I use this command to list all configured software sources (repositories), including currently disabled ones:
I use this primarily for troubleshooting; this can certainly be incorporated into scripts but you may want to narrow
/etc/apt/sources.list.d/*
to/etc/apt/sources.list.d/*.list
so you only get currently enabled software sources.So, doing some digging, we have
AptPkg::Class
.So using
perl
we can do something simple like this..This gets us a list of all the
AptPkg::Class::PkgFile
packages. You could probably generate theapt-add-repository
commands with that.Here is a one liner:
Using
add-apt-repository
fromsoftware-properties-common
, it is as simple as:The output can easily be supplied back to
add-apt-repository
command to recreate the sources.However, it only lists
deb
sources. If you are interested also inppa
s, then the other answers on this question will be more useful.Availability
It appears that the
--list
option was only available since version 0.99.0+ ofsoftware-properties-common
, which is available by default starting from Ubuntu 20.10 (Groovy). So you will either need to update your version of the software, or upgrade your distro to atleast 20.10.https://repogen.simplylinux.ch/ will give you a list of all PPAs for your version of Ubuntu. Here is a generated list without source files and no samsung printer ppa: