0

I'm automating my customary debian setup using ansible.

The playbook is supposed to treat testing/unstable and stable differently: the former are to be maintained "clean", while the latte is to receive kernel etc. from Backports.

As there's now stable-backports this requires that I retrieve the current stable name from an authoritative source and check it against the expected (currently "wheezy").

Can anyone think of a reliable/authoritative way to retrieve the current stable name in a one liner?

Sincerely, Joh

1

How about if you check from the official Debian FTP site? There the stable symbolic link points to actual version. So, for example, a shell script like this:

#!/bin/bash
PASSWD=''

ftp -n ftp.debian.org <<RESOLVE_PATH
quote USER anonymous
quote PASS $PASSWD
cd debian/dists/stable
pwd
quit
RESOLVE_PATH

And then run it like this:

./resolve_debian_stable_name.sh  | grep "Remote dir" | awk -F ':' '{ print $2; }'
 /debian/dists/wheezy

Or preferably make it a cleaner solution, this is just to give you an overall idea and a 30 second dirty hack. :)

  • Good strategy to follow. Thank you. Will report back with my "clean" solution. – balin Mar 20 '15 at 13:57
  • Or fetch and parse https://www.debian.org/releases/stable/ – Dan Mar 20 '15 at 17:52
0

Based on Janne's answer above I came up with the following:

#!/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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.