-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
get-fedora-latest-config
executable file
·153 lines (126 loc) · 4.65 KB
/
get-fedora-latest-config
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
#!/bin/bash
# vim: set ts=4 sw=4 sts=4 et :
set -e
if [ "${VERBOSE:-0}" -ge 2 ] || [ "${DEBUG:-0}" -eq 1 ]; then
debug=1
set -x
fi
exit_clean() {
local exit_code=$?
if [ -n "$tmpdir" ]; then
rm -rf "$tmpdir"
fi
if [ ${exit_code} != 0 ]; then
errecho "Unable to find the latest kernel rpm for Fedora $releasever";
fi
exit "${exit_code}"
}
errecho() {
>&2 echo "$@"
}
usage() {
errecho "Usage: $0 [OPTIONS]... []
This script is used for fetching latest Fedora kernel config for the current
kernel version used by Qubes.
Options:
--releasever <Fedora RELEASEVER> Fedora release version to use. Default is latest.
--include-testing Include testing updates repository
--include-rc Include release candidate kernels
Remark:
Ensure to have downloaded kernel sources in local directory (make get-sources).
"
exit 1
}
get_releasever() {
releasever="$1"
# example of releasever: '29' or 'rawhide'
if [ -n "$releasever" ]; then
if [[ ! "$releasever" =~ ^[1-9][0-9]$ ]] && [ "$releasever" != "rawhide" ]; then
errecho "Invalid release format"
exit 1
fi
elif [ -z "$releasever" ]; then
releasever="$(git ls-remote --heads https://src.fedoraproject.org/rpms/fedora-release | grep -Po "refs/heads/f[0-9][1-9]*" | sed 's#refs/heads/f##g' | sort -g | tail -1)"
if ! [[ "$releasever" =~ ^[1-9][0-9]$ ]]; then
errecho "An error occurred while trying to determine latest Fedora version"
exit 1
fi
fi
echo "$releasever"
}
localdir="$(dirname "$(readlink -f "$0")")"
kernelver="$(cat "$localdir/version")"
kernelsrc="linux-$kernelver"
kernelarchive="$kernelsrc.tar"
if ! OPTS=$(getopt -o hv:t:r: --long help,releasever:,include-testing,include-rc -n "$0" -- "$@"); then
errecho "An error occurred while parsing options."
exit 1
fi
eval set -- "$OPTS"
while [[ $# -gt 0 ]]; do
case "$1" in
-a | --releasever ) releasever="$2"; shift ;;
-m | --include-testing ) ktesting="1";;
-i | --include-rc ) krc="1";;
-h | --help) usage ;;
esac
shift
done
if [ ! -e "$localdir/$kernelarchive" ]; then
errecho "Cannot find $kernelarchive in local directory."
exit 1
fi
trap 'exit_clean' 0 1 2 3 6 15
releasever=$(get_releasever "$releasever")
# get the latest kernel rpm
repo_opts="--disablerepo=* --enablerepo=fedora --enablerepo=updates --releasever=$releasever"
# include testing
if [ "$ktesting" == "1" ]; then
repo_opts="$repo_opts --enablerepo=updates-testing"
fi
# shellcheck disable=SC2086
latestver=$(dnf -q repoquery kernel-core $repo_opts)
# include rc
if [ "$krc" != "1" ]; then
latestver=$(echo "$latestver" | grep -v "rc[0-9]*")
fi
latestver=$(echo "$latestver" | sort -V | tail -1 | cut -d ':' -f2)
latestrpm="kernel-core-$latestver.rpm"
if [ "$releasever" == 'rawhide' ]; then
releasever="$(echo "$latestver" | grep -o "fc[1-9][0-9]" | sed 's/fc//')"
fi
if [ -n "$latestrpm" ] && [ -n "$releasever" ]; then
key="$localdir/../builder-rpm/keys/RPM-GPG-KEY-fedora-$releasever-primary"
tmpdir="$(mktemp -d -p "$localdir")"
# download latest kernel rpm
# shellcheck disable=SC2086
dnf -q download kernel-core $repo_opts
mv "$latestrpm" "$tmpdir/$latestrpm.untrusted"
# check signature
mkdir -p "$tmpdir/rpmdb"
rpmkeys --dbpath="$tmpdir/rpmdb" --import "$key"
{ rpmkeys --dbpath="$tmpdir/rpmdb" --checksig "$tmpdir/$latestrpm.untrusted" | grep -q 'signatures OK' ; } || { errecho "Failed to check signature"; exit 1; }
mv "$tmpdir/$latestrpm.untrusted" "$tmpdir/$latestrpm"
# extract kernel sources in qubes-linux-kernel
tar xf "$localdir/$kernelarchive" -C "$tmpdir"
# get latest config and put it in extracted sources
rpm2cpio "$tmpdir/$latestrpm" | cpio --quiet -i --to-stdout "./lib/modules/$latestver/config" > "$tmpdir/$kernelsrc/.config"
# generate new config with: yes '' | make oldconfig
cd "$tmpdir/$kernelsrc/"
## drop config settings which depend on Fedora patches and adjust for the small version difference
if [ "$debug" == "1" ]; then
yes '' | make oldconfig
else
yes '' | make oldconfig > /dev/null 2>&1
fi
## remove comments in header
sed -i '1,4d' "$tmpdir/$kernelsrc/.config"
# create final config
cat - "$tmpdir/$kernelsrc/.config" > "$localdir/config-base-$(echo "$latestver" | cut -d '-' -f1)" << EOF
# Base config based on Fedora's config ($latestrpm)
# Only modification is \`yes '' | make oldconfig\` to drop config settings which
# depend on Fedora patches and adjust for the small version difference.
EOF
else
exit 1
fi