-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathupdate-sources
executable file
·80 lines (65 loc) · 2.98 KB
/
update-sources
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
#!/bin/bash
# vim: set ts=4 sw=4 sts=4 et :
set -e
set -o pipefail
[ "$DEBUG" = "1" ] && set -x
exit_clean() {
local exit_code=$?
if [ $exit_code -gt 0 ]; then
git checkout -- version
fi
exit "${exit_code}"
}
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"
FC_LATEST="${2//fc}"
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
if [ -z "$FC_LATEST" ]; then
FC_LATEST="$(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)"
fi
# Filter allowed branches
if [[ ! "$BRANCH" =~ ^stable-[0-9]+\.[0-9]+$ ]] && [ "$BRANCH" != "main" ]; 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 [ -z "$LATEST_KERNEL_VERSION" ]; then
echo "Current kernel version in branch ${BRANCH} is up to date"
exit 0
fi
# Download latest kernel
trap 'exit_clean' 0 1 2 3 6 15
echo "$LATEST_KERNEL_VERSION" > version
make get-sources
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" == "main" ]; 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 [ "$BRANCH" == "main" ] && { distance_version "$TESTING_KERNEL" "$LATEST_KERNEL_VERSION"; }; then
"$LOCALDIR/get-fedora-latest-config" --releasever "$FC_LATEST" --include-testing
mv config-base-"$TESTING_KERNEL" config-base
elif [ "$BRANCH" == "main" ] && { distance_version "$RAWHIDE_KERNEL" "$LATEST_KERNEL_VERSION"; }; then
"$LOCALDIR/get-fedora-latest-config" --releasever rawhide
mv config-base-"$RAWHIDE_KERNEL" config-base
elif distance_version "$STABLE_KERNEL" "$LATEST_KERNEL_VERSION"; then
"$LOCALDIR/get-fedora-latest-config" --releasever "$FC_LATEST"
mv config-base-"$STABLE_KERNEL" config-base
else
echo "Cannot determine latest config for kernel ${LATEST_KERNEL_VERSION}. Use the current existing config..."
fi