]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - debian/scripts/helpers/open
UBUNTU: [Packaging] update helper scripts
[mirror_ubuntu-focal-kernel.git] / debian / scripts / helpers / open
CommitLineData
c74bfc18
LO
1#!/bin/bash -eu
2export LC_ALL=C.UTF-8
3
4usage() {
5 cat << EOF
6Usage: ${P:-$(basename "$0")} [-h|--help] [-d|--dry-run] [-r|--reuse-abi]
7
8Create a "start new release" commit. The new commit will contain ABI
9changes and any customization required by backport kernels.
10
11Optional arguments:
12 -d, --dry-run Perform a trial run with no changes made
13 printing the commands instead.
14 -r, --reuse-abi Do not download the previous release ABI files
15 for the new release and just rename the
16 current ABI directory. This might cause the
17 build to fail if the module list or the
18 retpoline information has changed.
19 -h, --help Show this help message and exit.
20
21Environment variable:
22 CRANKY_MAILENFORCE Regular expression used to validate \$DEBEMAIL. If not
23 set, it defaults to "@canonical.com$".
24
25Examples:
26 Simply start a new release (that will fetch the ABI files from the
27 archieve repositories):
28 \$ cranky open
29
30 Start a new release re-using the ABI files already present in the
31 tree:
32 \$ cranky open --reuse-abi
33
34EOF
35}
36
37dry_run=0
38reuse_abi=0
39while [ "$#" -gt 0 ]; do
40 case "$1" in
41 -h|--help)
42 usage
43 exit 0
44 ;;
45 -d|--dry-run)
46 dry_run=1
47 ;;
48 -r|--reuse-abi)
49 reuse_abi=1
50 ;;
51 *)
52 usage
53 exit 1
54 ;;
55 esac
56 shift
57done
58
59hl() { echo -e "\e[1m$*\e[0m"; }
60
61run() {
62 # Quote args for echo or eval
63 local quoted=()
64 for token; do
65 quoted+=("$(printf '%q' "$token")")
66 done
67 # Run
68 if [ "$dry_run" -eq 1 ]; then
69 hl "DRY RUN: ${quoted[*]}"
70 else
71 hl "${quoted[*]}"
72 "$@"
73 echo
74 fi
75}
76
77# Trick shellcheck so it doesn't complain every time it's necessary to
78# use `run $CHROOT`. Use `chroot_run` instead.
79shopt -s expand_aliases
80alias chroot_run='run ${CHROOT:-}'
81
82# Check DEBEMAIL (used to create the new changelog stanza):
83DEBEMAIL="${DEBEMAIL:-}"
84CRANKY_MAILENFORCE="${CRANKY_MAILENFORCE:-@canonical.com\$}"
85if [ -z "$DEBEMAIL" ] || ! echo "$DEBEMAIL" | grep -qE "$CRANKY_MAILENFORCE"; then
86 echo "DEBEMAIL is unset, or does not contain \"$CRANKY_MAILENFORCE\": $DEBEMAIL" >&2
87 exit 1
88fi
89
90# Requires a git repo
91if [ ! -e .git ]; then
92 echo "Not a git repository!" >&2
93 exit 1
94fi
95
96# Check the debian directory
97if [ ! -e debian/debian.env ]; then
98 echo "Cannot find debian/debian.env!" >&2
99 exit 1
100fi
101DEBIAN=
102# shellcheck disable=SC1091
103. debian/debian.env
104if [ -z "$DEBIAN" ] || [ ! -d "$DEBIAN" ]; then
105 echo "Invalid DEBIAN directory: $DEBIAN" >&2
106 exit 1
107fi
108
109# Abort if changes or untracked files are found in the debian
d8a358c4 110# directory (ie, in "debian.master/"). cranky open is expected to
c74bfc18
LO
111# change and commit files in this directory.
112if ! git diff-index --quiet HEAD -- "$DEBIAN/" || \
113 [ -n "$(git ls-files --others -- "$DEBIAN/")" ]; then
114 echo "\"$DEBIAN/\" is not clean!" >&2
115 exit 1
116fi
117
118# Check changelog
119series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution)
120if [ "$series" == 'UNRELEASED' ]; then
121 echo "$DEBIAN/changelog is not closed!" >&2
122 exit 1
123fi
124
125# Load the info about derivative
126BACKPORT_SUFFIX=
127derivative_conf="$DEBIAN/etc/update.conf"
128if [ -f "$derivative_conf" ]; then
129 # shellcheck disable=SC1090
130 . "$derivative_conf"
131fi
132
133# Run the update script used for backport kernels
134if [ -n "$BACKPORT_SUFFIX" ]; then
135 update_from_master_script="$DEBIAN/scripts/helpers/copy-files"
136 if [ ! -x "$update_from_master_script" ]; then
137 echo "Backport kernel is missing the"\
138 "\"$update_from_master_script\" script!";
139 exit 1
140 fi
141 # The tree should be clean at this point, since that is enforced at
142 # the beginning of the script. Because of that, it's safe to git add
143 # "$DEBIAN/".
144 run env CHROOT="$CHROOT" "$update_from_master_script"
145 run git add "$DEBIAN"
146 # Update configs after the necessary files were copied from
147 # the base kernel. It's not expected that `fdr updateconfigs`
148 # will fail at this point, because the base kernel's
149 # configuration and annotations file are expected to be in a
150 # correct state. `fdr updateconfigs` should only change a few
151 # configuration options that depend on the userspace tooling
152 # version, such as gcc.
153 if ! chroot_run fakeroot debian/rules clean updateconfigs; then
154 echo "Failed to update configs. Please review the previous" \
155 "rebase operation and \"$update_from_master_script\"";
156 exit 1
157 fi
158 run git add "$DEBIAN/config"
159fi
160
161# fdr clean should be called after copy-files, that way we can git add
162# any changes in "debian.<branch>/" (`fdr clean` in trusty will
163# usually generate changes in "debian.<branch>/). Also, fdr clean
164# removes an ABI that matches the current version in the
165# changelog. Since `fdr startnewrelease` requires `fdr clean`, we need
166# to call it before getabis.
167chroot_run fakeroot debian/rules clean
168
169# Update ABI
170if [ -d "$DEBIAN/abi" ]; then
171 # The new ABI directory should use the current version in the
172 # changelog since `fdr startnewrelease` was't called at this
173 # point yet:
174 new=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion)
175
176 if [ "$reuse_abi" -ne 0 ]; then
177 # Get the old ABI directory:
fc199372
TLSC
178 old=$(find "$DEBIAN/abi/" -mindepth 1 -maxdepth 1 -type d | \
179 grep -P '/abi/[0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.[0-9]+')
180 if [ -z "${old}" ] ; then
181 echo "Failed to find the previous ABI directory." \
182 "Please check \"$DEBIAN/abi/\"!" >&2
183 exit 1
184 elif [ "$(echo "$old" | wc -l)" -gt 1 ]; then
c74bfc18
LO
185 echo "Failed to rename the current ABI directory." \
186 "Multiple directories found. Please check \"$DEBIAN/abi/\"!" >&2
187 exit 1
188 fi
189 new="$DEBIAN/abi/$new"
190 # Rename the ABI directory
191 run git mv "$old" "$new"
192 else
193 # Call in-tree getabis:
194 # Use the single argument form since getabis is now
195 # updated by cranky fix.
196 run debian/scripts/misc/getabis "${new}"
197 # getabis already handles the necessary git add/rm calls.
198 fi
199fi
200
201# Create the new changelog entry:
202run fakeroot debian/rules startnewrelease
203run git add "$DEBIAN/changelog"
204
205# Create the commit
206run git commit -s -F debian/commit-templates/newrelease
207
208# Perform a basic ABI check
209if [ "$dry_run" -eq 0 ]; then
210 version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion -c1 -o1)
211 abi_dir="$DEBIAN/abi/$version"
212 [ ! -d "$abi_dir" ] && hl "Warning: ABI directory is missing: $abi_dir"
213fi
214
215# Mimic maint-startnewrelease
216[ "$dry_run" -eq 0 ] && \
217 hl "\n***** Now please inspect the commit before pushing *****"
218
219exit 0