#!/bin/bash # # This is the modules-update script for Debian GNU/Linux. # Written by Wichert Akkerman # Copyright (C) 1998, 1999 Software in the Public Interest # # Modifications by Daniel Robbins , Gentoo Foundation # 02 Sep 2001 -- Removed "arch" stuff since I see no reason to have # support for varying CPU architectures on a single system. # # Updated by Aron Griffis # 05 May 2004 -- handle --assume-kernel argument for livecd building if [[ 0 -ne $(id -u) ]] ; then echo "You have to be root to do this." exit 2 fi CFGFILE="/etc/modules.conf" TMPFILE="${CFGFILE}.$$" CFGFILE2="/etc/modprobe.conf" TMPFILE2="${CFGFILE2}.$$" TMPFILE2B="${CFGFILE2}B.$$" CFGFILE3="/etc/modules.devfs" TMPFILE3="${CFGFILE3}.$$" CFGFILE4="/etc/modprobe.devfs" TMPFILE4="${CFGFILE4}.$$" MODDIR="/etc/modules.d" ARCHDIR="${MODDIR}/arch" HEADER="### This file is automatically generated by modules-update" FULLHEADER="${HEADER} # # Please do not edit this file directly. If you want to change or add # anything please take a look at the files in ${MODDIR} and read # the manpage for modules-update(8). # " source /etc/init.d/functions # Parse command-line FORCE=false ASSUME_KV= while [[ -n $1 ]] ; do case "$1" in force) FORCE=true ;; --assume-kernel=*) ASSUME_KV=${1#*=} ;; *) echo "Error: I don't understand $1" exit 1 ;; esac shift done # Set kernel version, either from --assume-kernel or uname -r KV=${ASSUME_KV:-$(uname -r)} # needed for kernel 2.6 if [[ $(kernel_major_version) = 2.6 ]] then KERNEL_2_6=true else KERNEL_2_6=false fi # Check if $CONF is valid [[ ! -r ${CONF} ]] && CONF= set -e # Reset the sorting order since we depend on it export LC_COLLATE="C" depdir() { dep=$(egrep '[[:space:]]*depfile' ${CFGFILE} 2> /dev/null | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,') [[ -z ${dep} ]] && dep="/lib/modules/${KV}" echo "${dep}" } CFGFILES=${CFGFILE} if ${KERNEL_2_6} ; then CFGFILES="${CFGFILES} ${CFGFILE2}" [[ -d /etc/devfs.d ]] && CFGFILES="${CFGFILES} ${CFGFILE4}" fi for x in ${CFGFILES} ; do if [[ -f ${x} ]] ; then if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}" ; then # Do not bother if its modutils config file, and we # have a 2.6 kernel without modprobe.old [[ ${x} == "${CFGFILE}" ]] && ${KERNEL_2_6} && \ ! type -p modprobe.old > /dev/null && \ continue echo "Error: the current ${x} is not automatically generated." if $FORCE ; then echo "force specified, (re)generating file anyway." else echo "Use \"modules-update force\" to force (re)generation." exit 1 fi fi fi done generate_config() { local cfg= local conf="$1" local moddir="$2" local tmpfile="$3" local do_mprobe="$4" for cfg in "${moddir}"/* "${conf}" ; do [[ -d ${cfg} ]] && continue [[ ! -r ${cfg} ]] && continue # Skip backup and RCS files; fixes bug 20597 (07 May 2004 agriffis) [[ ${cfg} == *~ || ${cfg} == *.bak || ${cfg} == *,v ]] && continue [[ ${do_mprobe} -eq 1 && -e "/etc/modprobe.d/${cfg##*/}" ]] && continue echo "### modules-update: start processing ${cfg}" >> "${tmpfile}" if [[ -x ${cfg} ]] ; then # $cfg can be executable; nice touch, Wichert! :) "${cfg}" >> "${tmpfile}" else cat "${cfg}" >> "${tmpfile}" fi echo >> "${tmpfile}" echo "### modules-update: end processing ${cfg}" >> "${tmpfile}" echo >> "${tmpfile}" done return 0 } if type -p modprobe.old > /dev/null ; then if ${FORCE} || is_older_than ${CFGFILE} ${MODDIR} || \ [[ ! -e ${CFGFILE} ]] ; then echo "Updating ${CFGFILE}" echo "${FULLHEADER}" > "${TMPFILE}" generate_config "${CONF}" "${MODDIR}" "${TMPFILE}" 0 [[ -e ${CFGFILE} ]] && mv -f "${CFGFILE}" "${CFGFILE}.old" mv -f "${TMPFILE}" "${CFGFILE}" fi fi if ${FORCE} || is_older_than ${CFGFILE2} ${MODDIR} || [[ ! -e ${CFGFILE2} ]]; then if [[ -x /sbin/generate-modprobe.conf ]] && ${KERNEL_2_6} ; then # Make sure that generate-modprobe.conf can handle --assume-kernel # if we were called with it. if [[ -n ${ASSUME_KV} ]] && \ ! grep -qe --assume-kernel /sbin/generate-modprobe.conf then echo "Error: modules-update called with --assume-kernel flag, but" echo "generate-modprobe.conf doesn't understand it. You need to" echo "install >= module-init-tools-3.0-r5" exit 3 fi echo "Updating ${CFGFILE2}" echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE2}" if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \ >> "${TMPFILE2}" 2>/dev/null then [[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old" mv -f "${TMPFILE2}" "${CFGFILE2}" else # # If we made it here, it means either generate-modprobe.conf # bombed on us, or the user doesn't have modutils installed. # If the latter is true, then we should generate modprobe.conf # ourselves with any old files laying around in /etc/modules.d. # rm -f "${TMPFILE2}" if type -p modprobe.old > /dev/null ; then echo "Warning: could not generate ${CFGFILE2}!" else echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE2B}" generate_config "${CONF}" "${MODDIR}" "${TMPFILE2}" 1 export TESTING_MODPROBE_CONF="${TMPFILE2}" if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \ >> "${TMPFILE2B}" 2> /dev/null then [[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old" mv -f "${TMPFILE2B}" "${CFGFILE2}" else echo "Warning: could not generate ${CFGFILE2}!" rm -f "${TMPFILE2B}" fi rm -f "${TMPFILE2}" fi fi if [[ -f ${CFGFILE3} ]] ; then echo "Updating ${CFGFILE4}" gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" \ > "${TMPFILE3}" echo "${FULLHEADER/modules.d/modprobe.d}" > "${TMPFILE4}" export TESTING_MODPROBE_CONF="${TMPFILE3}" if /sbin/generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \ >> "${TMPFILE4}" 2> /dev/null then [[ -e ${CFGFILE4} ]] && mv -f "${CFGFILE4}" "${CFGFILE4}.old" mv -f "${TMPFILE4}" "${CFGFILE4}" echo >> "${CFGFILE4}" echo "include /etc/modprobe.conf" >> "${CFGFILE4}" else echo "Warning: could not generate ${CFGFILE4}!" rm -f "${TMPFILE4}" fi rm -f "${TMPFILE3}" fi fi fi # We also call depmod here to stop insmod from complaining that modules.conf # is more recent then modules.dep if [[ ${CFGFILE2} -nt /lib/modules/${KV}/modules.dep ]] ; then if [[ -d $(depdir) && -f /proc/modules ]] ; then if [[ -f /usr/src/linux/System.map ]] ; then depmod -a -F /usr/src/linux/System.map ${KV} else depmod -a ${KV} fi fi fi # vim:ts=4