#!/bin/bash # # ScoutFS kernel install/remove hook for DKMS # # Installed to: # /etc/kernel/postinst.d/scoutfs (Debian/Ubuntu) # /etc/kernel/postrm.d/scoutfs (Debian/Ubuntu) # # On postinst: attempts to build and install the scoutfs module for the # newly installed kernel via DKMS. On failure, logs a warning but NEVER # blocks kernel installation. # # On postrm: removes the scoutfs DKMS module for the removed kernel. # # Usage: Called by the kernel package system with the kernel version as $1 # KVER="${1:-}" LOGFILE="/var/log/scoutfs-dkms.log" if [ -z "$KVER" ]; then exit 0 fi # Determine if we're in postinst or postrm context HOOK_DIR="$(basename "$(dirname "$0")")" # Find the installed scoutfs DKMS version get_scoutfs_version() { dkms status scoutfs 2>/dev/null | head -1 | sed -n 's/^scoutfs[, ]*\([^,: ]*\).*/\1/p' } log() { local msg="$(date '+%Y-%m-%d %H:%M:%S') scoutfs-dkms: $*" echo "$msg" >> "$LOGFILE" 2>/dev/null || true logger -t scoutfs-dkms "$*" 2>/dev/null || true } SCOUTFS_VERSION="$(get_scoutfs_version)" if [ -z "$SCOUTFS_VERSION" ]; then # scoutfs-dkms not installed, nothing to do exit 0 fi case "$HOOK_DIR" in postinst.d) log "New kernel ${KVER} detected, attempting DKMS build..." if dkms build -m scoutfs -v "$SCOUTFS_VERSION" -k "$KVER" >> "$LOGFILE" 2>&1; then if dkms install -m scoutfs -v "$SCOUTFS_VERSION" -k "$KVER" >> "$LOGFILE" 2>&1; then log "SUCCESS: ScoutFS module ${SCOUTFS_VERSION} built and installed for kernel ${KVER}" else log "WARNING: ScoutFS module ${SCOUTFS_VERSION} built but failed to install for kernel ${KVER}" fi else log "WARNING: ScoutFS module ${SCOUTFS_VERSION} failed to build for kernel ${KVER}. The scoutfs filesystem will not be available with this kernel." fi ;; postrm.d) if dkms status scoutfs/"$SCOUTFS_VERSION" -k "$KVER" 2>/dev/null | grep -q "$KVER"; then dkms remove -m scoutfs -v "$SCOUTFS_VERSION" -k "$KVER" >> "$LOGFILE" 2>&1 || true log "Removed ScoutFS module ${SCOUTFS_VERSION} for kernel ${KVER}" fi ;; esac # NEVER block kernel installation/removal exit 0