ppa-purge

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
dinolib
Level 1
Level 1
Posts: 2
Joined: Thu Jun 10, 2010 4:20 am

ppa-purge

Post by dinolib »

Hi to everybody.
I'm running mint 9-isadora.
Just for fun and interest in the state-of-the-art of new open video drivers (nouveau and Gallium3D) I've installed the xorgs-edgers repositories.
Everything was fine, I've tried some trick, but now I'd like to come back to the original repositories and packages.
As mentioned on many tutorials, I've used the ppa-purge utility. The problem is that it try to replace packages for "isadora" and not "lucid" as it is.

Does anybody know how to properly use ppa-purge on mint, or it's better to reinstall isadora (or just let the things as they are)?

thank you for your replies
DIno

dinolib
Level 1
Level 1
Posts: 2
Joined: Thu Jun 10, 2010 4:20 am

Re: ppa-purge

Post by dinolib »

I've temporary solved patching the script.
I've added an option "-d" to force the distribution.

The code:

Code: Select all

#!/bin/sh
# A script to remove all packages in a PPA and revert back to the normal
# distribution ones.
#
# AUTHORS: Robert Hooker (Sarvatt), Tormod Volden
#
# History:
# v0.1   - 2009-07-28: Initial Revision.
# v0.2   - 2009-07-29: Add warnings, do not remove ppa-purge package
# v0.2.2 - 2009-08-05: Fix command option parsing errors
# v0.2.3 - 2009-08-06: Removed verbose option. Also minor fixups
# v0.2.4 - 2009-08-13: Package dependencies
# v0.2.5 - 2009-09-30: New command syntax, various code rewrites

# Defaults
PPAHOST=ppa.launchpad.net
PPANAME=ppa

DIST=$(lsb_release -c -s)
ARCH=$(dpkg --print-architecture)
PPA_PKGS=$(mktemp)
REVERTS=$(mktemp)
trap "rm $PPA_PKGS $REVERTS" 0

# Functions to write output nicely.
write_msg() {
    echo "$*" | fold -s -w "${COLUMNS:-80}"
}

msg() {
	write_msg "$*"
}

warn() {
	write_msg "Warning:  $*" 1>&2
}

usage() {
	echo "Usage: sudo ppa-purge [options] <ppa-name>"
	echo
	echo "ppa-purge will reset all packages from a PPA to the standard"
	echo "versions released for your distribution."
	echo
	echo "Options:"
	echo "	-p [ppa]	Name of the PPA to be reset (default: ppa)"
	echo "	-d [dist]	Force the distribution"
	echo "	-s [host]	Repository server (default: ppa.launchpad.net)"
	echo "	-h      	Display this help text"
	echo
	echo "Example usage commands:"
	echo "	  sudo ppa-purge xorg-edgers"
	echo "	will remove https://launchpad.net/~xorg-edgers/+archive/ppa"
	echo
	echo "	  sudo ppa-purge -p xorg-testing sarvatt"
	echo "	will remove https://launchpad.net/~sarvatt/+archive/xorg-testing"
	echo
	echo "	  sudo ppa-purge ppa:ubuntu-x-swat/x-updates"
	echo "	will remove https://launchpad.net/~ubuntu-x-swat/+archive/x-updates"
	echo
	exit $1
}

# Command line options
while getopts "p:s:d:h\?" opt; do
	case "$opt" in
		p ) PPANAME="$OPTARG"				;;
		s ) PPAHOST="$OPTARG"				;;
		d ) DIST="$OPTARG"				;;
		h ) usage 0;					;;
		\?) usage 1;					;;
		* ) warn "Unknown option '$opt'"; usage 1;	;;
	esac
done
shift $(($OPTIND -1))

PPAOWNER=$1

if echo $1 | grep -q "^ppa:"; then
	PPAOWNER=$(echo $1 | sed "s#^ppa:\(.*\)/\(.*$\)#\1#")
	PPANAME=$(echo $1 | sed "s#^ppa:\(.*\)/\(.*$\)#\2#")
fi

if [ -z "$PPAOWNER" ]; then
	warn "Required ppa-name argument was not specified"
	usage 1
fi

if [ "$(id -u)" != "0" ]; then
	warn "This script would need superuser privileges, use sudo"
fi

msg "PPA to be removed: $PPAOWNER $PPANAME"

# Make list of all packages in PPA
PPA_LIST=/var/lib/apt/lists/${PPAHOST}_${PPAOWNER}_${PPANAME}_*_Packages
for LIST in $PPA_LIST; do
	if [ -e $LIST ]; then
		grep "^Package: " $LIST | cut -d " " -f2 | sort >> $PPA_PKGS
	fi
done

if [ ! -s $PPA_PKGS ]; then
	warn "Could not find package list for PPA: $PPAOWNER $PPANAME"
	exit 1
fi

# Ignore the ppa-purge package
if grep -q "ppa-purge" $PPA_PKGS; then
	sed -i '/ppa-purge/d' $PPA_PKGS
	msg "Note: Not removing ppa-purge package"
fi

dpkg --get-selections | awk '/install$/{print $1}' |
     sort | comm -12 - $PPA_PKGS > $REVERTS

# Create apt-get argument list for reverting packages
REINSTALL=""
for PACKAGE in $(cat $REVERTS); do
	REINSTALL="$REINSTALL $PACKAGE/$DIST"
done

msg "Package revert list generated:"
msg "$REINSTALL"
echo

# Disable PPA from sources.list files
for LIST in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
	if [ -e $LIST ] && grep -q $PPAOWNER/$PPANAME $LIST; then
		msg "Disabling $PPAOWNER PPA from $LIST"
		sed -ri "\:^[^#]+/${PPAOWNER}/${PPANAME}/:s/^deb/# deb/" $LIST
	fi
done

msg "Running apt-get update"
apt-get update > /dev/null || warn "apt-get update failed for some reason"

# FIXME:
# Workaround for now in case apt-get fails because of a package not in Ubuntu.
# Aptitude actually works but it would be preferred to remove the package
# from $REINSTALL directly.

if apt-get install $REINSTALL; then
	msg "PPA purged successfully"
elif aptitude install $REINSTALL; then
	msg "PPA purged successfully using aptitude fallback"
else
	warn "Something went wrong, packages may not have been reverted"
	exit 1
fi
exit 0

bohoomil
Level 1
Level 1
Posts: 3
Joined: Fri Jan 22, 2010 5:56 am

Re: ppa-purge

Post by bohoomil »

Thank you so much -- it's working like a charm.

Post Reply

Return to “Software & Applications”