-
Notifications
You must be signed in to change notification settings - Fork 6
/
version.sh
executable file
·80 lines (73 loc) · 1.61 KB
/
version.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
#!/bin/bash
major() {
if IFS=. read -r major rest <version.txt || [ -n "$major" ]; then
echo "$((major + 1)).0.0" >"version.txt"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
minor() {
if IFS=. read -r major minor patch <version.txt || [ -n "$major" ]; then
echo "$major.$((minor + 1)).0" >"version.txt"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
patch() {
if IFS=. read -r major minor patch <version.txt || [ -n "$major" ]; then
echo "$major.$minor.$((patch + 1))" >"version.txt"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
print_major() {
if IFS=. read -r major minor patch <version.txt || [ -n "$major" ]; then
echo "$major"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
print_major_minor() {
if IFS=. read -r major minor patch <version.txt || [ -n "$major" ]; then
echo "$major.$minor"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
print_major_minor_patch() {
if IFS=. read -r major minor patch <version.txt || [ -n "$major" ]; then
echo "$major.$minor.$patch"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
case "$1" in
major)
major $2
;;
minor)
minor $2
;;
patch)
patch $2
;;
print_major)
print_major $2
;;
print_major_minor)
print_major_minor $2
;;
print_major_minor_patch)
print_major_minor_patch $2
;;
*)
echo "Usage: bash version.sh {major|minor|patch|print_major_minor_patch}"
exit 1
esac
exit 0