-
Notifications
You must be signed in to change notification settings - Fork 5
/
fetch.sh
executable file
·214 lines (188 loc) · 9.45 KB
/
fetch.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
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/bash
set -eoux pipefail
kernel_version="${KERNEL_VERSION}"
kernel_flavor="${KERNEL_FLAVOR}"
build_tag="${KERNEL_BUILD_TAG:-latest}"
# CoreOS pool repo
# curl -LsSf -o /etc/yum.repos.d/fedora-coreos-pool.repo \
# https://raw.githubusercontent.com/coreos/fedora-coreos-config/testing-devel/fedora-coreos-pool.repo
dnf install -y dnf-plugins-core rpmrebuild sbsigntools openssl
case "$kernel_flavor" in
"asus")
dnf copr enable -y lukenukem/asus-kernel
;;
"fsync")
dnf copr enable -y sentry/kernel-fsync
;;
"fsync-ba")
dnf copr enable -y sentry/kernel-ba
;;
"surface")
dnf config-manager --add-repo=https://pkg.surfacelinux.com/fedora/linux-surface.repo
;;
"coreos-stable")
;;
"coreos-testing")
;;
"bazzite")
;;
"main")
;;
*)
echo "unexpected kernel_flavor ${kernel_flavor} for query"
;;
esac
if [[ "${kernel_flavor}" =~ asus|fsync ]]; then
dnf download -y \
kernel-"${kernel_version}" \
kernel-modules-"${kernel_version}" \
kernel-modules-core-"${kernel_version}" \
kernel-modules-extra-"${kernel_version}" \
kernel-devel-"${kernel_version}" \
kernel-devel-matched-"${kernel_version}" \
kernel-uki-virt-"${kernel_version}"
elif [[ "${kernel_flavor}" == "surface" ]]; then
dnf download -y \
kernel-surface-"${kernel_version}" \
kernel-surface-modules-"${kernel_version}" \
kernel-surface-modules-core-"${kernel_version}" \
kernel-surface-modules-extra-"${kernel_version}" \
kernel-surface-devel-"${kernel_version}" \
kernel-surface-devel-matched-"${kernel_version}" \
kernel-surface-default-watchdog-"${kernel_version}" \
iptsd \
libwacom-surface \
libwacom-surface-data
elif [[ "${kernel_flavor}" == "bazzite" ]]; then
# Using curl for bazzite release
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-core-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-modules-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-modules-core-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-modules-extra-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-devel-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-devel-matched-"$kernel_version".rpm
curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-uki-virt-"$kernel_version".rpm
# curl -LO https://github.com/hhd-dev/kernel-bazzite/releases/download/"$build_tag"/kernel-uki-virt-addons-"$kernel_version".rpm
else
KERNEL_MAJOR_MINOR_PATCH=$(echo "$kernel_version" | cut -d '-' -f 1)
KERNEL_RELEASE="$(echo "$kernel_version" | cut -d - -f 2 | cut -d . -f 1).$(echo "$kernel_version" | cut -d - -f 2 | cut -d . -f 2)"
ARCH=$(uname -m)
# Using curl instead of dnf download for https links
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-"$kernel_version".rpm
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-modules-"$kernel_version".rpm
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-modules-core-"$kernel_version".rpm
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-modules-extra-"$kernel_version".rpm
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-devel-"$kernel_version".rpm
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-devel-matched-"$kernel_version".rpm
curl -LO https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-uki-virt-"$kernel_version".rpm
fi
if [[ "${kernel_flavor}" =~ fsync|fsync-ba ]]; then
dnf download -y \
kernel-headers-"${kernel_version}"
fi
if [[ ! -s /tmp/certs/private_key.priv ]]; then
echo "WARNING: Using test signing key."
cp /tmp/certs/private_key.priv{.test,}
cp /tmp/certs/public_key.der{.test,}
fi
PUBLIC_KEY_PATH="/etc/pki/kernel/public/public_key.crt"
PRIVATE_KEY_PATH="/etc/pki/kernel/private/private_key.priv"
openssl x509 -in /tmp/certs/public_key.der -out /tmp/certs/public_key.crt
install -Dm644 /tmp/certs/public_key.crt "$PUBLIC_KEY_PATH"
install -Dm644 /tmp/certs/private_key.priv "$PRIVATE_KEY_PATH"
ls -la /
if [[ "${kernel_flavor}" =~ asus|fsync|fsync-ba ]]; then
dnf install -y \
/kernel-"$kernel_version".rpm \
/kernel-modules-"$kernel_version".rpm \
/kernel-modules-core-"$kernel_version".rpm \
/kernel-modules-extra-"$kernel_version".rpm \
kernel-core-"${kernel_version}"
elif [[ "${kernel_flavor}" =~ surface ]]; then
dnf install -y \
/kernel-surface-"$kernel_version".rpm \
/kernel-surface-modules-"$kernel_version".rpm \
/kernel-surface-modules-core-"$kernel_version".rpm \
/kernel-surface-modules-extra-"$kernel_version".rpm \
kernel-surface-core-"${kernel_version}"
elif [[ "${kernel_flavor}" == "bazzite" ]]; then
dnf install -y \
/kernel-"$kernel_version".rpm \
/kernel-core-"$kernel_version".rpm \
/kernel-modules-"$kernel_version".rpm \
/kernel-modules-core-"$kernel_version".rpm \
/kernel-modules-extra-"$kernel_version".rpm
else
dnf install -y \
/kernel-"$kernel_version".rpm \
/kernel-modules-"$kernel_version".rpm \
/kernel-modules-core-"$kernel_version".rpm \
/kernel-modules-extra-"$kernel_version".rpm \
https://kojipkgs.fedoraproject.org//packages/kernel/"$KERNEL_MAJOR_MINOR_PATCH"/"$KERNEL_RELEASE"/"$ARCH"/kernel-core-"$kernel_version".rpm
fi
# Strip Signatures from non-fedora Kernels
if [[ ${kernel_flavor} =~ main|coreos ]]; then
echo "Will not strip Fedora signature(s) from ${kernel_flavor} kernel."
else
EXISTING_SIGNATURES="$(sbverify --list /usr/lib/modules/"$kernel_version"/vmlinuz | grep '^signature \([0-9]\+\)$' | sed 's/^signature \([0-9]\+\)$/\1/')" || true
if [[ -n "$EXISTING_SIGNATURES" ]]; then
for SIGNUM in $EXISTING_SIGNATURES; do
echo "Found existing signature at signum $SIGNUM, removing..."
sbattach --remove /usr/lib/modules/"${kernel_version}"/vmlinuz
done
fi
fi
# Sign Kernel with Key
sbsign --cert "$PUBLIC_KEY_PATH" --key "$PRIVATE_KEY_PATH" /usr/lib/modules/"${kernel_version}"/vmlinuz --output /usr/lib/modules/"${kernel_version}"/vmlinuz
# Verify Signatures
sbverify --list /usr/lib/modules/"${kernel_version}"/vmlinuz
rm -f "$PRIVATE_KEY_PATH" "$PUBLIC_KEY_PATH"
if [[ ${DUAL_SIGN:-} == "true" ]]; then
SECOND_PUBLIC_KEY_PATH="/etc/pki/kernel/public/public_key_2.crt"
SECOND_PRIVATE_KEY_PATH="/etc/pki/kernel/private/public_key_2.priv"
if [[ ! -s /tmp/certs/private_key_2.priv ]]; then
echo "WARNING: Using test signing key."
cp /tmp/certs/private_key_2.priv{.test,}
cp /tmp/certs/public_key_2.der{.test,}
find /tmp/certs/
fi
openssl x509 -in /tmp/certs/public_key_2.der -out /tmp/certs/public_key_2.crt
install -Dm644 /tmp/certs/public_key_2.crt "$SECOND_PUBLIC_KEY_PATH"
install -Dm644 /tmp/certs/private_key_2.priv "$SECOND_PRIVATE_KEY_PATH"
sbsign --cert "$SECOND_PUBLIC_KEY_PATH" --key "$SECOND_PRIVATE_KEY_PATH" /usr/lib/modules/"${kernel_version}"/vmlinuz --output /usr/lib/modules/"${kernel_version}"/vmlinuz
sbverify --list /usr/lib/modules/"${kernel_version}"/vmlinuz
rm -f "$SECOND_PRIVATE_KEY_PATH" "$SECOND_PUBLIC_KEY_PATH"
fi
ln -s / /tmp/buildroot
# Rebuild RPMs and Verify
if [[ "${kernel_flavor}" =~ surface ]]; then
rpmrebuild --additional=--buildroot=/tmp/buildroot --batch kernel-surface-core-"${kernel_version}"
rm -f /usr/lib/modules/"${kernel_version}"/vmlinuz
dnf reinstall -y \
/kernel-surface-"$kernel_version".rpm \
/kernel-surface-modules-"$kernel_version".rpm \
/kernel-surface-modules-core-"$kernel_version".rpm \
/kernel-surface-modules-extra-"$kernel_version".rpm \
/root/rpmbuild/RPMS/"$(uname -m)"/kernel-*.rpm
else
rpmrebuild --additional=--buildroot=/tmp/buildroot --batch kernel-core-"${kernel_version}"
rm -f /usr/lib/modules/"${kernel_version}"/vmlinuz
dnf reinstall -y \
/kernel-"$kernel_version".rpm \
/kernel-modules-"$kernel_version".rpm \
/kernel-modules-core-"$kernel_version".rpm \
/kernel-modules-extra-"$kernel_version".rpm \
/root/rpmbuild/RPMS/"$(uname -m)"/kernel-*.rpm
fi
sbverify --list /usr/lib/modules/"${kernel_version}"/vmlinuz
# Make Temp Dir
mkdir -p /tmp/rpms
# Move RPMs over
mv /kernel-*.rpm /tmp/rpms
mv /root/rpmbuild/RPMS/"$(uname -m)"/kernel-*.rpm /tmp/rpms
if [[ "${kernel_flavor}" =~ surface ]]; then
cp iptsd-*.rpm libwacom-*.rpm /tmp/rpms
fi
# Delete keys in /tmp if we decide to publish this later
rm -rf /tmp/certs