Sunday, May 5, 2024
121
rated 0 times [  121] [ 0]  / answers: 1 / hits: 653287  / 2 Years ago, thu, december 16, 2021, 2:36:02

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?


More From » command-line

 Answers
0

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


listppas script:


#! /bin/sh 

# listppas Script to get all the PPAs 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 listppas > installppas.sh you get an installppas.sh script you can copy onto a new machine to reinstall all PPAs.


Next stop: do that for the other repositories:


Final listppas script:


#! /bin/sh

# Script to get all the PPAs which are installed on a system

for APT in `find /etc/apt/ -name *.list`; do
grep -Po "(?<=^debs).*?(?=#|$)" $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. Use it as listppas > installppas.sh on the source machine, then run the contents of installppas.sh on the destination machine.


I needed a question on superuser to figure out the correct regex.


[#37735] Friday, December 17, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ionodest

Total Points: 252
Total Questions: 122
Total Answers: 100

Location: Liechtenstein
Member since Tue, Apr 27, 2021
3 Years ago
ionodest questions
Sat, Jan 1, 22, 06:31, 2 Years ago
Wed, May 12, 21, 03:21, 3 Years ago
Tue, Feb 22, 22, 09:46, 2 Years ago
Thu, Jun 30, 22, 12:12, 2 Years ago
;