mkgitrel.pre: new, early prechecking pass to catch various mistakes
[releases.git] / mkgitrel.pre
1 #! /bin/bash
2
3 # pre-check to stop early in case of typos and other mistakes
4 #
5 # Copyright 2021-2023 Alexandre Oliva <lxoliva@fsfla.org>
6 #
7 # This program is part of GNU Linux-libre, a GNU project that
8 # publishes scripts to clean up Linux so as to make it suitable for
9 # use in the GNU Project and in Free System Distributions.
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 # General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
24 # USA
25
26 scriptdir=$(dirname "$0")
27 . $scriptdir/mkgitrel.gcfg
28
29 success=:
30 for rel
31 do
32
33 . $scriptdir/mkgitrel.setprev &&
34
35   case $rel in
36   v*)
37     echo $rel starts with v, that is unexpected >&2
38     success=false
39     ;;
40   *.*-gnu*)
41     if test -d scripts/v$rel &&
42        git -C scripts/v$rel status | grep -q Untracked; then
43       echo scripts/v$rel exists and contains untracked files >&2
44       success=false
45     fi
46     ;;
47   *)
48     echo $rel does not end with -gnu, that is unexpected >&2
49     success=false
50     ;;
51   esac &&
52
53 if for up in linus stable; do
54      git rev-parse --verify -q $up/v$rup && break
55    done &&
56    git verify-tag $up/v$rup; then
57   :
58 else
59   echo could not find a $rup tag on which to base this release >&2
60   success=false
61   continue
62 fi &&
63
64 for d in sources/v$rel logs/v$rel; do
65   if test -d $d; then
66     echo directory $d already exists, it needs to be cleaned up first >&2
67     success=false
68   fi
69 done &&
70
71 for f in linux-libre-$rel.check linux-libre-$rel.patck; do
72   if test -f $f; then
73     echo warning: file $f already exists >&2
74   fi
75 done &&
76
77 { test -d scripts/v$rel ||
78   git worktree add --detach scripts/v$rel scripts/$cbr
79 } &&
80
81 case $(sed -n 's,^kver=\(.*\) extra=\(.*\),\1-gnu\2,p' \
82            scripts/v$rel/deblob-$cbr) in
83 "$cbr$(echo $rel | sed -n 's,.*\(-gnu\),\1,p')") ;;
84 *) echo $rel mismatches release implied by scripts/v$rel/deblob-$cbr >&2
85    echo "$cbr$(echo $rel | sed -n 's,.*\(-gnu\),\1,p')" vs \
86         $(sed -n 's,^kver=\(.*\) extra=\(.*\),\1-gnu\2,p' \
87            scripts/v$rel/deblob-$cbr) >&2
88    continue;;
89 esac &&
90
91 for f in scripts/v$rel/.* scripts/v$rel/*; do
92   case $f in
93   scripts/"v$rel"/. | \
94   scripts/"v$rel"/.. | \
95   scripts/"v$rel"/.gitx | \
96   scripts/"v$rel"/COPYING | \
97   scripts/"v$rel"/deblob-"$cbr" | \
98   scripts/"v$rel"/deblob-check) ;;
99   *) echo unexpected file $f exists >&2
100      success=false;;
101   esac
102 done &&
103
104 continue
105
106 success=false
107
108 done &&
109
110 $success