-
Notifications
You must be signed in to change notification settings - Fork 3
/
version_number.sh
89 lines (77 loc) · 2.04 KB
/
version_number.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
while getopts :hn: opt
do
case $opt in
h)
echo use no arguments for the versions in __init_.py and setup.py to be updated to the highest version between the two.
echo use \-n \<version.number\> to update both to the perscribed version number.
exit 0
;;
n)
perscribed_version=$OPTARG
echo version numbers will be updated to "$perscribed_version"
;;
\?)
echo "unrecognized flag used: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
read_version_number(){
awk -F "\"" '/version/ {print $2}' "$1"
}
conform_to_greater_vn(){
i=1
if [[ $1 == $2 ]]
then
versionsEqual=1
else
versionsEqual=0
fi
while [ $versionsEqual -lt 1 ]
do
first_dec=$(echo "$1" | cut -d "." -f $i)
second_dec=$(echo "$2" | cut -d "." -f $i)
# echo comparing "$first_dec" to "$second_dec"
if [[ $first_dec > $second_dec && $4 != "FAIL" ]]
then
sed -i "s/$2/$1/" $4
versionsEqual=1
elif [[ $first_dec < $second_dec && $3 != "FAIL" ]]
then
sed -i "s/$1/$2/" $3
versionsEqual=1
elif [[ $first_dec == $second_dec ]]
then
(( i++ ))
else # FAIL
echo FAILED: Perscribed version number is LESS THAN existing version number >&2
exit 1
fi
done
}
setup_file="setup.py"
init_file="hydrophobicity_explorer/__init__.py"
setup_version=$(read_version_number "$setup_file")
init_version=$(read_version_number "$init_file")
# echo "$setup_version"
# echo "$init_version"
# echo "$perscribed_version"
if [[ $perscribed_version != "" ]]
then
if [[ $perscribed_version == $setup_version || $perscribed_version == $init_version ]]
then
echo FAILED: Perscribed version number is EQUAL TO at least one existing version number >&2
exit 1
else
conform_to_greater_vn "$perscribed_version" "$init_version" "FAIL" "$init_file"
conform_to_greater_vn "$setup_version" "$perscribed_version" "$setup_file" "FAIL"
fi
else
conform_to_greater_vn "$setup_version" "$init_version" "$setup_file" "$init_file"
fi
echo version number in both files is $(read_version_number "$setup_file")