Last active
December 20, 2015 10:30
-
-
Save ms-tg/6115447 to your computer and use it in GitHub Desktop.
Test our package naming proposal for debian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# A script to test our debian package naming policy. | |
# | |
# This script uses `dpkg --compare-versions` to test that provided | |
# sequences of package names are considered to be in ascending order | |
# by Debian's tools. | |
# | |
# Author: Marc Siegel <marc.siegel@timgroup.com> | |
# Modified: 2013-07-30 | |
## | |
## | |
# Config: arrays of versions to test | |
## | |
declare -a SEQ1=( | |
play-2.0.4 | |
play-2.0.5~~YD1 | |
play-2.0.5~~YD2 | |
play-2.0.5~~YD3 | |
play-2.0.5~RC1 | |
play-2.0.5~RC2~YD1 | |
play-2.0.5~RC2 | |
play-2.0.5 | |
) | |
declare -a SEQ2=( | |
play-2.0.5~~YD3-youdevise1 | |
play-2.0.5~~YD3-youdevise2 | |
play-2.0.5~~YD3-youdevise3 | |
play-2.0.5~RC1-youdevise1 | |
play-2.0.5~RC1-youdevise2 | |
play-2.0.5~RC2~YD1-youdevise2 | |
play-2.0.5~RC2-youdevise1 | |
) | |
# All sequences to test | |
declare -a SEQS=(SEQ1[@] SEQ2[@]) | |
## | |
# Test if all versions in the sequences are ascending | |
## | |
# Return 0 if all were ascending | |
ret=0 | |
# Function to test that a sequence is ascending | |
test_seq () | |
{ | |
declare -a sequence=("${!1}") # extract first arg as an array | |
echo "Testing whether the following versions form an ascending sequence for dpkg:" | |
for n in "${sequence[@]}"; do | |
echo " $n" | |
done | |
echo | |
let "countMinusOne=${#sequence[@]} - 1" | |
index=0 | |
while [ "$index" -lt "$countMinusOne" ]; do | |
x=${sequence[$index]} | |
y=${sequence[$index + 1]} | |
a=$(echo $x | sed 's/\(^[[:alpha:]\-]*\)//g') # strip name ('play-') prefix | |
b=$(echo $y | sed 's/\(^[[:alpha:]\-]*\)//g') # strip name ('play-') prefix | |
test_pair $a $b | |
let "index = $index + 1" | |
done | |
echo -e "\n" | |
} | |
# Function to test that a given pair is ascending | |
test_pair () | |
{ | |
a="$1" | |
b="$2" | |
dpkg --compare-versions "$b" gt "$a" | |
r=$? | |
if [ $r -ne 0 ]; then msg="no"; else msg="yes"; fi | |
echo "$b $a $msg" | awk '{ printf "Is %-24s > %-25s? %-3s\n", $1, $2, $3 }' | |
if [ $r -ne 0 ]; then ret=1; fi | |
} | |
# Test all sequences | |
for s in "${SEQS[@]}"; do | |
test_seq $s | |
done | |
# Results | |
if [ $ret -ne 0 ]; then | |
echo "Fail: not all ascending according to dpkg." | |
else | |
echo "Success: all ascending according to dpkg." | |
fi | |
exit $ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bash test-dpkg-version-naming.bash | |
Testing whether the following versions form an ascending sequence for dpkg: | |
play-2.0.4 | |
play-2.0.5~~YD1 | |
play-2.0.5~~YD2 | |
play-2.0.5~~YD3 | |
play-2.0.5~RC1 | |
play-2.0.5~RC2~YD1 | |
play-2.0.5~RC2 | |
play-2.0.5 | |
Is 2.0.5~~YD1 > 2.0.4 ? yes | |
Is 2.0.5~~YD2 > 2.0.5~~YD1 ? yes | |
Is 2.0.5~~YD3 > 2.0.5~~YD2 ? yes | |
Is 2.0.5~RC1 > 2.0.5~~YD3 ? yes | |
Is 2.0.5~RC2~YD1 > 2.0.5~RC1 ? yes | |
Is 2.0.5~RC2 > 2.0.5~RC2~YD1 ? yes | |
Is 2.0.5 > 2.0.5~RC2 ? yes | |
Testing whether the following versions form an ascending sequence for dpkg: | |
play-2.0.5~~YD3-youdevise1 | |
play-2.0.5~~YD3-youdevise2 | |
play-2.0.5~~YD3-youdevise3 | |
play-2.0.5~RC1-youdevise1 | |
play-2.0.5~RC1-youdevise2 | |
play-2.0.5~RC2~YD1-youdevise2 | |
play-2.0.5~RC2-youdevise1 | |
Is 2.0.5~~YD3-youdevise2 > 2.0.5~~YD3-youdevise1 ? yes | |
Is 2.0.5~~YD3-youdevise3 > 2.0.5~~YD3-youdevise2 ? yes | |
Is 2.0.5~RC1-youdevise1 > 2.0.5~~YD3-youdevise3 ? yes | |
Is 2.0.5~RC1-youdevise2 > 2.0.5~RC1-youdevise1 ? yes | |
Is 2.0.5~RC2~YD1-youdevise2 > 2.0.5~RC1-youdevise2 ? yes | |
Is 2.0.5~RC2-youdevise1 > 2.0.5~RC2~YD1-youdevise2 ? yes | |
Success: all ascending according to dpkg. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment