1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#!/bin/sh
# vi: ts=4 noexpandtab
Usage() {
cat <<EOF
Usage: ${0##*/} adjective
Output the version string for a given ubuntu adjective
Only pays attention to the first letter of the string, and as
such will fail to function after 'zippy zebra'
Example:
- $ ${0##*/} hardy
8.04
- $ ${0##*/} PRETTY
12.04
- $ ${0##*/} yearning
16.10
EOF
}
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
ubuntu_adj2ver() {
# over engineered function, convert ubuntu adjective to version
# based on its first letter.
local letter1="" list=defghijklmnopqrstuvwxyz
local baseyear=6 year="" month="04" tmp="" relnum=""
[ "$1" = "warty" -o "$1" = "Warty" -o "$1" = "WARTY" ] &&
{ _RET="5.10"; return 0; }
letter1=$(echo "${1}" | sed 's,\(.\).*,\1,') || return 1
case "${letter1}" in
[A-Z]) letter1=$(echo "${letter1}" | tr "[:upper:]" "[:lower:]");;
[a-z]) :;;
*) return 1;
esac
tmp=${list%${letter1}*}
[ "${tmp}" != "${list}" ] || return 1;
relnum=${#tmp} # number of release starting with 6.04
year=$((${relnum}/2 + ${baseyear}))
# if this is an even numbered release, then its in the 10th month
# odd numbered are in the 4th.
[ $((${relnum} % 2)) -eq 0 ] || month="10"
_RET="${year}.${month}"
}
[ $# -eq 1 ] || { Usage 1>&2; fail "must give single adjective"; }
[ "$1" = "--help" -o "$1" = "-h" ] && { Usage; exit; }
ubuntu_adj2ver "$1" && echo ${_RET}
|