-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Makefile: include specific target update-sources - Refactor get-fedora-latest-config (cherry picked from commit 8a001e9)
- Loading branch information
Showing
4 changed files
with
221 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import argparse | ||
import requests | ||
import json | ||
|
||
from packaging import version | ||
from packaging.version import parse as parse_version | ||
|
||
|
||
class KernelUpdaterClient: | ||
def __init__(self, version, branch): | ||
self.version = version | ||
self.branch = branch | ||
|
||
def get_version_qubes(self): | ||
return self.version | ||
|
||
def get_version_upstream(self): | ||
url_releases = 'https://www.kernel.org/releases.json' | ||
r = requests.get(url_releases) | ||
latest_upstream = None | ||
if 200 <= r.status_code < 300: | ||
content = json.loads(r.content.decode('utf-8')) | ||
releases = [rel['version'] for rel in content['releases'] if | ||
rel['moniker'] in ('stable', 'longterm')] | ||
|
||
releases.sort(key=parse_version, reverse=True) | ||
|
||
if 'stable-' in self.branch: | ||
branch_version = self.branch.split('-')[1] | ||
releases = [rel for rel in releases if | ||
rel.startswith(branch_version)] | ||
|
||
latest_upstream = releases[0] | ||
else: | ||
print('An error occurred while downloading "%s"' % url_releases) | ||
|
||
return latest_upstream | ||
|
||
def is_update_needed(self): | ||
version_qubes = self.get_version_qubes() | ||
version_upstream = self.get_version_upstream() | ||
if version_qubes and version_upstream and (version.parse(version_qubes) < version.parse(version_upstream)): | ||
return version_upstream | ||
|
||
def parse_args(argv): | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('--check-update', required=False, action='store_true') | ||
parser.add_argument('--version', required=True) | ||
parser.add_argument('--branch', required=True) | ||
|
||
args = parser.parse_args(argv[1:]) | ||
|
||
return args | ||
|
||
|
||
def main(argv): | ||
args = parse_args(argv) | ||
client = KernelUpdaterClient(version=args.version, branch=args.branch) | ||
|
||
if args.check_update: | ||
is_update_needed = client.is_update_needed() | ||
if is_update_needed is not None: | ||
print(is_update_needed) | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main(sys.argv)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
# vim: set ts=4 sw=4 sts=4 et : | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
[ "$DEBUG" = "1" ] && set -x | ||
|
||
distance_version() { | ||
read -ra VER1 <<<"$(echo "$1" | tr '.' ' ')" | ||
read -ra VER2 <<<"$(echo "$2" | tr '.' ' ')" | ||
|
||
[[ ${VER1[0]} -eq ${VER2[0]} ]] && [[ $((VER1[1] - VER2[1])) -le 1 ]] && [[ $((VER1[1] - VER2[1])) -ge 0 ]] | ||
} | ||
|
||
LOCALDIR="$(readlink -f "$(dirname "$0")")" | ||
BUILDERDIR="$LOCALDIR/../../" | ||
VERSION="$(cat version)" | ||
BRANCH="$1" | ||
|
||
if [ -z "$BRANCH" ]; then | ||
# Check if qubes-builder Makefile is here | ||
# else rely on current checkout branch | ||
if [ -e "$BUILDERDIR/Makefile" ]; then | ||
BRANCH="$(make -C ../../ -s get-var GET_VAR=BRANCH_linux_kernel 2>/dev/null)" | ||
else | ||
BRANCH="$(git rev-parse --abbrev-ref HEAD)" | ||
fi | ||
fi | ||
|
||
# Filter allowed branches | ||
if [[ ! "$BRANCH" =~ ^stable-[0-9]+\.[0-9]+$ ]] && [ "$BRANCH" != "master" ]; then | ||
echo "Cannot determine kernel branch to use." | ||
exit 1 | ||
fi | ||
|
||
LATEST_KERNEL_VERSION="$(python3 "$LOCALDIR/kernel-updater.py" --check-update --version "$VERSION" --branch "$BRANCH")" | ||
|
||
if [ "x$LATEST_KERNEL_VERSION" == "x" ]; then | ||
echo "Current kernel version in branch ${BRANCH} is up to date" | ||
exit 0 | ||
fi | ||
|
||
# Download latest kernel | ||
echo "$LATEST_KERNEL_VERSION" > version | ||
make get-sources | ||
|
||
FC_LATEST="$(curl -s -L https://dl.fedoraproject.org/pub/fedora/linux/releases | sed -e 's/<[^>]*>//g' | awk '{print $1}' | grep -o "[1-9][0-9]" | tail -1)" | ||
STABLE_KERNEL="$(dnf -q repoquery kernel --disablerepo=* --enablerepo=fedora --enablerepo=updates --releasever="$FC_LATEST" | sort -V | tail -1 | cut -d ':' -f2 | cut -d '-' -f1)" | ||
if [ "$BRANCH" == "master" ]; then | ||
TESTING_KERNEL="$(dnf -q repoquery kernel --disablerepo=* --enablerepo=fedora --enablerepo=updates --enablerepo=updates-testing --releasever="$FC_LATEST" | sort -V | tail -1 | cut -d ':' -f2 | cut -d '-' -f1)" | ||
RAWHIDE_KERNEL="$(dnf -q repoquery kernel --disablerepo=* --enablerepo=fedora --enablerepo=updates --releasever=rawhide | grep -v "rc[0-9]*" | sort -V | tail -1 | cut -d ':' -f2 | cut -d '-' -f1 || true)" | ||
fi | ||
|
||
if distance_version "$STABLE_KERNEL" "$LATEST_KERNEL_VERSION"; then | ||
"$LOCALDIR/get-fedora-latest-config" --releasever "$FC_LATEST" | ||
mv config-base-"$STABLE_KERNEL" config-base | ||
elif [ "$BRANCH" == "master" ] && { distance_version "$TESTING_KERNEL" "$LATEST_KERNEL_VERSION"; }; then | ||
"$LOCALDIR/get-fedora-latest-config" --releasever "$FC_LATEST" --include-testing | ||
mv config-base-"$STABLE_KERNEL" config-base | ||
elif [ "$BRANCH" == "master" ] && { distance_version "$RAWHIDE_KERNEL" "$LATEST_KERNEL_VERSION"; }; then | ||
"$LOCALDIR/get-fedora-latest-config" --releasever rawhide | ||
mv config-base-"$RAWHIDE_KERNEL" config-base | ||
else | ||
echo "Cannot determine latest config for kernel ${LATEST_KERNEL_VERSION}. Use the current existing config..." | ||
fi |