xref: /freebsd/contrib/ntp/scripts/build/UpdatePoint (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1#! /bin/sh
2
3# showusage is set to 1 on any command-line syntax error
4showusage=0
5# are we playing by stable or dev rules?
6repo=
7# test is set to 1 if -t/--test is given to prevent modifications
8test=0
9
10case "$#" in
11 1) repo=$1
12    ;;
13 2) repo=$2
14    case $1 in
15     -t|--test)
16	test=1
17	;;
18     *)
19	showusage=1
20	;;
21    esac
22    ;;
23 *) showusage=1
24    ;;
25esac
26
27case "$repo" in
28 dev|stable)
29    ;;
30 '')
31    showusage=1
32    ;;
33 *) echo "Unexpected repo type: <$repo>!"
34    showusage=1
35    ;;
36esac
37
38case "$showusage" in
39 1) echo "Usage: $0 [-t] <stable|dev>"
40    echo "No changes are made to packageinfo.sh if -t is given."
41    exit 1
42    ;;
43esac
44
45
46set -e
47
48. ./packageinfo.sh
49
50case "$repotype" in
51 $repo)
52    ;;
53 *) echo "You indicated repo type <$repo> but packageinfo.sh"
54    echo "indicates <$repotype>."
55    exit 1
56    ;;
57esac
58
59ver_repo_mismatch=1
60
61case "$minor" in
62 1|3|5|7|9)
63    case "$repo" in
64     dev)
65	ver_repo_mismatch=0
66	;;
67     stable)
68	;;
69    esac
70    ;;
71 0|2|4|6|8)
72    case "$repo" in
73     dev)
74	;;
75     stable)
76	ver_repo_mismatch=0
77	;;
78    esac
79    ;;
80esac
81
82case "$ver_repo_mismatch" in
83 1) echo "Minor version <$minor> mismatches repotype <$repo>."
84    exit 1
85    ;;
86esac
87
88# Do we want to bump the point?
89bp=1
90# Do we want to bump the beta point?
91bbp=0
92# Do we want to change the RC point? (n=no, z=empty rcpoint and zero
93# betapoint, i=incr)
94crcp=n
95# Do we want to change the prerelease value?
96setpr=0
97
98# for stable:
99# if we are not in a beta or RC state, enter beta unless point is NEW.
100# if we are in a beta state:
101# - bump the beta point
102# else if we are in an RC state:
103# - if rcpoint is GO:
104# - - set rcpoint= (empty)
105# - - set prerelease= (empty)
106# - - set betapoint=0
107# - else
108# - - if rcpoint==(empty)
109# - - - (bump-point) and set rcpoint to 0 (and fall thru, so -RC1 is first)
110# - - bump the RC point
111
112# for dev, we only want to bump-point and possibly clear prerelease,
113# but we do not modify rcpoint nor betapoint.
114
115case "$repo" in
116 dev)
117    case "$point" in
118     [Nn][Ee][Ww])
119	crcp=z
120	;;
121     *)
122	# crcp=n
123	;;
124    esac
125    # bp=1
126    ;;
127 stable)
128    case "$prerelease" in
129     '')
130	# echo "Checking <$betapoint::$rcpoint::$point>"
131	case "$betapoint::$rcpoint::$point" in
132	 *::*::NEW)
133	    # new minor release (no p)
134	    crcp=z
135	    # bp=1
136	    ;;
137	 0::::*)
138	    # start of first beta cycle for the next point release
139	    setpr=1
140	    newpr=beta
141	    # bp=1
142	    bbp=1
143	    ;;
144	 0::[Gg][Oo]::*)
145	    # skip all -beta and -RC prereleases to the next point.
146	    crcp=z
147	    setpr=1
148	    newpr=
149	    # bp=1
150	    # bbp=0
151	    ;;
152	 ::[Gg][Oo]::*)
153	    # echo "Good - betapoint is empty.  Look in $0 and figure out what's going on here."
154	    crcp=z
155	    ;;
156	 *::[Gg][Oo]::*)
157	    echo "betapoint is NOT empty.  Look in $0 and figure out what's going on here."
158	    test=1
159	    ;;
160	 *) echo "betapoint is <$betapoint>, rcpoint is <$rcpoint>"
161	    echo "betapoint must be 0 and rcpoint must be empty to start the"
162	    echo "beta cycle."
163	    exit 1
164	    ;;
165	esac
166	;;
167     beta)
168	case "$betapoint::$rcpoint" in
169	 [1-9]*::*)
170	    bp=0
171	    bbp=1
172	    ;;
173	 0::) echo "betapoint is 0, rcpoint emtpy, and prerelease is beta."
174	    echo "You probably intended prerelease=  (that is, empty).  It"
175	    echo "will then be changed to beta by this script, starting the"
176	    echo "first beta for the next point release."
177	    exit 1
178	    ;;
179	 *)
180	    bp=0
181	    bbp=1
182	    ;;
183	esac
184	case "$rcpoint" in
185	 [Gg][Oo])
186	    echo "prerelease is beta, rcpoint is GO, disallowed."
187	    echo "rcpoint GO is allowed only when prerelease is RC or empty."
188	    exit 1
189	    ;;
190	esac
191	;;
192     rc|RC)
193	case "$rcpoint" in
194	 '')
195	    case "$betapoint" in
196	     0) # bp=1
197		;;
198	     *) bp=0
199		;;
200	    esac
201	    crcp=i
202	    ;;
203	 [1-9]*)
204	    bp=0
205	    crcp=i
206	    ;;
207	 [Gg][Oo])
208	    bp=0
209	    crcp=z
210	    setpr=1
211	    newpr=
212	    ;;
213	 *) echo "Unexpected value for 'rcpoint' <$rcpoint>!"
214	    exit 1
215	    ;;
216	esac
217	;;
218     *)
219	echo "prerelease <$prerelease> unexpected"
220	exit 1
221	;;
222    esac
223    ;;
224 *) echo "impossible: repo <$repo>!"
225    exit 1
226    ;;
227esac
228
229case "$repo::$bp::$point" in
230 *::0::*)
231    newpoint=$point
232    ;;
233 dev::1::0)
234    newpoint=`expr $point + 1`
235    ;;
236 *::1::[1-9]*)
237    newpoint=`expr $point + 1`
238    ;;
239 dev::1::)
240    newpoint=0
241    ;;
242 stable::1::)
243    newpoint=1
244    ;;
245 *::1::[Nn][Ee][Ww])
246    newpoint=
247    ;;
248 *) echo "Unexpected value for 'point' <$point>! (repo::bp::point is $repo::$bp::$point)"
249    exit 1
250    ;;
251esac
252
253case "$bbp::$betapoint" in
254 0::*)
255    newbetapoint=$betapoint
256    ;;
257 1::[0-9]*)
258    newbetapoint=`expr $betapoint + 1`
259    ;;
260 *) echo "Unexpected value for 'betapoint' <$betapoint>!"
261    exit 1
262    ;;
263esac
264
265case "$crcp::$rcpoint" in
266 n::*)
267    newrcpoint=$rcpoint
268    ;;
269 i::)
270    newrcpoint=1
271    ;;
272 i::[0-9]*)
273    newrcpoint=`expr $rcpoint + 1`
274    ;;
275 z::*)
276    newrcpoint=
277    case "$repo" in
278     dev)
279	newbetapoint=0
280	;;
281     stable)
282	newbetapoint=
283	;;
284     *)
285	echo "crcp::rcpoint - bogus repo <$repo>"
286	exit 1
287	;;
288    esac
289    ;;
290 *) echo "Unexpected value for 'crcp::rcpoint' <$crcp::$rcpoint>!"
291    exit 1
292    ;;
293esac
294
295case "$setpr" in
296 0)
297    newpr=$prerelease
298esac
299
300# display results
301printf "prerelease		$prerelease"
302case "$newpr" in
303 $prerelease)
304    printf "\n"
305    ;;
306 *) printf " -> $newpr\n"
307    ;;
308esac
309printf "point			$point"
310case "$newpoint" in
311 $point)
312    printf "\n"
313    ;;
314 *) printf " -> $newpoint\n"
315    ;;
316esac
317printf "betapoint		$betapoint"
318case "$newbetapoint" in
319 $betapoint)
320    printf "\n"
321    ;;
322 *) printf " -> $newbetapoint\n"
323    ;;
324esac
325printf "rcpoint			$rcpoint"
326case "$newrcpoint" in
327 $rcpoint)
328    printf "\n"
329    ;;
330 *) printf " -> $newrcpoint\n"
331    ;;
332esac
333
334printf "Previous version: "
335scripts/build/VersionName
336
337# apply packageinfo.sh changes
338
339sed -e "s/^point=.*/point=$newpoint/"			\
340    -e "s/^betapoint=.*/betapoint=$newbetapoint/"	\
341    -e "s/^rcpoint=.*/rcpoint=$newrcpoint/"		\
342    -e "s/^prerelease=.*/prerelease=$newpr/"		\
343	< packageinfo.sh					\
344	> packageinfo.sh+
345
346case "$test" in
347 0)
348    mv packageinfo.sh+ packageinfo.sh
349    printf "Updated version: "
350    scripts/build/VersionName
351    ;;
352 *)
353    printf "Next version would be: "
354    scripts/build/VersionName -p ./packageinfo.sh+
355    rm packageinfo.sh+
356    ;;
357esac
358