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