static usb ethnet addresses
[automated-distro-installer] / fai / config / distro-install-common / install-stable-kernel-debs
1 #!/bin/bash
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 set -x
25
26 prereqs=()
27 for p in wget curl; do
28 if ! type -p $p &>/dev/null; then
29 prereqs+=($p)
30 fi
31 done
32 if (( ${#prereqs[@]} >= 1 )); then
33 apt-get -y install ${prereqs[@]}
34 fi
35
36
37 tmpdir=$($ROOTCMD mktemp -d) || exit
38 outertmp=$target/$tmpdir
39 trap 'cd; rm -rf "$outertmp"' EXIT
40 cd $outertmp
41
42 # update stable_ver when we are ready to jump to a new stable kernel.
43 # Stable kernels are listed here: https://www.kernel.org/category/releases.html
44 stable_ver='6\.6'
45 # Actually, I dont want stable right now. comment this out to get stable
46 # version.
47 stable_ver='[1-9]'
48 va=$(curl -s https://kernel.ubuntu.com/mainline/ | \
49 sed -rn 's,.*alt="\[DIR\]".*href="([^/]+).*,\1,p' | \
50 grep -v -- -rc | sed 's/^v//' | grep "^$stable_ver" | sort -V | tail -n1)
51
52 # note the wiki page about these says to install linux-headers.*generic.*amd64, but
53 # as of 2024, they have a requirement of a very new glibc, and people report
54 # that installing it is not needed.
55 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' )
56 mapfile -t pkgs <<<"$tmpstr"
57
58 if (( ${#pkgs[@]} != 3 )); then
59 echo "$0: error. expected to find 3 kernel packages, got: ${pkgs[*]}" >&2
60 exit 1
61 fi
62
63 urls=()
64 for p in ${pkgs[@]}; do
65 if ! $ROOTCMD dpkg -s -- "${p%%_*}" 2>&1 | grep -Fx "Status: install ok installed" &>/dev/null; then
66 urls+=(https://kernel.ubuntu.com/mainline/v$va/amd64/$p)
67 fi
68 done
69 if (( ${#urls[@]} >= 1 )); then
70 wget -nv "${urls[@]}"
71 $ROOTCMD dpkg -i ${pkgs[@]/#/$tmpdir/}
72 fi