]>
Commit | Line | Data |
---|---|---|
a5923e37 | 1 | #!/bin/bash -eu |
575a9151 | 2 | export LC_ALL=C.UTF-8 |
a5923e37 KE |
3 | |
4 | usage() { | |
5 | cat << EOF | |
6 | Usage: ${P:-$(basename "$0")} [-h|--help] [-d|--dry-run] [-r|--reuse-abi] | |
7 | ||
8 | Create a "start new release" commit. The new commit will contain ABI | |
9 | changes and any customization required by backport kernels. | |
10 | ||
11 | Optional 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 | ||
21 | Environment variable: | |
22 | CRANKY_MAILENFORCE Regular expression used to validate \$DEBEMAIL. If not | |
23 | set, it defaults to "@canonical.com$". | |
24 | ||
25 | Examples: | |
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 | ||
34 | EOF | |
35 | } | |
36 | ||
37 | dry_run=0 | |
38 | reuse_abi=0 | |
39 | while [ "$#" -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 | |
57 | done | |
58 | ||
59 | hl() { echo -e "\e[1m$*\e[0m"; } | |
60 | ||
61 | run() { | |
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. | |
79 | shopt -s expand_aliases | |
80 | alias chroot_run='run ${CHROOT:-}' | |
81 | ||
82 | # Check DEBEMAIL (used to create the new changelog stanza): | |
83 | DEBEMAIL="${DEBEMAIL:-}" | |
84 | CRANKY_MAILENFORCE="${CRANKY_MAILENFORCE:-@canonical.com\$}" | |
85 | if [ -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 | |
88 | fi | |
89 | ||
90 | # Requires a git repo | |
91 | if [ ! -e .git ]; then | |
92 | echo "Not a git repository!" >&2 | |
93 | exit 1 | |
94 | fi | |
95 | ||
96 | # Check the debian directory | |
97 | if [ ! -e debian/debian.env ]; then | |
98 | echo "Cannot find debian/debian.env!" >&2 | |
99 | exit 1 | |
100 | fi | |
101 | DEBIAN= | |
102 | # shellcheck disable=SC1091 | |
103 | . debian/debian.env | |
104 | if [ -z "$DEBIAN" ] || [ ! -d "$DEBIAN" ]; then | |
105 | echo "Invalid DEBIAN directory: $DEBIAN" >&2 | |
106 | exit 1 | |
107 | fi | |
108 | ||
109 | # Abort if changes or untracked files are found in the debian | |
110 | # directory (ie, in "debian.master/"). cranky-open is expected to | |
111 | # change and commit files in this directory. | |
112 | if ! git diff-index --quiet HEAD -- "$DEBIAN/" || \ | |
113 | [ -n "$(git ls-files --others -- "$DEBIAN/")" ]; then | |
114 | echo "\"$DEBIAN/\" is not clean!" >&2 | |
115 | exit 1 | |
116 | fi | |
117 | ||
118 | # Check changelog | |
119 | series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution) | |
120 | if [ "$series" == 'UNRELEASED' ]; then | |
121 | echo "$DEBIAN/changelog is not closed!" >&2 | |
122 | exit 1 | |
123 | fi | |
124 | ||
125 | # Load the info about derivative | |
126 | BACKPORT_SUFFIX= | |
127 | derivative_conf="$DEBIAN/etc/update.conf" | |
128 | if [ -f "$derivative_conf" ]; then | |
129 | # shellcheck disable=SC1090 | |
130 | . "$derivative_conf" | |
131 | fi | |
132 | ||
133 | # Run the update script used for backport kernels | |
134 | if [ -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" | |
159 | fi | |
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. | |
167 | chroot_run fakeroot debian/rules clean | |
168 | ||
169 | # Update ABI | |
170 | if [ -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: | |
178 | old=$(find "$DEBIAN/abi/" -mindepth 1 -maxdepth 1 -type d -a -name "${new%%-*}*") | |
179 | if [ "$(echo "$old" | wc -l)" -gt 1 ]; then | |
180 | echo "Failed to rename the current ABI directory." \ | |
181 | "Multiple directories found. Please check \"$DEBIAN/abi/\"!" >&2 | |
182 | exit 1 | |
183 | fi | |
184 | new="$DEBIAN/abi/$new" | |
185 | # Rename the ABI directory | |
186 | run git mv "$old" "$new" | |
187 | else | |
188 | # Call in-tree getabis: | |
189 | # Use the single argument form since getabis is now | |
190 | # updated by cranky fix. | |
191 | run debian/scripts/misc/getabis "${new}" | |
192 | # getabis already handles the necessary git add/rm calls. | |
193 | fi | |
194 | fi | |
195 | ||
196 | # Create the new changelog entry: | |
197 | run fakeroot debian/rules startnewrelease | |
198 | run git add "$DEBIAN/changelog" | |
199 | ||
200 | # Create the commit | |
201 | run git commit -s -F debian/commit-templates/newrelease | |
202 | ||
203 | # Perform a basic ABI check | |
204 | if [ "$dry_run" -eq 0 ]; then | |
205 | version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion -c1 -o1) | |
206 | abi_dir="$DEBIAN/abi/$version" | |
207 | [ ! -d "$abi_dir" ] && hl "Warning: ABI directory is missing: $abi_dir" | |
208 | fi | |
209 | ||
210 | # Mimic maint-startnewrelease | |
211 | [ "$dry_run" -eq 0 ] && \ | |
212 | hl "\n***** Now please inspect the commit before pushing *****" | |
5ca64a3d KSS |
213 | |
214 | exit 0 |