Create LATEST-X.[0N] links when running the first X-rc
[releases.git] / mkgitrel.rel
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 if test -f linux-libre-$rel.check; then
67     success=false
68     git worktree remove logs/v$rel
69     git worktree remove --force sources/v$rel
70     continue
71 fi &&
72
73 DATE=$(git cat-file -p incr/v$rel |
74        gawk '/^(author|tagger)/ {
75                print strftime(PROCINFO["strftime"], $(NF-1))
76              }') &&
77 export GIT_COMMITTER_DATE=$DATE GIT_AUTHOR_DATE=$DATE &&
78
79 plist="patch-$prev0-$rel" &&
80 if test "$prev0" != "$prevn"; then
81   plist="$plist patch-$prevn-$rel"
82 fi &&
83
84 list="linux-libre-$rel.tar $plist" &&
85
86 bzip2 -k9 $list &&
87 xz -k9 $list &&
88 lzip -k9s64MiB $list &&
89
90 mkdir -v $rel &&
91
92 for f in $(ls scripts/v$rel); do
93   if cmp scripts/v$rel/$f $reldir/$prevn/$f; then
94     gpg --verify $reldir/$prevn/$f.sign &&
95     ln -v $reldir/$prevn/$f $reldir/$prevn/$f.sign $rel/
96   else
97     ln -v scripts/v$rel/$f $rel/ &&
98     gpg --armor --detach-sign $rel/$f &&
99     mv -v $rel/$f.asc $rel/$f.sign
100   fi
101 done &&
102
103 ln -v logs/v$rel/linux-libre-$rel.* $rel/ &&
104
105 for f in $plist; do
106   gpg --armor --detach-sign $f &&
107   mv -v $f.asc $rel/$f.sign
108 done &&
109
110 for ext in .bz2 .xz .lz; do
111   for f in $list; do
112     mv -v $f$ext $rel/ &&
113     gpg --armor --detach-sign $rel/$f$ext &&
114     mv -v $rel/$f$ext.asc $rel/$f$ext.sign
115   done
116 done &&
117
118 rm -vf $list &&
119
120 mv -v $rel $reldir/$rel &&
121 ln -snfv $rel $reldir/LATEST-$cbr.N &&
122 if test "$rup" = "$cbr"; then
123   ln -nfv $reldir/LATEST-$cbr.N $reldir/LATEST-$cbr.0 &&
124   ln -nfv $reldir/LATEST-$cbr.N $reldir/LATEST-${cbr%.*}.N
125 elif test -n "$prevbase" && test ! -h $reldir/LATEST-$cbr.0; then
126   ln -nfv $reldir/LATEST-$prevbase.N $reldir/LATEST-$cbr.0
127 fi &&
128
129 git worktree remove logs/v$rel &&
130 git worktree remove scripts/v$rel
131
132 done &&
133
134 $success