mkgitrel.cln: run single check pass and refuse --force releases
[releases.git] / mkgitrel.setprev
1 #! /bin/bash
2
3 # Copyright 2021-2022 Alexandre Oliva <lxoliva@fsfla.org>
4 #
5 # This program is part of GNU Linux-libre, a GNU project that
6 # publishes scripts to clean up Linux so as to make it suitable for
7 # use in the GNU Project and in Free System Distributions.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 # USA
23
24 if test -d $reldir/$rel; then
25   echo $reldir/$rel exists >&2
26   continue
27 fi
28
29 rup=$(echo "$rel" | sed 's,-gnu[0-9]*$,,')
30 cbr=$(echo "$rup" | sed 's,\(\.\|-rc\)[0-9]*$,,')
31
32 if test -h $reldir/LATEST-$cbr.0; then
33   prev0=$(readlink $reldir/LATEST-$cbr.0)
34   prevn=$(readlink $reldir/LATEST-$cbr.N)
35 elif test -h $reldir/LATEST-$rup.N; then
36   cbr=$rup
37   prev0=$(readlink $reldir/LATEST-$cbr.0)
38   prevn=$(readlink $reldir/LATEST-$cbr.N)
39 else
40   case $rup in
41   [3-9].0-rc* | [1-9][0-9].0-rc*)
42     prevbase=$(echo "$cbr" | sed 's,\.[0-9]*$,,')
43     if test -h $reldir/LATEST-$prevbase.N; then
44       prev0=$(readlink $reldir/LATEST-$prevbase.N)
45       prevn=$prev0
46     elif pbase=$(expr "$prevbase" - 1) && test -h $reldir/LATEST-$pbase.N; then
47       prevbase=$pbase
48       prev0=$(readlink $reldir/LATEST-$prevbase.N)
49       prevn=$prev0
50     else
51       echo neither $reldir/LATEST-$prevbase.N nor $reldir/LATEST-$pbase.N exist>&2
52       exit 1
53     fi
54     ;;
55   *-rc*)
56     prevbase=$(echo "$cbr" | sed 's,\.[0-9]*$,,')
57     if test -h $reldir/LATEST-$prevbase.N; then
58       prev0=$(readlink $reldir/LATEST-$prevbase.N)
59       prevn=$prev0
60     else
61       echo $reldir/LATEST-$prevbase.N does not exit >&2
62       exit 1
63     fi
64     ;;
65   *)
66     echo Neither $reldir/LATEST-$cbr.0 nor $reldir/LATEST-$rup.N exist >&2
67     exit 1
68     ;;
69   esac
70 fi