mkgitrel.pub: catch .check file created while waiting for .patck removal
[releases.git] / mkgitrel.pub
1 #! /bin/bash
2
3 # Copyright 2021 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 reldir=$HOME/linux-libre/releases
25
26 key=474402C8C582DAFBE389C427BCB7CF877E7D47A7
27
28 success=:
29 for rel
30 do
31     
32 rup=$(echo "$rel" | sed 's,-gnu[0-9]*$,,')
33 cbr=$(echo "$rup" | sed 's,\(\.\|-rc\)[0-9]*$,,')
34
35 if test -d $reldir/$rel; then
36   echo $reldir/$rel exists >&2
37   continue
38 fi
39
40 if test -h $reldir/LATEST-$cbr.0; then
41   prev0=$(readlink $reldir/LATEST-$cbr.0)
42   prevn=$(readlink $reldir/LATEST-$cbr.N)
43 elif test -h $reldir/LATEST-$rup.N; then
44   cbr=$rup
45   prev0=$(readlink $reldir/LATEST-$cbr.0)
46   prevn=$(readlink $reldir/LATEST-$cbr.N)
47 else
48   echo Neither $reldir/LATEST-$cbr.0 nor $reldir/LATEST-$rup.N exist >&2
49   exit 1
50 fi
51
52 DATE=$(git cat-file -p incr/v$rel |
53        gawk '/^(author|tagger)/ {
54                print strftime(PROCINFO["strftime"], $(NF-1))
55              }') &&
56 export GIT_COMMITTER_DATE=$DATE GIT_AUTHOR_DATE=$DATE &&
57
58 if test -f linux-libre-$rel.check; then
59     echo linux-libre-$rel.check exists, abandoning this release
60     git tag -d incr/v$rel logs/v$rel sources/v$rel |&
61       tee -a linux-libre-$rel.dtags
62     continue
63 fi &&
64
65 while test -f linux-libre-$rel.patck && test ! -f linux-libre-$rel.check; do
66   echo please verify linux-libre-$rel.patck and move it away to complete the release
67   sleep 30
68 done &&
69
70 # Look for .check again, maybe it was created manually while we waited
71 # for .patck to be removed.  In this case, we have to duplicate the
72 # cleanups that .rel would have already done.
73 if test -f linux-libre-$rel.check; then
74     echo linux-libre-$rel.check exists, abandoning this release
75     git tag -d incr/v$rel logs/v$rel sources/v$rel |&
76       tee -a linux-libre-$rel.dtags
77     git worktree remove logs/v$rel
78     git worktree remove --force sources/v$rel
79     continue
80 fi &&
81
82 (
83   cd scripts/v$rel &&
84   { { git reset --soft -q scripts/$cbr &&
85       otop=$(git rev-parse --verify -q HEAD); } ||
86     echo $rel | grep -q -e -rc; } &&
87   { git commit -a -S$key -m "GNU Linux-libre $rel scripts" ||
88     if git status -su | grep .; then
89       success=false
90       continue
91     fi; } &&
92   case $rup:$(git rev-parse --verify -q HEAD) in
93   *-rc*:* | "$cbr":*) forcetag=: ;;
94   *:"$otop") forcetag=false ;;
95   *) forcetag=: ;;
96   esac &&
97   if $forcetag; then
98     git tag -m "GNU Linux-libre $rel scripts" -s -u $key \
99         -f \
100       scripts/v$rel &&
101     git checkout scripts/$cbr &&
102     git reset --hard scripts/v$rel &&
103     git checkout HEAD
104   fi
105 ) &&
106
107 for x in scripts sources logs; do
108   if git rev-parse --verify -q $x/v$rel > /dev/null ; then
109     git tag public/$x/v$rel $x/v$rel &&
110     git tag -d $x/v$rel
111   fi
112 done &&
113
114 git worktree remove --force sources/v$rel
115
116 done &&
117
118 $success