Answers:
您可以通过以下方式显示所有内容:
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*
cat /etc/apt/sources.list /etc/apt/sources.list.d/*
感谢您的指导。经过一点清理,我得到了一个脚本,其中列出了PPA,但没有列出任何其他存储库:
#! /bin/sh
# 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
当您调用它时,listppa > installppa.sh
会获得一个脚本,您可以在新计算机上复制以重新安装所有PPA。
下一站:对其他存储库执行此操作:
#! /bin/sh
# Script to get all the PPA installed on a system
for APT in `find /etc/apt/ -name \*.list`; do
grep -Po "(?<=^deb\s).*?(?=#|$)" $APT | while read ENTRY ; do
HOST=`echo $ENTRY | cut -d/ -f3`
USER=`echo $ENTRY | cut -d/ -f4`
PPA=`echo $ENTRY | cut -d/ -f5`
#echo sudo apt-add-repository ppa:$USER/$PPA
if [ "ppa.launchpad.net" = "$HOST" ]; then
echo sudo apt-add-repository ppa:$USER/$PPA
else
echo sudo apt-add-repository \'${ENTRY}\'
fi
done
done
grep -o
示例中,\`
in [a-z0-9\-]
并没有达到您的期望。它实际上与文字反斜杠匹配。你并不需要逃避的-
时候它是在开始或结束[]
列表; 实际上,您无法逃脱它!..在这种情况下,\`
(可能)不会引起问题,因为您(希望)在条目中不会遇到反斜线deb
。
http://ppa.launchpad.net/[a-z0-9-]\+/[a-z0-9.-]\+
[[:graph:]]
,[a-z...blah.anything]
因为它将与任何字母数字+标点符号匹配-这就是PPA名称的组成。
deb
在每个存储库行的开头都包含单词(如果未以ppa:$USER/$PPA
形式给出)。
grep -Po "(?<=^deb\s).*?(?=#|$)" /etc/apt/{sources.list,sources.list.d/*.list} | while read ENTRY ; do echo $ENTRY; done
请注意,按照本文的说明,您会看到每个条目的文件名,因此您需要从结果开头到第一个冒号进行修整,但是使用cut并不是很困难。uniq
如果您不希望同一来源的多个条目(例如,如果您安装了Google Chrome Stable / Beta / Dev),则可能还需要传递它。
让我感到惊讶的是,尚未发布将所有启用的二进制软件源以及在其中指定的文件一起获得的最简单但最有效的方法:
grep -r --include '*.list' '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/
对于所有已处理的文件,这将打印以开头的每一行deb
。这不包括注释行以及deb-src
启用源代码存储库的行。
它实际上仅搜索*.list
将由解析的所有文件,apt
例如,不搜索*.list.save
用于备份的文件或其他具有非法名称的文件。
如果您想要一个较短但可能仅占所有情况的99.9%的正确输出,可能搜索过多的文件(不仅包括所有/etc/apt/sources.list*
文件和目录,还包括/etc/apt/sources.list
`/etc/apt/sources.list.d/*),您也可以用这个:
grep -r --include '*.list' '^deb ' /etc/apt/sources.list*
除非存在不应该存在的文件,否则输出将相同。
我的机器上的示例输出如下:
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily main restricted
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates main restricted
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily universe
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates universe
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily multiverse
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates multiverse
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-backports main restricted universe multiverse
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security main restricted
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security universe
/etc/apt/sources.list:deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security multiverse
/etc/apt/sources.list:deb http://archive.canonical.com/ubuntu wily partner
/etc/apt/sources.list.d/maarten-fonville-ubuntu-ppa-wily.list:deb http://ppa.launchpad.net/maarten-fonville/ppa/ubuntu wily main
/etc/apt/sources.list.d/webupd8team-ubuntu-tor-browser-wily.list:deb http://ppa.launchpad.net/webupd8team/tor-browser/ubuntu wily main
/etc/apt/sources.list.d/fossfreedom-ubuntu-indicator-sysmonitor-wily.list:deb http://ppa.launchpad.net/fossfreedom/indicator-sysmonitor/ubuntu wily main
/etc/apt/sources.list.d/getdeb.list:deb http://archive.getdeb.net/ubuntu wily-getdeb apps
如果您想要更漂亮的输出,让我们通过sed
以下方式进行传递:
grep -r --include '*.list' '^deb ' /etc/apt/ | sed -re 's/^\/etc\/apt\/sources\.list((\.d\/)?|(:)?)//' -e 's/(.*\.list):/\[\1\] /' -e 's/deb http:\/\/ppa.launchpad.net\/(.*?)\/ubuntu .*/ppa:\1/'
我们将看到:
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily main restricted
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates main restricted
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily universe
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates universe
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily multiverse
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-updates multiverse
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-backports main restricted universe multiverse
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security main restricted
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security universe
deb http://ftp-stud.hs-esslingen.de/ubuntu/ wily-security multiverse
deb http://archive.canonical.com/ubuntu wily partner
[maarten-fonville-ubuntu-ppa-wily.list] ppa:maarten-fonville/ppa
[webupd8team-ubuntu-tor-browser-wily.list] ppa:webupd8team/tor-browser
[fossfreedom-ubuntu-indicator-sysmonitor-wily.list] ppa:fossfreedom/indicator-sysmonitor
[getdeb.list] deb http://archive.getdeb.net/ubuntu wily-getdeb apps
ppa:<user>/<project>
表格形式显示PPA 。
apt-cache policy
仅在运行后显示回购apt-get update
。如果您只是添加了一个add-apt-repository
apt-cache policy
apt-get update
sudo apt update > /dev/null 2>&1 && sudo apt-cache policy | grep http | awk '{print $2 $3}' | sort -u
效果很好。 gist.github.com/bmatthewshea/229da822f1f02157bff192a2e4a8ffd1
我使用此命令列出所有已配置的软件源(存储库),包括当前禁用的源:
cat /etc/apt/sources.list; for X in /etc/apt/sources.list.d/*; do echo; echo; echo "** $X:"; echo; cat $X; done
我主要将其用于故障排除。当然可以将其合并到脚本中,但是您可能希望缩小范围/etc/apt/sources.list.d/*
,/etc/apt/sources.list.d/*.list
以便仅获取当前启用的软件源。
https://repogen.simplylinux.ch/将为您提供适用于您的Ubuntu版本的所有PPA的列表。这是一个没有源文件且没有三星打印机ppa的生成列表:
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://us.archive.ubuntu.com/ubuntu/ yakkety main restricted universe multiverse
###### Ubuntu Update Repos
deb http://us.archive.ubuntu.com/ubuntu/ yakkety-security main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ yakkety-updates main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ yakkety-proposed main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ yakkety-backports main restricted universe multiverse
###### Ubuntu Partner Repo
deb http://archive.canonical.com/ubuntu yakkety partner
#------------------------------------------------------------------------------#
# UNOFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### 3rd Party Binary Repos
#### Flacon PPA - http://kde-apps.org/content/show.php?content=113388
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F2A61FE5
deb http://ppa.launchpad.net/flacon/ppa/ubuntu yakkety main
#### Gimp PPA - https://launchpad.net/~otto-kesselgulasch/+archive/gimp
## Run this command: sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 614C4B38
deb http://ppa.launchpad.net/otto-kesselgulasch/gimp/ubuntu yakkety main
#### Google Chrome Browser - http://www.google.com/linuxrepositories/
## Run this command: wget -q https://dl.google.com/linux/linux_signing_key.pub -O- | sudo apt-key add -
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
#### Google Earth - http://www.google.com/linuxrepositories/
## Run this command: wget -q https://dl.google.com/linux/linux_signing_key.pub -O- | sudo apt-key add -
deb [arch=amd64] http://dl.google.com/linux/earth/deb/ stable main
#### Highly Explosive PPA - https://launchpad.net/~dhor/+archive/myway
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93330B78
deb http://ppa.launchpad.net/dhor/myway/ubuntu yakkety main
#### JDownloader PPA - https://launchpad.net/~jd-team
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6A68F637
deb http://ppa.launchpad.net/jd-team/jdownloader/ubuntu yakkety main
#### Lazarus - http://www.lazarus.freepascal.org/
## Run this command: gpg --keyserver hkp://pgp.mit.edu:11371 --recv-keys 6A11800F && gpg --export --armor 0F7992B0 | sudo apt-key add -
deb http://www.hu.freepascal.org/lazarus/ lazarus-stable universe
#### LibreOffice PPA - http://www.documentfoundation.org/download/
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1378B444
deb http://ppa.launchpad.net/libreoffice/ppa/ubuntu yakkety main
#### MEGA Sync Client - https://mega.co.nz/
deb http://mega.nz/linux/MEGAsync/xUbuntu_16.10/ ./
#### MKVToolnix - http://www.bunkus.org/videotools/mkvtoolnix/
## Run this command: wget -q http://www.bunkus.org/gpg-pub-moritzbunkus.txt -O- | sudo apt-key add -
deb http://www.bunkus.org/ubuntu/yakkety/ ./
#### Mozilla Daily Build Team PPA - http://edge.launchpad.net/~ubuntu-mozilla-daily/+archive/ppa
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 247510BE
deb http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu yakkety main
#### muCommander - http://www.mucommander.com/
## Run this command: sudo wget -O - http://apt.mucommander.com/apt.key | sudo apt-key add -
deb http://apt.mucommander.com stable main non-free contrib
#### Opera - http://www.opera.com/
## Run this command: sudo wget -O - http://deb.opera.com/archive.key | sudo apt-key add -
deb http://deb.opera.com/opera/ stable non-free
#### Oracle Java (JDK) Installer PPA - http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
deb http://ppa.launchpad.net/webupd8team/java/ubuntu yakkety main
#### PlayDeb - http://www.playdeb.net/
## Run this command: wget -O- http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
deb http://archive.getdeb.net/ubuntu yakkety-getdeb games
#### SABnzbd PPA - http://sabnzbd.org/
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4BB9F05F
deb http://ppa.launchpad.net/jcfp/ppa/ubuntu yakkety main
#### SimpleScreenRecorder PPA - http://www.maartenbaert.be/simplescreenrecorder/
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 283EC8CD
deb http://ppa.launchpad.net/maarten-baert/simplescreenrecorder/ubuntu yakkety main
#### Steam for Linux - http://store.steampowered.com/about/
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F24AEA9FB05498B7
deb [arch=i386] http://repo.steampowered.com/steam/ precise steam
#### Syncthing - https://syncthing.net/
## Run this command: curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
deb http://apt.syncthing.net/ syncthing release
#### Tor: anonymity online - https://www.torproject.org
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 886DDD89
deb http://deb.torproject.org/torproject.org yakkety main
#### Unsettings PPA - http://www.florian-diesch.de/software/unsettings/
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0FEB6DD9
deb http://ppa.launchpad.net/diesch/testing/ubuntu yakkety main
#### VirtualBox - http://www.virtualbox.org
## Run this command: wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox_2016.asc -O- | sudo apt-key add -
deb http://download.virtualbox.org/virtualbox/debian yakkety contrib
#### Webmin - http://www.webmin.com
## Run this command: wget http://www.webmin.com/jcameron-key.asc -O- | sudo apt-key add -
deb http://download.webmin.com/download/repository sarge contrib
#### WebUpd8 PPA - http://www.webupd8.org/
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4C9D234C
deb http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu yakkety main
#### Xorg Edgers PPA - https://launchpad.net/~xorg-edgers
## Run this command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8844C542
deb http://ppa.launchpad.net/xorg-edgers/ppa/ubuntu yakkety main
here is a generated list without source files and no samsung printer ppa
#### Yuuguu - http://yuuguu.com
deb http://update.yuuguu.com/repositories/apt hardy multiverse
这是我的脚本“ list-apt-repositories
”,其中列出了“” /etc/sources.list"
和“ /etc/sources.list.d/*.list
” 中的所有存储库。您可以添加--ppa-only
以仅显示PPA,PPA会自动转换为ppa:USER/REPO
格式。
相关的部分是其中的5行list_sources
和list_ppa
功能,其余只是将其包装在方便的shell脚本中的样板。
list-apt-repositories
:#!/bin/sh
usage () {
cat >&2 <<USAGE
$0 [--ppa-only]
Options:
--ppa-only only list PPAs
USAGE
exit $1
}
list_sources () {
grep -E '^deb\s' /etc/apt/sources.list /etc/apt/sources.list.d/*.list |\
cut -f2- -d: |\
cut -f2 -d' ' |\
sed -re 's#http://ppa\.launchpad\.net/([^/]+)/([^/]+)(.*?)$#ppa:\1/\2#g'
}
list_ppa () {
list_sources | grep '^ppa:'
}
generate=list_sources
while test -n "$1"
do
case "$1" in
-h|--help) usage 1;;
--ppa-only) generate=list_ppa;;
*)
printf -- "Unknown argument '$1'\n" >&2
usage 2
;;
esac
shift
done
$generate
并制作一个安装脚本,管道到另一个脚本“ make-apt-repository-install-script
”。生成的脚本支持-y
/ --yes
参数用于非交互使用(请参阅参考资料add-apt-repository(1)
)。
make-apt-repository-install-script
:#!/bin/sh
if test -n "$1"
then
cat >&2 <<USAGE
Usage: $0 < PATH_TO_LIST_OF_REPOS
list-apt-repositories [--ppa-only] | $0
No options recognized.
Reads list of repositories from stdin and generates a script to install them
using \`add-apt-repository(1)\`. The script is printed to stdout.
The generated script supports an optional
\`-y\` or \`--yes\` argument which causes the \`add-apt-repository\` commands
to be run with the \`--yes\` flag.
USAGE
exit 1
fi
cat <<INSTALL_SCRIPT
#!/bin/sh
y=
case "\$1" in
-y|--yes) y=\$1;;
'') y=;;
*)
printf '%s\n' "Unknown option '\$1'" "Usage: \$0 [{-y|--yes}]" >&2
exit 1
;;
esac
INSTALL_SCRIPT
xargs -d'\n' printf "add-apt-repository \$y '%s'\n"
同样,重要的部分是xargs
最后一行的命令,其余部分是样板。
要添加它,请将ppa.launchpad.net行添加为ppa:$ USER / $ PPA。从* .list文件中以全行添加其他存储库。没有欺骗行。
#!/ bin / bash #我的〜/ bin / mk_repositories_restore_script mkdir -p〜/ bin x =〜/ bin / restore_repositories 回声\#\!/ bin / bash> $ x chmod u + x $ x ( 在$()中查找APT(找到/ etc / apt / -name \ *。list) 做sed -n -e'/ ^ deb / { /ppa\.launchpad/s/\(.*\/\/[^\/]*.\)\([^ \ t] * \)\(。* $ \)/ sudo apt-add-repository ppa :\ 2 / p; /ppa\.launchpad/!s / \(deb [\ t] * \)\(。* $ \)/ sudo apt-add-repository \ 2 / p; }'$ APT 完成 )| 排序| uniq | tee -a〜/ bin / restore_repositories
谢谢BobDodds!
如果有人感兴趣,我会稍微更新一下您的代码(希望您不介意)。
此脚本将只键入用户添加的PPA(/etc/apt/sources.list.d)。
#!/bin/bash
# My ~/bin/mk_repositories_restore_script
mkdir -p ~/bin
x=~/bin/restore_repositories
echo \#\!/bin/bash > $x
chmod u+x $x
(
for APT in $( find /etc/apt/ -name \*.list )
do sed -n -e '/^deb /{
/ppa\.launchpad/s/\(.*\/\/[^\/]*.\)\([^ \t]*\)\(.*\/ubuntu.*$\)/ppa:\2/p;
}' $APT
done
) | sort | uniq | tee -a ~/bin/restore_repositories
egrep -v '^#|^ *$' /etc/apt/sources.list /etc/apt/sources.list.d/*
去除注释掉线和空白行?