2018-12-22 14:56:34 +00:00
|
|
|
#!/bin/bash
|
2019-03-28 10:58:46 +00:00
|
|
|
# vim: set ts=4 sw=4 sts=4 et :
|
2018-12-22 14:56:34 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
if [ "${VERBOSE:-0}" -ge 2 ] || [ "${DEBUG:-0}" -eq 1 ]; then
|
2019-03-28 10:58:46 +00:00
|
|
|
debug=1
|
2018-12-22 14:56:34 +00:00
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
localdir="$(dirname "$(readlink -f "$0")")"
|
|
|
|
releasever="$1"
|
2019-12-07 09:08:27 +00:00
|
|
|
# Set to 1 to include rc srpm
|
|
|
|
rc="$2"
|
2018-12-22 14:56:34 +00:00
|
|
|
|
|
|
|
kernelver="$(cat "$localdir/version")"
|
|
|
|
kernelsrc="linux-$kernelver"
|
|
|
|
|
2019-12-07 09:08:27 +00:00
|
|
|
exit_clean() {
|
|
|
|
local exit_code=$?
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
exit "${exit_code}"
|
|
|
|
}
|
|
|
|
|
2019-03-28 10:58:46 +00:00
|
|
|
errecho() {
|
|
|
|
>&2 echo "$@"
|
|
|
|
}
|
2018-12-23 21:06:49 +00:00
|
|
|
|
2019-03-28 10:58:46 +00:00
|
|
|
# example of releasever: '29' or 'rawhide'
|
|
|
|
if [ "x$releasever" != "x" ]; then
|
|
|
|
if [[ ! "$releasever" =~ ^[1-9][0-9]$ ]] && [ "$releasever" != "rawhide" ]; then
|
|
|
|
errecho "Invalid release format"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
elif [ "x$releasever" == "x" ]; then
|
|
|
|
listver="$(curl -s -L https://dl.fedoraproject.org/pub/fedora/linux/releases 2> /dev/null)"
|
|
|
|
releasever="$(echo "$listver" | sed -e 's/<[^>]*>//g' | awk '{print $1}' | grep -o "[1-9][0-9]" | tail -1)"
|
|
|
|
if ! [[ "$releasever" =~ ^[1-9][0-9]$ ]]; then
|
|
|
|
errecho "An error occurred while trying to determine latest Fedora version"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-03-15 21:28:54 +00:00
|
|
|
fi
|
2018-12-22 14:56:34 +00:00
|
|
|
|
|
|
|
# get the latest kernel rpm
|
2019-12-07 09:08:27 +00:00
|
|
|
latestver=$(dnf -q repoquery kernel-core --disablerepo=* --enablerepo=fedora --enablerepo=updates --releasever="$releasever")
|
|
|
|
if [ "$rc" != "1" ]; then
|
|
|
|
latestver=$(echo "$latestver" | grep -v "rc[0-9]*")
|
|
|
|
fi
|
|
|
|
latestver=$(echo "$latestver" | sort -V | tail -1 | cut -d ':' -f2)
|
2019-03-28 10:58:46 +00:00
|
|
|
latestrpm="kernel-core-$latestver.rpm"
|
|
|
|
|
|
|
|
if [ "$releasever" == 'rawhide' ]; then
|
|
|
|
releasever="$(echo "$latestver" | grep -o "fc[1-9][0-9]" | sed 's/fc//')"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$latestrpm" != "x" ] && [ "x$releasever" != "x" ]; then
|
|
|
|
key="$localdir/keys/RPM-GPG-KEY-fedora-$releasever-primary"
|
2018-12-22 14:56:34 +00:00
|
|
|
|
2019-12-07 09:08:27 +00:00
|
|
|
trap 'exit_clean' 0 1 2 3 6 15
|
2019-04-20 15:11:28 +00:00
|
|
|
tmpdir="$(mktemp -d -p "$localdir")"
|
2018-12-22 14:56:34 +00:00
|
|
|
# download latest kernel rpm
|
2019-04-20 15:12:07 +00:00
|
|
|
dnf -q download kernel-core --disablerepo=* --enablerepo=fedora --enablerepo=updates --releasever="$releasever"
|
2019-03-28 10:58:46 +00:00
|
|
|
mv "$latestrpm" "$tmpdir/$latestrpm.untrusted"
|
2018-12-23 21:06:49 +00:00
|
|
|
|
|
|
|
# check signature
|
|
|
|
mkdir -p "$tmpdir/rpmdb"
|
|
|
|
rpmkeys --dbpath="$tmpdir/rpmdb" --import "$key"
|
2019-03-28 10:58:46 +00:00
|
|
|
{ rpmkeys --dbpath="$tmpdir/rpmdb" --checksig "$tmpdir/$latestrpm.untrusted" | grep -q 'signatures OK' ; } || { errecho "Failed to check signature"; exit 1; }
|
2018-12-23 21:06:49 +00:00
|
|
|
mv "$tmpdir/$latestrpm.untrusted" "$tmpdir/$latestrpm"
|
2018-12-22 14:56:34 +00:00
|
|
|
|
|
|
|
# extract kernel sources in qubes-linux-kernel
|
|
|
|
tar xf "$localdir/$kernelsrc.tar.xz" -C "$tmpdir"
|
|
|
|
|
|
|
|
# get latest config and put it in extracted sources
|
2019-03-28 10:58:46 +00:00
|
|
|
rpm2cpio "$tmpdir/$latestrpm" | cpio --quiet -i --to-stdout "./lib/modules/$latestver/config" > "$tmpdir/$kernelsrc/.config"
|
2018-12-22 14:56:34 +00:00
|
|
|
|
|
|
|
# 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
|
2019-03-28 10:58:46 +00:00
|
|
|
if [ "$debug" == "1" ]; then
|
|
|
|
yes '' | make oldconfig
|
|
|
|
else
|
|
|
|
yes '' | make oldconfig > /dev/null 2>&1
|
|
|
|
fi
|
2018-12-22 14:56:34 +00:00
|
|
|
## remove comments in header
|
|
|
|
sed -i '1,4d' "$tmpdir/$kernelsrc/.config"
|
|
|
|
|
|
|
|
# create final config
|
2019-03-28 10:58:46 +00:00
|
|
|
cat - "$tmpdir/$kernelsrc/.config" > "$localdir/config-base-$(echo "$latestver" | cut -d '-' -f1)" << EOF
|
2018-12-22 14:56:34 +00:00
|
|
|
# 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
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
else
|
2019-03-28 10:58:46 +00:00
|
|
|
errecho "Unable to find the latest kernel rpm for Fedora $releasever"; exit 1
|
2018-12-22 14:56:34 +00:00
|
|
|
fi
|