c0247969695e2bdb0d2ab9f13516432824eff05f
[automated-distro-installer] / fai / config / distro-install-common / install-stable-kernel-debs
1 #!/bin/bash -x
2 # This file is part of Ian Kelling's automated-distro-installer
3 # Copyright (C) 2024 Ian Kelling
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 set -eE -o pipefail
20 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
21
22 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
23
24 tmpdir=$(mktemp -d) || exit
25 trap 'cd; rm -rf "$tmpdir"' EXIT
26 cd $tmpdir
27
28 # update stable_ver when we are ready to jump to a new stable kernel.
29 # Stable kernels are listed here: https://www.kernel.org/category/releases.html
30 stable_ver='6\.6'
31 va=$(curl -s https://kernel.ubuntu.com/mainline/ | \
32 sed -rn 's,.*alt="\[DIR\]".*href="([^/]+).*,\1,p' | \
33 grep -v -- -rc | sed 's/^v//' | grep "^$stable_ver" | sort -V | tail -n1)
34
35 # note the wiki page about these says to install linux-headers.*generic.*amd64, but
36 # as of 2024, they have a requirement of a very new glibc, and people report
37 # that installing it is not needed.
38 tmpstr=$(curl -s https://kernel.ubuntu.com/mainline/v$va/amd64/CHECKSUMS | awk '$2 ~ /^linux-/ { print $2 }' | sort -u | grep -iv 'linux-headers.*generic.*amd64' )
39 mapfile -t pkgs <<<"$tmpstr"
40
41 if (( ${#pkgs[@]} != 3 )); then
42 echo "$0: error. expected to find 3 kernel packages, got: ${pkgs[*]}" >&2
43 exit 1
44 fi
45
46 urls=()
47 for p in ${pkgs[@]}; do
48 if ! dpkg -s -- "${p%%_*}" 2>&1 | grep -Fx "Status: install ok installed" &>/dev/null; then
49 urls+=(https://kernel.ubuntu.com/mainline/v$va/amd64/$p)
50 fi
51 done
52 if (( ${#urls[@]} >= 1 )); then
53 wget "${urls[@]}"
54 dpkg -i ./*.deb
55 fi