自动检索当前映射的debian stable – >发布名称

我使用ansible自动化我的习惯debian设置。

剧本应该是处理testing/不稳定和稳定不同:前者要保持“清洁”,而拿铁是从后台接收内核等。

由于现在有稳定backports这需要我从权威来源检索当前稳定的名称,并检查它与预期(目前“wheezy”)。

任何人都可以想到一个可靠/权威的方法来检索当前稳定的名字在一个class轮?

真诚的,约翰

如果你从官方的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秒的肮脏的黑客。 🙂

根据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