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

balin
  • 123
  • 1
  • 5

2 Answers2

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. :)

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
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
balin
  • 123
  • 1
  • 5