mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-19 19:40:37 +02:00
simplify _kver function
This commit is contained in:
parent
7a006fbfe0
commit
22bebd4c19
1 changed files with 7 additions and 19 deletions
|
@ -160,26 +160,14 @@ _run_update_environment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_kver() {
|
_kver() {
|
||||||
# this is intentionally very loose. only ensure that we're
|
if [[ -f "${1}" ]]; then
|
||||||
# dealing with some sort of string that starts with something
|
# x86_64 default image
|
||||||
# resembling dotted decimal notation. remember that there's no
|
rg --no-heading -Noazm 1 'ABCDEF(.*)\(.*@' -r '$1' ${1} ||
|
||||||
# requirement for CONFIG_LOCALVERSION to be set.
|
# aarch64, works for compressed and uncompressed image
|
||||||
local kver re='^[[:digit:]]+(\.[[:digit:]]+)+'
|
rg --no-heading -Noazm 1 'Linux version ([0-9].*) \(.*@' -r '$1' "${1}" ||
|
||||||
local arch bytes reader
|
# riscv64, rg cannot detect compression without suffix
|
||||||
arch="${_RUNNING_ARCH}"
|
zcat "${1}" | rg -Noazm 1 'Linux version ([0-9].*) \(.*@' -r '$1'
|
||||||
if [[ $arch == @(i?86|x86_64) ]]; then
|
|
||||||
local -i offset
|
|
||||||
offset="$(od -An -j0x20E -dN2 "$1")" || return
|
|
||||||
read -r kver _ < \
|
|
||||||
<(dd if="$1" bs=1 count=127 skip=$((offset + 0x200)) 2>"${_NO_LOG}")
|
|
||||||
else
|
|
||||||
reader='cat'
|
|
||||||
bytes="$(od -An -t x2 -N2 "$1" | tr -dc '[:alnum:]')"
|
|
||||||
[[ "$bytes" == '8b1f' ]] && reader='zcat'
|
|
||||||
read -r _ _ kver _ < <($reader "$1" | rg -m1 -ao 'Linux version .(\.[-[:alnum:]+]+)+')
|
|
||||||
fi
|
fi
|
||||||
[[ "$kver" =~ $re ]] || return 1
|
|
||||||
printf '%s' "$kver"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
### check architecture
|
### check architecture
|
||||||
|
|
Loading…
Reference in a new issue