我正在使用 ansible 自动化我习惯的 debian 设置。
该剧本应该以不同的方式对待测试/不稳定和稳定:前者要保持“干净”,而后者要从 Backports 接收内核等。
由于现在有稳定的反向移植,这要求我从权威来源检索当前稳定名称并根据预期进行检查(当前为“wheezy”)。
有人能想到一个可靠/权威的方法来在一行中检索当前稳定的名称吗?
真诚的,约翰
答案1
如果你从官方 Debian FTP 站点检查一下会怎么样?那里的stable
符号链接指向实际版本。例如,像这样的 shell 脚本:
#!/bin/bash
PASSWD=''
ftp -n ftp.debian.org <<RESOLVE_PATH
quote USER anonymous
quote PASS $PASSWD
cd debian/dists/stable
pwd
quit
RESOLVE_PATH
然后像这样运行它:
./resolve_debian_stable_name.sh | grep "Remote dir" | awk -F ':' '{ print $2; }'
/debian/dists/wheezy
或者最好使其成为一个更清洁的解决方案,这只是为您提供一个总体想法和 30 秒的肮脏黑客。:)
答案2
根据 Janne 的上述回答,我得出以下结论:
#!/bin/bash
#lower case the first input parameter
lcParam=${1,,}
# Check prerequisites
## Check the 1st input parameter against a list of dealt with
## meta-distributions
declare -A legaloptions=( [stable]=stable [testing]=testing [unstable]=sid )
[[ -z "${legaloptions[$lcParam]}" ]] && \
echo "'$lcParam' is not a supported meta-distribution ( ${!legaloptions[*]} )." && \
exit 1
# 'Unstable' remains 'sid'
if [[ ${lcParam} == "unstable" ]]; then
echo "sid"
exit 0
fi
# Retrieve explicit distribution name from a ftp connection to debian.org
## Store output here:
FTPLOGFILE="/tmp/ftp_distriution_name.log"
## Use an empty password
PASSWD=''
## Connect
## Authenticate (USER & PASS)
## Decend into the directory the meta-distribution requested points to
## Retrieve the directory name (including the explicit distribution name)
## End the session
ftp -n ftp.debian.org <<RESOLVE_PATH >> ${FTPLOGFILE} 2>&1
quote USER anonymous
quote PASS $PASSWD
cd debian/dists/$lcParam
pwd
quit
RESOLVE_PATH
# Reformat output
distributionName=$(cat ${FTPLOGFILE} | sed 's/"//g')
# Delete logfile
rm ${FTPLOGFILE}
# Return
basename `echo $distributionName | awk '{print $2}'`
exit 0