]>
Commit | Line | Data |
---|---|---|
a5923e37 | 1 | #!/bin/bash -eu |
575a9151 | 2 | export LC_ALL=C.UTF-8 |
a5923e37 KE |
3 | |
4 | usage() { | |
5 | cat << EOF | |
1d2975de | 6 | Usage: ${P:-$(basename "$0")} [-h|--help] [-d|--dry-run] [-c|--include-config] [-s|--skip-master] [-b BASE_VERSION] |
a5923e37 KE |
7 | |
8 | Prepare the closing release commit. Include all the changelog entries | |
9 | in the current release, including the changes from the base | |
10 | kernel. Also close the changelog entry and check for config changes. | |
11 | ||
12 | Optional arguments: | |
13 | -d, --dry-run Perform a trial run with no changes made | |
14 | printing the commands instead. | |
15 | -c, --include-config Include config changes in the closing commit. | |
16 | -s, --skip-master Skip master kernel changelog entries (used when | |
17 | bootstraping new kernels). | |
1d2975de JH |
18 | -b BASE_VERSION For derivatives and backports, force the changelog |
19 | entries to have the base version as provided (used | |
20 | when changing the base derivative version of a | |
21 | backport). | |
a5923e37 KE |
22 | -h, --help Show this help message and exit. |
23 | ||
24 | Examples: | |
25 | Simply close a release: | |
26 | \$ cranky close | |
27 | ||
28 | Also include any config changes to the closing commit: | |
29 | \$ cranky close -c | |
30 | ||
31 | EOF | |
32 | } | |
33 | ||
34 | dry_run=0 | |
35 | commit_configs=0 | |
36 | skip_master_entries=0 | |
1d2975de | 37 | base_version= |
a5923e37 KE |
38 | while [ "$#" -gt 0 ]; do |
39 | case "$1" in | |
40 | -h|--help) | |
41 | usage | |
42 | exit 0 | |
43 | ;; | |
44 | -d|--dry-run) | |
45 | dry_run=1 | |
46 | ;; | |
47 | -c|--include-config) | |
48 | commit_configs=1 | |
49 | ;; | |
50 | -s|--skip-master) | |
51 | skip_master_entries=1 | |
52 | ;; | |
1d2975de JH |
53 | -b) |
54 | shift | |
55 | base_version="$1" | |
56 | ;; | |
a5923e37 KE |
57 | *) |
58 | usage | |
59 | exit 1 | |
60 | ;; | |
47149618 | 61 | esac |
a5923e37 | 62 | shift |
47149618 KSS |
63 | done |
64 | ||
65 | hl() { echo -e "\e[1m$*\e[0m"; } | |
66 | ||
67 | run() { | |
68 | # Quote args for echo or eval | |
69 | local quoted=() | |
70 | for token; do | |
71 | quoted+=( "$(printf '%q' "$token")" ) | |
72 | done | |
73 | # Run | |
a5923e37 | 74 | if [ "$dry_run" -eq 1 ]; then |
47149618 KSS |
75 | hl "DRY RUN: ${quoted[*]}" |
76 | else | |
77 | hl "${quoted[*]}" | |
a5923e37 | 78 | "$@" |
47149618 KSS |
79 | echo |
80 | fi | |
81 | } | |
82 | ||
a5923e37 KE |
83 | # Trick shellcheck so it doesn't complain every time it's necessary to |
84 | # use `run $CHROOT`. Use `chroot_run` instead. | |
85 | shopt -s expand_aliases | |
86 | alias chroot_run='run ${CHROOT:-}' | |
87 | ||
88 | DEBIAN= | |
89 | # shellcheck disable=SC1091 | |
90 | . debian/debian.env | |
91 | ||
5ca64a3d | 92 | # Check if the "$DEBIAN" directory exists. |
47149618 KSS |
93 | if [ ! -d "$DEBIAN" ]; then |
94 | echo "You must run this script from the top directory of this repository." | |
95 | exit 1 | |
96 | fi | |
5ca64a3d KSS |
97 | |
98 | CONF="$DEBIAN/etc/update.conf" | |
99 | if [ -f "$CONF" ]; then | |
100 | # shellcheck disable=SC1090 | |
101 | . "$CONF" | |
102 | fi | |
47149618 KSS |
103 | |
104 | # Check if changelog is open | |
105 | series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution) | |
106 | if [ "$series" != 'UNRELEASED' ]; then | |
107 | echo "The last entry of the changelog is already released." | |
108 | exit 1 | |
109 | fi | |
110 | ||
111 | # Update configs | |
a5923e37 | 112 | chroot_run fakeroot debian/rules clean updateconfigs |
47149618 | 113 | changes=$(git diff HEAD -- "./$DEBIAN/config/") |
a5923e37 | 114 | if [ "$commit_configs" -eq 0 ] && [ -n "$changes" ]; then |
47149618 KSS |
115 | echo "Config has changed! please, review it and commit." |
116 | exit 1 | |
117 | fi | |
118 | ||
5ca64a3d KSS |
119 | # Derivatives and backports have a master kernel directory (DEBIAN_MASTER). |
120 | if [ "$DEBIAN" != 'debian.master' ] && [ $skip_master_entries == 0 ]; then | |
121 | if [ "$DEBIAN_MASTER" = "" ]; then | |
122 | echo "DEBIAN_MASTER should be defined either in $DEBIAN/etc/update.conf or the environment" | |
123 | exit 1 | |
124 | fi | |
125 | ||
126 | if [ -z "${base_version}" ]; then | |
127 | offset=0 | |
128 | # If not provided as an option, loop through each entry of the current changelog, | |
129 | # searching for an entry that refers to the master version used as base | |
130 | # (ie a line containing "[ Ubuntu: 4.15.0-39.42 ]"): | |
131 | while true; do | |
132 | changes=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SChanges -c1 -o"$offset") | |
133 | if ! [ "$changes" ]; then | |
134 | echo "Failed to retrieve base master version from changelog file: $DEBIAN/changelog" | |
135 | exit 1 | |
136 | fi | |
e10e5160 | 137 | base_version=$(echo "$changes" | sed -n -r -e '/^\s.*\[ Ubuntu: ([~0-9.-]*) \]$/{s//\1/p;q}') |
5ca64a3d KSS |
138 | [ "$base_version" ] && break |
139 | offset=$(( offset + 1 )) | |
140 | done | |
47149618 KSS |
141 | fi |
142 | ||
5ca64a3d KSS |
143 | master_version=$(dpkg-parsechangelog -l${DEBIAN_MASTER}/changelog -SVersion) |
144 | if ! [ "$master_version" ]; then | |
145 | echo "Failed to retrieve current master version from changelog: $DEBIAN/changelog" | |
146 | exit 1 | |
47149618 | 147 | fi |
5ca64a3d KSS |
148 | run ./debian/scripts/misc/insert-ubuntu-changes "$DEBIAN/changelog" "$base_version" "$master_version" \ |
149 | "$DEBIAN_MASTER/changelog" | |
47149618 KSS |
150 | fi |
151 | ||
152 | # Insert local changes | |
153 | run fakeroot debian/rules insertchanges | |
154 | ||
155 | # This should be the last step. If there were no changes to the | |
156 | # changelog, there is nothing to release, so nothing to commit. | |
157 | changes=$(git diff HEAD) | |
a5923e37 | 158 | if [ -z "$changes" ] && [ "$dry_run" -eq 0 ]; then |
47149618 KSS |
159 | hl "No changes to commit." |
160 | exit 1 | |
161 | fi | |
162 | ||
163 | # Find the current series from previous changelog entries: | |
164 | series='' | |
165 | offset=0 | |
166 | while true; do | |
167 | series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution -c1 -o"$offset") | |
168 | if [ "$series" ] && [ "$series" != 'UNRELEASED' ]; then | |
169 | break | |
170 | fi | |
171 | offset=$(( offset + 1 )) | |
172 | done | |
173 | if ! [ "$series" ]; then | |
174 | echo "Failed to retrieve the package series from changelog: $DEBIAN/changelog" | |
175 | exit 1 | |
176 | fi | |
177 | # Close the changelog | |
178 | run dch --nomultimaint -c "$DEBIAN/changelog" -r -D "$series" '' | |
179 | ||
180 | # Commit changes | |
181 | package=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SSource) | |
182 | prefix="Ubuntu$(echo "$package" | sed -r -e 's/linux(-?)/\1/')-" | |
183 | version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion) | |
184 | run git commit -sam "UBUNTU: $prefix$version" |