Skip to content

Commit

Permalink
Manage Kernels (#119)
Browse files Browse the repository at this point in the history
Implement the script to deal with Debian's 6.1.0-(29|30) kernel problem
  • Loading branch information
jxmx authored Jan 22, 2025
1 parent 7cbbbea commit 770fc47
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 1 deletion.
125 changes: 125 additions & 0 deletions bin/asl-kernel-manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/bash
#
# This script is used to manage the kernel and the APT structure
# for ASL3-related systems. It is both platform dependent (Pi vs. not Pi)
# and Debian release dependent (12, 13, etc.)

if [ ${UID} != 0 ]; then
echo "$0 only runs as root"
exit 1
fi

DEBIAN_MAJ_VERSION=$(awk -F '\\.' '{print $1}' /etc/debian_version)

#
# Do Debian 12 fixes
#
function debian_12(){

# Is this a Pi?
is_rpi=$(grep Raspberry /proc/cpuinfo | wc -l)

# Determine the linux-image and linux-headers
if [ ${is_rpi} -gt 0 ]; then
KERN_META_PKG=linux-image-rpi-v8
NEEDS_BACKPORTS=0
else
NEEDS_BACKPORTS=1
case $(uname -m) in
x86_64)
KERN_META_PKG=linux-image-amd64
;;
aarch64)
KERN_META_PKG=linux-image-arm64
;;
esac

# check if it's a "cloud" kernel
if `uname -a | grep -q cloud`; then
KERN_META_PKG=$(echo ${KERN_META_PKG} | sed 's/image/image-cloud/g')
fi
fi
KERN_META_PKG_HEADS=$(echo ${KERN_META_PKG} | sed 's/image/headers/g')

# Pretty-print
echo ""
echo " Debian Version: ${1}"
echo " Architecture: $(uname -m)"
echo " Kernel Package: ${KERN_META_PKG}"
echo " Kernel Headers Package: ${KERN_META_PKG_HEADS}"
echo ""

# Remediate if needing a backport
if [ ${NEEDS_BACKPORTS} -eq 1 ]; then

# Check to see if Debian 12 is already remediated
if [ -f /etc/asl-kernel-manager/d12-6.1.0-broken ]; then
echo ""
echo "Task d12-6.1.0-broken already completed; no action"
echo ""
exit 0
fi

# Enable bookworm-backports
echo " Enabling bookworm-backports for this system"
remove_marked_kernels
enable_bookworm_backports
set_semaphore
echo ""
echo " This system requires a reboot"
echo ""
wall "asl-kernel-manager needs to reboot the system in 60 seconds"
shutdown -r
exit 0

else
echo " Not enabling backports for this system"
echo ""
exit 0
fi
}

function enable_bookworm_backports() {

cat - > /etc/apt/sources.list.d/asl3-debian-bookworm-backports.list <<EOF
#
# Enable Bookworm Backports for ASL3
#
deb http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
EOF

DEBIAN_FRONTEND=noninteractive apt update
DEBIAN_FRONTEND=noninteractive \
apt upgrade -y -t bookworm-backports $KERN_META_PKG $KERN_MEGA_PKG_HEADS

}

function remove_marked_kernels() {
HELD_KERNS=$(apt-mark showhold | grep -E '^linux\-(headers|image)')
if [ ! -z "${HELD_KERNS}" ]; then
apt-mark unhold ${HELD_KERNS}
fi
}

function set_d12_610_semaphore() {
if [ ! -d /etc/asl-kernel-manager ]; then
mkdir /etc/asl-kernel-manager
fi
chmod 700 /etc/asl-kernel-manager

echo $(date +%s) > /etc/asl-kernel-manager/d12-6.1.0-broken
echo $(date --rfc-3339=seconds) >> /etc/asl-kernel-manager/d12-6.1.0-broken
}

#
# What Debian version are we on?
#
case ${DEBIAN_MAJ_VERSION} in
12)
debian_12 ${DEBIAN_MAJ_VERSION}
;;
*)
echo "This script does not support Debian ${DEBIAN_MAJ_VERSION}"
exit 1
;;
esac
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Rules-Requires-Root: binary-targets
Package: asl3
Architecture: all
Depends: ${misc:Depends}, asl3-asterisk, asl3-menu, dahdi-linux, lsb-release,
bind9-dnsutils, uuid, curl, lame, sox, whiptail, python3-serial
bind9-dnsutils, uuid, curl, lame, sox, whiptail, python3-serial, dahdi-dkms (>= 3.4.0-6)
Breaks: asl3-pi-appliance (<< 1.8.0)
Suggests: allmon3, asl3-update-nodelist
Description: AllStarLink 3
Expand Down
1 change: 1 addition & 0 deletions debian/dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
etc/asl-kernel-manager
78 changes: 78 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# postinst script for asl3
#
# see: dh_installdeb(1)

# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

set -e

function print_kernel_banner() {
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
( cat - <<EOM
Some Debian 6.1.0 kernel versions (those after 6.1.0-28) have
exhibited performance issues with OSS-based USB devices like
those used by AllStarLink.
!!! Your system is running one of the affected kernels !!!
To address this issue we recommend that your system be configured
to use Debian Bookworm-Backports to obtain the latest 6.11.0 based
kernel. The newer kernel restores proper Asterisk/app_rpt support
for AllStarLink.
When this upgrade completes, run /usr/bin/asl-kernel-manager
and reboot the system when prompted
EOM
) | fmt
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
sleep 5
}

function do_configure() {
if [ ! -f /etc/asl-kernel-manager/d12-6.1.0-broken ]; then
is_rpi=$(grep Raspberry /proc/cpuinfo | wc -l)
if [ "${is_rpi}" -eq 0 ]; then
if `dpkg --compare-versions $(uname -r) gt 6.1.0-28-amd64` &&
`dpkg --compare-versions $(uname -r) lt 6.11.0`; then
print_kernel_banner
fi
fi
fi
}

case "$1" in
configure)
do_configure
;;

abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

0 comments on commit 770fc47

Please sign in to comment.