我正在尝试下载一些软件包进行离线安装apt-get download,但由于某种原因,apt-rdepends包括不存在的软件包。这是我正在使用的命令:
apt-get download $(apt-rdepends libboost1.55-all-dev | grep -v "^ ")
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
E: Can't select candidate version from package libstdc++-dev as it has no candidate
E: Can't select candidate version from package debconf-2.0 as it has no candidate
E: Can't select candidate version from package libc-dev as it has no candidate
E: Can't select candidate version from package python-celementtree as it has no candidate
E: Can't select candidate version from package python-elementtree as it has no candidate
Run Code Online (Sandbox Code Playgroud)
但apt一直抱怨有套餐没有候选人。我想忽略这些错误并下载软件包及其依赖项。我似乎找不到一个可以让我忽略apt-get错误的标志。我该怎么做呢?
由于apt-rdepends没有提供忽略包的方法,因此需要包装器来从下载列表中删除无法满足的包。一种相对可移植的自动化方法是使用下面的 BASH 脚本,而无需首先安装 Perl/Python 等解释器。
getdepends.sh:
#!/bin/bash
export MAXPARAMETERS=255
function array_contains_find_index() {
local n=$#
local i=0
local value=${!n}
for (( i=1; i < n; i++ )) {
if [ "${!i}" == "${value}" ]; then
echo "REMOVING $i: ${!i} = ${value}"
return $i
fi
}
return $MAXPARAMETERS
}
LIST=( $( apt-rdepends $1 | grep -v "^ " ) )
echo ${LIST[*]}
read -n1 -r -p "... Packages that will be downloaded (Continue or CTRL+C) ..."
RESULTS=( $( apt-get download ${LIST[*]} |& cut -d' ' -f 8 ) )
LISTLEN=${#LIST[@]}
while [ ${#RESULTS[@]} -gt 0 ]; do
for (( i=0; i < $LISTLEN; i++ )); do
array_contains_find_index ${RESULTS[@]} ${LIST[$i]}
ret=$?
if (( $ret != $MAXPARAMETERS )); then
unset LIST[$i]
fi
done
FULLRESULTS=$( apt-get download ${LIST[*]} 2>&1 )
RESULTS=( $( echo $FULLRESULTS |& cut -d' ' -f 11 | sed -r "s/'(.*?):(.*$)/\1/g" ) )
done
apt-get download ${LIST[*]}
Run Code Online (Sandbox Code Playgroud)
运行脚本:
./getdepends.sh [package name]
Run Code Online (Sandbox Code Playgroud)
我编写的具有更多日志记录功能的注释版本可在此处的 Pastebin 上找到:
| 归档时间: |
|
| 查看次数: |
9768 次 |
| 最近记录: |