我经常使用终端将 PPA 添加到我的资源列表中,后来才发现 PPA 不支持我的 Ubuntu 版本。唉,因此我遇到了一个错误:
404 Not Found
Run Code Online (Sandbox Code Playgroud)
如何通过终端检查要添加的 ppa 是否支持我的 Ubuntu 版本?
更新:
该脚本现在检查 ppa 是否支持您的发行版,然后如果您想将 repo 添加到您的源列表,然后才安装软件包,请确认。
使用它需要您自担风险!我只在两个 ppa 上测试过这个!包裹破损本人概不负责!
#!/bin/bash
#-----------------------------------------------
# Author : Imri Paloja
# Email : ****.******@*****.***
# HomePage : www.eurobytes.nl
# Version : 3.0
# Name : add-ppa
#-----------------------------------------------
# CHANGELOG
#
# 1. Asks for confirmation if ppa supports distro.
mkdir /tmp/add-ppa/
wget --quiet "http://ppa.launchpad.net/$(echo $1 | sed -e 's/ppa://g')/ubuntu/dists" -O /tmp/add-ppa/support.html
grep "$(lsb_release -sc)" "/tmp/add-ppa/support.html" >> /tmp/add-ppa/found.txt
cat /tmp/add-ppa/found.txt | sed 's|</b>|-|g' | sed 's|<[^>]*>||g' >> /tmp/add-ppa/stripped_file.txt
if [[ -s /tmp/add-ppa/stripped_file.txt ]] ; then
echo "$(lsb_release -sc) is supported"
read -p "Do you wish to install add the ppa to your source, and install the binaries [y/n] ?"
if [ "$REPLY" == "y" ] ; then
echo "Adding it to your sources list"
sudo add-apt-repository $1
echo "Refreshing your sources list"
sudo apt-get update
# Searching for the needed files, and installing them
wget --quiet "http://ppa.launchpad.net/$(echo $1 | sed -e 's/ppa://g')/ubuntu/dists/$(lsb_release -sc)/main/binary-amd64/Packages" -O /tmp/add-ppa/packages.html
grep "Package:" "/tmp/add-ppa/packages.html" >> /tmp/add-ppa/packages.txt
cat /tmp/add-ppa/packages.txt | sed ':a;N;$!ba;s/\n/ /g' >> /tmp/add-ppa/packages_stripped_file.txt
cat /tmp/add-ppa/packages_stripped_file.txt | sed 's|Package:||g' >> /tmp/add-ppa/packages_stripped_file2.txt
sudo apt-get install $(grep -vE "^\s*#" /tmp/add-ppa/packages_stripped_file2.txt | tr "\n" " ")
else
exit 0
fi
else
echo "$(lsb_release -sc) is not supported"
fi;
#Cleanup
rm -r /tmp/add-ppa/
Run Code Online (Sandbox Code Playgroud)
不支持ppa
./support.sh ppa:m-gehre/ppa
saucy is not supported
Run Code Online (Sandbox Code Playgroud)
支持ppa
./support.sh ppa:banshee-team/ppa
saucy is supported
Do you wish to add the ppa to your sources list, and install the binaries [y/n] ??
Adding it to your sources list
...
Refreshing your sources list
...
sudo apt-get install
....
Run Code Online (Sandbox Code Playgroud)
查看正在运行的脚本:
改进了它。威尔夫的原始答案
我刚刚为你学了一些 bash哈哈。这很好用,我很自豪(感谢 Wilf 的回答)
#!/bin/bash
# usage : bash myscript ppa:something/something
# get list of ppa's supported distribution
wget http://ppa.launchpad.net/$(echo $1 | sed -e 's/ppa://g')/ubuntu/dists -O /tmp/test-ppa.tmp -q
# check if your release is in the downloaded list
RELEASE=`cat /tmp/test-ppa.tmp | grep $(lsb_release -sc)`
if [[ -n "$RELEASE" ]] ; then
echo "$1 will work with $(lsb_release -si) $(lsb_release -sr) $(lsb_release -sc)"
else
echo "$1 won't work with $(lsb_release -si) $(lsb_release -sr) $(lsb_release -sc)"
fi
# cleaning
rm /tmp/test-ppa.tmp
Run Code Online (Sandbox Code Playgroud)
1) 将其复制到某个文本文件中(在下面的示例中为~/myscript)
2)使用命令:
bash myscript ppa:something/something
Run Code Online (Sandbox Code Playgroud)
注意:您还可以将该脚本复制到/usr/bin/文件夹中
sudo cp ~/myscript /usr/bin/ppa-test && sudo chmod +x /usr/bin/ppa-test以直接在命令行中使用:
ppa-test ppa:something/something
(这里我使用了:ppa:libreoffice/ppa和~/myscript)

编辑:更新了blade19899的使用想法lsb_release
| 归档时间: |
|
| 查看次数: |
826 次 |
| 最近记录: |