Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 601  / 1 Year ago, mon, february 6, 2023, 4:06:24

Is there a way to automatically delete or disable a ppa that does not work anymore?



When I do apt-get update I get a lot of error message regarding some ppas that cant be found.



I have disabled them by hand for now, but is there a way to disable them automatically? Since I have many ppas it is a lot of work to search and disable them by hand.


More From » 12.04

 Answers
3

You can use a script to disable/enable a ppa very easily. Save the script as toggle_ppa.sh and put it in /usr/local/bin



#!/bin/bash
#
# toggle_ppa.sh
#
# DESCRIPTION: Detects if a PPA is active/inactive and deactivates/activates it
# on user confirmation.

SOURCEDIRECTORY=/etc/apt/sources.list.d
PPA="$1"
if [ -z "$PPA" ]
then
echo "Error: Please provide a PPA name to toggle between activation/deactivation"
echo "The PPA name should be formatted as it appears on launchpad, e.g.:
"$0" ppa:webupd8team/y-ppa-manager"
exit 1
fi

## Root privileges

if [ "$(whoami)" != "root" ]; then
echo "Error: This script needs root privileges. Restarting..."
sudo "$0" "$1"
exit
fi

### MAIN

SOURCELIST_NOPFX="${PPA#*:}" #remove 'ppa:' prefix
SOURCELIST="${SOURCELIST_NOPFX////-}"-$(lsb_release -cs) #replace all slashes with dashes, include release
SOURCEFILE="$SOURCEDIRECTORY"/"$SOURCELIST".list #compose sources list path

if [ -e "$SOURCEFILE" ]
then
echo "Processing $SOURCEFILE..."
SOURCE_COMMENTED=$(grep "^#deb " "$SOURCEFILE") #check if sources line is commented
if [ -z "$SOURCE_COMMENTED" ]
then
echo "$PPA is active. Going to deactivate. Proceed? [ y/n ]"
read ANSWER
if [ $ANSWER == "y" ]
then
sed -i "s/^deb-src/#deb-src/" $SOURCEFILE
sed -i "s/^deb http/#deb http/" $SOURCEFILE
echo "Updating package index files..."
sudo apt-get update
echo "Done."
else
echo "Aborted."
exit 0
fi
else
echo "$PPA is inactive. Going to activate. Proceed? [ y/n ]"
read ANSWER
if [ $ANSWER == "y" ]
then
sed -i "s/^#deb-src/deb-src/" $SOURCEFILE
sed -i "s/^#deb http/deb http/" $SOURCEFILE
echo "Updating package index files..."
sudo apt-get update
echo "Done."
else
echo "Aborted."
exit 0
fi
fi
else
echo "Error: Source file at $SOURCEFILE for $PPA does not exist. Please check PPA name."
exit 0
fi


Usage



sudo toggle_ppa.sh <full-ppa-name>


Example



sudo toggle_ppa.sh ppa:webupd8team/java


How it works



When any ppa repo is deactivated using Software center (GUI), it actually puts a # in front of all the lines inside corresponding ppa .list file at /etc/apt/sources.list.d/. Usually most of the .list files contain two lines that begins with deb http and deb-src, a few have only one. The above script is doing the same thing using sed. First it checks the ppa .list (input by user) is present or not. Then put or remove a # in front the lines accordingly.



The code acts in a very interactive manner. When someone runs this along with ppa name as its argument, it will display the PPA's current status and what the code is going to do on successful execution. Then it will ask permission of the user. Only if the user inputs 'y' to confirm the code will change the status of the PPA and activate/deactivate it. It will immediately abort if the user puts an 'n' for no.



Note I proposed this code in this answered. glutanimate helped a lot to improve the code.


[#35065] Wednesday, February 8, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
landarre

Total Points: 254
Total Questions: 96
Total Answers: 109

Location: Burundi
Member since Sun, Apr 16, 2023
1 Year ago
landarre questions
;