Create LATEST-X.[0N] links when running the first X-rc
[releases.git] / mkgitrel.cln
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   case $rup in
49   *-rc*)
50     prevbase=$(echo "$cbr" | sed 's,\.[0-9]*$,,')
51     if test -h $reldir/LATEST-$prevbase.N; then
52       prev0=$(readlink $reldir/LATEST-$prevbase.N)
53       prevn=$prev0
54     else
55       echo $reldir/LATEST-$prevbase.N does not exit >&2
56       exit 1
57     fi
58     ;;
59   *)
60     echo Neither $reldir/LATEST-$cbr.0 nor $reldir/LATEST-$rup.N exist >&2
61     exit 1
62     ;;
63   esac
64 fi
65
66 for up in linus stable; do
67   git rev-parse --verify -q $up/v$rup && break
68 done
69
70 git verify-tag $up/v$rup &&
71
72 { test -d scripts/v$rel ||
73   git worktree add --detach scripts/v$rel scripts/$cbr
74 } &&
75
76 case $(sed -n 's,^kver=\(.*\) extra=\(.*\),\1-gnu\2,p' \
77            scripts/v$rel/deblob-$cbr) in
78 "$cbr$(echo $rel | sed -n 's,.*\(-gnu\),\1,p')") ;;
79 *) echo $rel mismatches release implied by scripts/v$rel/deblob-$cbr >&2
80    echo "$cbr$(echo $rel | sed -n 's,.*\(-gnu\),\1,p')" vs \
81         $(sed -n 's,^kver=\(.*\) extra=\(.*\),\1-gnu\2,p' \
82            scripts/v$rel/deblob-$cbr) >&2
83    continue;;
84 esac &&
85
86 git worktree add --detach sources/v$rel $up/v$rup &&
87
88 git worktree add --detach logs/v$rel public/logs/v$prevn &&
89
90 (cd logs/v$rel && git rm -f linux-*) &&
91
92 (
93   cd sources/v$rel &&
94   ../../scripts/v$rel/deblob-$cbr >& ../../logs/v$rel/linux-libre-$rel.log &&
95   git commit -m "GNU Linux-libre v$rel incremental" -a &&
96   git tag incr/v$rel
97 ) &&
98
99 DATE=$(git cat-file -p incr/v$rel |
100        gawk '/^(author|tagger)/ {
101                print strftime(PROCINFO["strftime"], $(NF-1))
102              }') &&
103 export GIT_COMMITTER_DATE=$DATE GIT_AUTHOR_DATE=$DATE &&
104
105 (
106   cd sources/v$rel &&
107   git reset --soft -q public/sources/v$prevn &&
108   git commit --amend --reset-author -S$key \
109       -m "GNU Linux-libre $rel" &&
110   git tag -m "GNU Linux-libre $rel" -s -u $key sources/v$rel &&
111
112   git reset --hard incr/v$rel^ &&
113   { git merge --no-commit incr/v$prevn || :; } &&
114   git diff incr/v$rel > ../../linux-libre-$rel.patckT &&
115   mv -v ../../linux-libre-$rel.patckT ../../linux-libre-$rel.patck
116  ) &&
117
118 git archive --format tar --prefix=linux-$rup/ -o linux-libre-$rel.tar sources/v$rel &&
119 gpg --armor --detach-sign linux-libre-$rel.tar &&
120 mv linux-libre-$rel.tar.asc logs/v$rel/linux-libre-$rel.tar.sign &&
121
122 for f in linux-libre-; do
123   if cmp logs/v$rel/$f$rel.log $reldir/$prevn/$f$prevn.log; then
124     ln -vf $reldir/$prevn/$f$prevn.log logs/v$rel/$f$rel.log &&
125     ln -vf $reldir/$prevn/$f$prevn.log.sign logs/v$rel/$f$rel.log.sign
126   else
127     gpg --armor --detach-sign logs/v$rel/$f$rel.log &&
128     mv -v logs/v$rel/$f$rel.log.asc logs/v$rel/$f$rel.log.sign
129   fi
130 done &&
131
132 (
133   cd logs/v$rel &&
134   git add linux* &&
135   git commit --amend --reset-author -S$key -m "GNU Linux-libre $rel logs" &&
136   git tag -m "GNU Linux-libre $rel logs" -s -u $key logs/v$rel
137 ) &&
138
139 git diff --src-prefix=linux-libre-$prev0/ --dst-prefix=linux-libre-$rel/ \
140   public/sources/v$prev0 sources/v$rel -- > patch-$prev0-$rel &&
141
142 if test "$prev0" != "$prevn"; then
143   git diff --src-prefix=linux-libre-$prevn/ --dst-prefix=linux-libre-$rel/ \
144     public/sources/v$prevn sources/v$rel -- > patch-$prevn-$rel
145 fi &&
146
147 { scripts/v$rel/deblob-check --use-awk linux-libre-$rel.tar ||
148     scripts/v$rel/deblob-check --use-awk -C linux-libre-$rel.tar \
149       > linux-libre-$rel.check ||
150     { success=false; continue; }; }
151
152 done &&
153
154 $success