When I upgrade from 11.10 to 12.04, what's the best way to re-enable my PPAs and added repositories?
5 Answers
You need to add them all back/re-enabled them individually by uncommenting the lines in the files in the /etc/apt/sources.list.d/ directory.
Though upgrade time is a good time to reevaluate if you need the PPA in the first place if you were just using one to get a newer version of a package.
- 69,223
- 56
- 216
- 327
- 70,934
- 124
- 466
- 653
I wrote a bash script that removes the leading hash character from all files in sources.list.d that were disabled during the upgrade.
The following code is for upgrading raring sources to saucy.
If you want to keep the suffix # disabled on upgrade to ..., use
for f in /etc/apt/sources.list.d/*.list; do sudo sed -i 's/raring/saucy/g' $f; sudo sed -i 's/^# \(.*disabled on upgrade to.*\)/\1/g' $f;done
if you want to delete the suffix # disabled on upgrade to ..., use
for f in /etc/apt/sources.list.d/*.list; do sudo sed -i 's/raring/saucy/g' $f; sudo sed -i 's/^# \(.*\) # disabled on upgrade to.*/\1/g' $f;done
- 316
- 3
- 6
Here's a python script that uses the Python APT API to find and enable such sources, while setting the release to the current release:
#! /usr/bin/python3
import aptsources.sourceslist as sl
import lsb_release
codename = lsb_release.get_distro_information()['CODENAME']
sources = sl.SourcesList()
for source in sources.list:
if source.comment.lower().find("disabled on upgrade") >= 0:
source.dist = codename
source.set_enabled(True)
print(source)
sources.save()
If you run it without sudo, it won't be able to save changes, but it will show which sources would be enabled. Run with sudo to save the changes.
- 193,181
- 53
- 473
- 722
-
Does this replace, for instance, '# deb http://cran.rstudio.com/bin/linux/ubuntu artful/' with '# deb http://cran.rstudio.com/bin/linux/ubuntu bionic'? What would happen if you didn't do that (as the response ahead of your does)? – Jeffrey Benjamin Brown Jul 01 '18 at 03:38
-
@JeffreyBenjaminBrown it does, and if you don't replace it, it might happen that dependencies can't be satisfied. – muru Jul 01 '18 at 05:59
-
I found that the word "artful" (the 17.10 codename) had been replaced with "bionic" in some of the lines that were commented "disabled on upgrade ...", while others weren't. I just uncommented all the lines with that "disabled" comment and apt proceeded to work (although I had to reinstall gcc for some reason). And I use a lot of third-party repos -- 13 files in `sources.list.d`, and three alien ones in `sources.list`. Might this be something that Ubuntu takes care of automatically now? – Jeffrey Benjamin Brown Jul 02 '18 at 07:13
-
@JeffreyBenjaminBrown Possibly, I haven't upgraded in recent times (fresh installs, usually), so dunno. – muru Jul 02 '18 at 07:21
-
1This seems to have broken my apt sources files for 19.10 – Dreamcat4 Oct 24 '19 at 12:47
-
@Dreamcat4 without knowing what your `sources.list` looks like, not much I can do. – muru Mar 19 '20 at 02:52
To check and automatically update the source.list file, I created a script using curl and codename as follows.
#!/bin/bash
CODENAME="$(lsb_release -cs)"
for file in /etc/apt/sources.list.d/*.list;
do
APT_URL="$(cat $file | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*' | sort | uniq)"
CURRENT_CODES="$(cat $file | rev | awk '{NF=2}1' | rev | awk '{print $1;}')"
LENGTH=${#APT_URL}
[[ ${APT_URL:LENGTH-1:1} != */ ]] && APT_URL="$APT_URL/"; :
NEW_APT_URL="${APT_URL}dists/${CODENAME}"
echo -n "$NEW_APT_URL"
STATUS=$(curl --head --location --write-out %{http_code} --silent --output /dev/null ${NEW_APT_URL})
if [[ $STATUS == 200 ]]; then
echo -en "\e[93m OK\033[0m"
for code in $CURRENT_CODES;
do
[[ $code != $CODENAME ]] && sudo sed -i "s/$code/$CODENAME/g" $file
done;
sudo sed -i 's/^# \(.*\) # disabled on upgrade to.*/\1/g' $file
echo -e "\e[92m DONE\033[0m"
else
echo -e "\e[91m NOT FOUND\033[0m"
fi
done;
I have created a couple of scripts to both enable (re-enable) and disable PPAs, specially after an upgrade. Here they are:
PPA re-enable script
#! /bin/bash
# PPA re-enable script
# Use: ppa-reenable source.list
# to reenable a PPA without its source line
# Use: ppa-reenable src source.list
# to reenable a PPA with its source line
mod=1
file="$1"
if [ $1 == "src" ]; then mod=""; file="$2"; fi;
sudo sed -i "${mod}s/^# \(.*\) \(disabled on upgrade.*\)\?/\1/" "$file"
PPA disable script
#! /bin/bash
# PPA disable script
# Use: ppa-disable source.list
# to disable the PPA completely
# Use: ppa-disable src source.list
# to disable the source of the PPA only
file="${1}"
mod=""
# If its only needed to disable the source
if [ $1 = "src" ]; then mod="2"; file="${2}"; fi;
# If source line is disabled, don't comment it out
second="`sed -n 2p \"$file\"`"
second="${second:0:1}"
if ( [ $second == "#" ] && [ $mod != "2" ] ); then
mod="1"
fi
sudo sed -i "${mod}s/^/# /" "$file"
The sudo is included so you can store this script in your home bin directory
- 193,181
- 53
- 473
- 722
- 5,951
- 4
- 35
- 44