-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
quiz-lib
80 lines (70 loc) · 2.27 KB
/
quiz-lib
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
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (c) 2023, Rob Norris <robn@despairlabs.com>
#
# Linux source version numbers (the tarball version) don't always match their
# installed version number (module dir version, uname -a output), eg:
#
# source installed
# 6.9-rc1 6.9.0-rc1
# 6.9 6.9.0
# 6.9.1 6.9.1
#
# we allow any form. internally, we'll set up variables for the "version"
# (installed) and "source version" (source), and also vars for all the pieces
#
# separate function for the pre-cooked parse; used by quiz-prepare-kernel
# to request "latest in series"
function _quiz_kernel_vars () {
local kver=$1
_quiz_kver=""
_quiz_ksrcver=""
_quiz_kmajor=""
_quiz_kminor=""
_quiz_kpatch=""
_quiz_ktype=""
_quiz_ktype_patch=""
shopt -s lastpipe
echo $kver | perl -nE '
($maj, $min, $pat, $ty, $typat) = m/
^
([1-9][0-9]*) # major
\. # dot sep
(0|[1-9][0-9]*) # minor
(?:\.(0|[1-9][0-9]*))? # patch 1+, optional
(?:-(rc)([1-9][0-9]*))? # type & typepatch
$
/gx;
print qq{$maj $min $pat $ty $typat}
' | read _quiz_kmajor _quiz_kminor _quiz_kpatch _quiz_ktype _quiz_ktype_patch
return 0
}
function quiz_kernel_vars () {
local kver="${1:-}"
if [[ -z $kver ]] ; then
fail "no kernel version set. use -k or set QUIZ_KERNEL_VERSION"
fi
_quiz_kernel_vars $kver
if [[ -z $_quiz_kmajor || -z $_quiz_kminor ]] ; then
fail "'$kver' is not a valid kernel version"
fi
if [[ -z $_quiz_kpatch ]] ; then
_quiz_kpatch="0"
fi
if [[ -z $_quiz_ktype ]] ; then
_quiz_ktype='release'
_quiz_ksrcver=$_quiz_kmajor.$_quiz_kminor
_quiz_kver=$_quiz_ksrcver
if [[ "$_quiz_kpatch" = "0" ]] ; then
_quiz_kver="$_quiz_kver.0"
else
_quiz_kver="$_quiz_kver.$_quiz_kpatch"
_quiz_ksrcver="$_quiz_ksrcver.$_quiz_kpatch"
fi
elif [[ $_quiz_ktype == "rc" ]] ; then
_quiz_kver=$_quiz_kmajor.$_quiz_kminor.0-$_quiz_ktype$_quiz_ktype_patch
_quiz_ksrcver=$_quiz_kmajor.$_quiz_kminor-$_quiz_ktype$_quiz_ktype_patch
fi
}