ComputersManaging PPAs in Ubuntu: a couple of useful scripts.

PPAs are really a great thing in Ubuntu: they allow you to have quite recent programs without upgrading all your system; most Ubuntu users use them extensively.

They have just one problematic side — the havoc that can happen on an upgrade. You see, when you upgrade your system, PPAs are disabled, but the program they have installed are not downgraded automatically. That means that the upgrade process can have to deal with some program which is different from the expected one, causing problems sometime. So I normally when I upgrade my system I will purge all the PPAs and then I reinstall them after the upgrade (if they are available).

To do that rapidly I have a couple of scripts that are quite useful at least to me. The first one is this one:

#! /bin/bash
#
# 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

save it as, for example, list_ppa and upon calling it, you’ll have:

[romano:~/software/scripts] % ./list_ppa.sh 
sudo apt-add-repository ppa:tualatrix/ppa
sudo apt-add-repository ppa:fransschreuder1/qucs
[...]

Even more useful is this one, call it list_ppa_packages :

#! /bin/bash
#
list_all_packages_repos() {    
apt-cache policy $(dpkg -l | awk 'NR >= 6 { print $2 }') |
  awk '/^[^ ]/    { split($1, a, ":"); pkg = a[1] }
    nextline == 1 { nextline = 0; printf("%-40s %-50s %s\n", pkg, $2, $3) }
    /\*\*\*/      { nextline = 1 }'
    }

list_packages_of() { #1 is the tmpfile, $2 is the ppa regexp
    grep $2 $1 | awk '{print "---> ", $1}'
}

# cache all packages files now 

tmpfile=/tmp/list_pcks.$$.txt 
list_all_packages_repos > $tmpfile

# 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  PPA:$USER/$PPA
    list_packages_of $tmpfile "$USER/$PPA"
    done
done

rm $tmpfile

This will give an output like that (it’s slow — be patient):

[romano:~/software/scripts] % ./list_ppa_packages.sh 
PPA:tualatrix/ppa
---> ubuntu-tweak
PPA:fransschreuder1/qucs
---> qucs
PPA:nilarimogard/webupd8
---> ap-hotspot
---> libguess1
---> libmowgli-2-0
[...]

…and with the output of these two command is really a breeze to reinstall your PPAs after an upgrade.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  


*