Answers:
我编写了一个bash脚本,该脚本从sources.list.d
升级过程中禁用的所有文件中删除前导哈希字符。
以下代码用于将raring
源升级到saucy
。
如果要保留后缀# disabled on upgrade to ...
,请使用
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
如果要删除后缀# disabled on upgrade to ...
,请使用
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
这是一个Python脚本,该脚本使用Python APT API查找并启用此类源,同时将发行版设置为当前发行版:
#! /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()
如果不使用来运行它sudo
,它将无法保存更改,但是它将显示将启用哪些源。运行sudo
以保存更改。
sources.list.d
,并包含3个外来文件sources.list
。这可能是Ubuntu现在自动处理的吗?
我创建了两个脚本来启用(重新启用)和禁用PPA,尤其是在升级之后。他们来了:
PPA重新启用脚本
#! /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禁用脚本
#! /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"
该sudo
包括在内,以便您能在自己家bin目录中存储这些脚本