forked from Frogging-Family/linux-tkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-kernel-versions.sh
executable file
·202 lines (166 loc) · 7.29 KB
/
update-kernel-versions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
msg2() {
echo -e " \033[1;34m->\033[1;0m \033[1;1m$1\033[1;0m" >&2
}
escape() {
_escaped=$(printf '%s\n' "$1" | sed -e 's/[]\/$*.^[]/\\&/g')
}
kernel_rc_tags=$(git -c 'versionsort.suffix=-' \
ls-remote --exit-code --refs --sort='version:refname' --tags https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git '*.*' \
| cut --delimiter='/' --fields=3)
source linux-tkg-config/prepare
trap - EXIT
# Start by making sure our GnuPG environment is sane
if [[ ! -x /usr/bin/gpg ]]; then
echo "Could not find gpg"
exit 4
fi
## Generate the keyring
if [ ! -s gnupg/keyring.gpg ]; then
if [[ ! -d gnupg ]]; then
echo "gnupg directory does not exist"
mkdir -p -m 0700 gnupg
fi
echo "Making sure we have all the necessary keys"
gpg --batch --quiet --homedir gnupg --auto-key-locate wkd --locate-keys [email protected]
if [[ $? != "0" ]]; then
echo "FAILED to retrieve keys"
exit 3
fi
gpg --batch --homedir gnupg --export [email protected] [email protected] [email protected] > gnupg/keyring.gpg
echo "----------------------"
fi
# Cleanup
rm -f v*.x.sha256sums{,.asc}
updates=""
for _key in "${_current_kernels[@]}"; do
kver_major="$(echo ${_key} | cut -d. -f1)"
kver_base="$(echo ${_key} | tr -d ".")"
## Getting sha256sums by sha256sums.asc
if [ ! -s v${kver_major}.x.sha256sums ]; then
echo "Downloading the checksums file for linux-v${kver_major}.x"
curl -sL --retry 2 -o "v${kver_major}.x.sha256sums.asc" https://cdn.kernel.org/pub/linux/kernel/v${kver_major}.x/sha256sums.asc
if [[ $? != "0" ]]; then
echo "FAILED to download the v${kver_major}.x checksums file"
exit 3
fi
echo "Verifying the v${kver_major}.x checksums file"
count_gpg=$(gpg --homedir gnupg --keyring=gnupg/keyring.gpg --status-fd=1 v${kver_major}.x.sha256sums.asc | grep -c -E '^\[GNUPG:\] (GOODSIG|VALIDSIG)')
if [[ ${count_gpg} -lt 2 ]]; then
echo "FAILED to verify the v${kver_major}.x.sha256sums file."
rm -f "v${kver_major}.x.sha256sums"
exit 3
fi
rm -f "v${kver_major}.x.sha256sums.asc"
echo "----------------------"
fi
_from_rc_to_release="false"
latest_full_ver=$(cut -c 67- v${kver_major}.x.sha256sums | grep ".tar.xz" | sed 's/.tar.xz//' | grep -F "linux-$_key" | tail -1 | sed 's/linux-//')
if [[ "${_kver_subver_map[$_key]}" == rc* ]]; then
# check if latest_full_ver is non-RC
if [ ! -n "$latest_full_ver" ]; then
latest_full_ver=$(echo "$kernel_rc_tags" | grep -F "v$_key-rc" | tail -1 | cut -c2-)
fi
if [[ "$latest_full_ver" == *rc* ]]; then
latest_subver="${latest_full_ver##*-rc}"
else
_from_rc_to_release="true"
if [ "$latest_full_ver" = "$_key" ]; then
# this is the first release after rc, so the kernel version will be 5.xx (and not 5.xx.0)
latest_subver="0"
else
# For whatever reason we are moving from an rc kernel to 5.xx.y
latest_subver="${latest_full_ver##*.}"
fi
fi
current_subver="${_kver_subver_map[$_key]}"
current_subver="${current_subver##*rc}"
else
if [ "$latest_full_ver" != "$_key" ]; then
latest_subver="${latest_full_ver##*.}"
else
latest_subver="0"
fi
current_subver=${_kver_subver_map[$_key]}
fi
echo "current version on repository $_key.${_kver_subver_map[$_key]} -> $current_subver"
echo "upstream version $latest_full_ver -> $latest_subver"
old_kernel_shasum=""
new_kernel_shasum=""
old_kernel_patch_shasum=""
new_kernel_patch_shasum=""
if [ "$_from_rc_to_release" = "true" ]; then
# append kernel version update to updates
updates="${updates} ${latest_full_ver}"
echo "Updating from rc kernel to release in linux-tkg-config/prepare"
escape "[\"${_key}\"]=\"rc${current_subver}\""
_from="$_escaped"
escape "[\"${_key}\"]=\"${latest_subver}\""
_to="$_escaped"
sed -i "/^_kver_subver_map=($/,/^)$/s|$_from|$_to|g" linux-tkg-config/prepare
old_kernel_shasum=$(grep -A$(wc -l PKGBUILD | cut -d' ' -f1) "${kver_base})" PKGBUILD | grep sha256sums -m 1 - | cut -d \' -f2)
new_kernel_shasum=$(grep linux-${_key}.tar.xz v${kver_major}.x.sha256sums | cut -d' ' -f1)
if [ ! -n "$new_kernel_shasum" ]; then
echo "WARNING sha256sum for linux-${_key} was not found."
fi
if [ "$latest_subver" != "0" ]; then
# we move from an rc release directly to a kernel with a subversion update
sed -i "s|#\"\$patch_site\"|\"\$patch_site\"|g" PKGBUILD
old_kernel_patch_shasum="#upcoming_kernel_patch_sha256"
new_kernel_patch_shasum="'$(grep patch-${_key}.${latest_subver}.xz v${kver_major}.x.sha256sums | cut -d' ' -f1)'"
fi
elif (( "$current_subver" < "$latest_subver" )); then
# append kernel version update to updates
updates="${updates} ${latest_full_ver}"
echo "Newer upstream"
if [[ "${_kver_subver_map[$_key]}" == rc* ]]; then
echo "Updating rc kernel version in linux-tkg-config/prepare"
escape "[\"${_key}\"]=\"rc${current_subver}\""
_from="$_escaped"
escape "[\"${_key}\"]=\"rc${latest_subver}\""
_to="$_escaped"
sed -i "/^_kver_subver_map=($/,/^)$/s|$_from|$_to|g" linux-tkg-config/prepare
old_kernel_shasum=$(grep -A$(wc -l PKGBUILD | cut -d' ' -f1) "${kver_base})" PKGBUILD | grep sha256sums -m 1 - | cut -d \' -f2)
# For RC we need download the original file
echo "Downloading the GZ tarball for linux-${_key}-rc${latest_subver}"
curl -sL --retry 2 -o "linux-${_key}-rc${latest_subver}.tar.gz" https://git.kernel.org/torvalds/t/linux-${_key}-rc${latest_subver}.tar.gz
if [[ $? != "0" ]]; then
echo "FAILED to download the linux-${_key}-rc${latest_subver}.tar.gz"
exit 3
fi
new_kernel_shasum=$(sha256sum linux-${_key}-rc${latest_subver}.tar.gz | cut -d' ' -f1)
else
echo "Updating kernel version in linux-tkg-config/prepare"
escape "[\"${_key}\"]=\"${current_subver}\""
_from="$_escaped"
escape "[\"${_key}\"]=\"${latest_subver}\""
_to="$_escaped"
sed -i "/^_kver_subver_map=($/,/^)$/s|$_from|$_to|g" linux-tkg-config/prepare
if [ "$current_subver" = "0" ]; then
# we move from an initial release to a kernel subversion update
sed -i "s|#\"\$patch_site\"|\"\$patch_site\"|g" PKGBUILD
old_kernel_patch_shasum="#upcoming_kernel_patch_sha256"
new_kernel_patch_shasum="'$(grep patch-${_key}.${latest_subver}.xz v${kver_major}.x.sha256sums | cut -d' ' -f1)'"
else
old_kernel_patch_shasum="$(grep patch-${_key}.${current_subver}.xz v${kver_major}.x.sha256sums | cut -d' ' -f1)"
new_kernel_patch_shasum="$(grep patch-${_key}.${latest_subver}.xz v${kver_major}.x.sha256sums | cut -d' ' -f1)"
fi
fi
else
echo "Same upstream"
fi
if [ -n "$new_kernel_shasum" ]; then
echo "Updating kernel shasum in PKGBUILD"
echo "old kernel: $old_kernel_shasum"
echo "new kernel: $new_kernel_shasum"
sed -i "s|$old_kernel_shasum|$new_kernel_shasum|g" PKGBUILD
fi
if [ -n "$new_kernel_patch_shasum" ]; then
echo "Updating kernel patch shasum in PKGBUILD"
echo "old kernel patch: $old_kernel_patch_shasum"
echo "new kernel patch: $new_kernel_patch_shasum"
sed -i "s|$old_kernel_patch_shasum|$new_kernel_patch_shasum|g" PKGBUILD
fi
echo "----------------------"
done
echo "$updates" > kernel_updates