--- trunk/magellan-initscripts/sbin/modules-update 2005/10/21 15:24:25 275 +++ trunk/magellan-initscripts/sbin/modules-update 2005/10/21 15:24:54 276 @@ -3,21 +3,24 @@ # 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 -# Modifications by Daniel Robbins , Gentoo Technologies, Inc. -# 02 Sep 2001 -- Removed "arch" stuff since I see no reason to have support for varying -# CPU architectures on a single system. - -# More modifications by Niels Rogalla for Magellan-Linux -# Hacked some entries to fit into Magellan: -# functions.sh & kernel-2.5 stuff not needed - -# 06.09.2004 Added kernel 2.6 stuff +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" @@ -25,17 +28,45 @@ 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 -KERNEL_2_5="no" +# 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" ] +if [[ $(kernel_major_version) = 2.6 ]] then - KERNEL_2_5="yes" + KERNEL_2_6=true +else + KERNEL_2_6=false fi +# Check if $CONF is valid +[[ ! -r ${CONF} ]] && CONF= set -e @@ -43,144 +74,164 @@ export LC_COLLATE="C" depdir() { - dep="`egrep '[[:space:]]*depfile' ${CFGFILE} | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,'`" - if [ -z "${dep}" ] - then - dep="/lib/modules/$(uname -r)" - fi - + 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_5}" = "yes" ] -then - CFGFILES="${CFGFILES} ${CFGFILE2} ${CFGFILE4}" +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 +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 [ "$1" != "force" ] - then + if $FORCE ; then + echo "force specified, (re)generating file anyway." + else echo "Use \"modules-update force\" to force (re)generation." exit 1 - else - echo "force specified, (re)generating file anyway." fi fi fi done -if [ 0 -ne "`id -u`" ] -then - echo "You have to be root to do this." - exit 2 -fi - -if [ -e "${CFGFILE}" ] -then - cp -f "${CFGFILE}" "${CFGFILE}".old -fi -if [ "${KERNEL_2_5}" = "yes" ] -then - if [ -e "${CFGFILE2}" ] - then - cp -f "${CFGFILE2}" "${CFGFILE2}".old - fi - if [ -e "${CFGFILE4}" ] - then - cp -f "${CFGFILE4}" "${CFGFILE4}".old - fi -fi +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 -echo "${HEADER}" > "${TMPFILE}" -cat <> "${TMPFILE}" -# -# 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. -# -EOF -if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "yes" ] -then - sed -e "s:the files in ${MODDIR}:${CFGFILE}:" \ - "${TMPFILE}" > "${TMPFILE2}" + return 0 +} - if [ -f "${CFGFILE3}" ] - then - sed -e "s:the files in ${MODDIR}:${CFGFILE3}:" \ - "${TMPFILE}" > "${TMPFILE4}" +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 -for cfg in "${MODDIR}"/* "${CONF}" -do - [ -d "${cfg}" ] && continue - - [ ! -r "${cfg}" ] && continue - - [ -n "`echo "${cfg}" | awk '!/~$|\.bak$/ { print $0 }'`" ] || 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 - -mv -f "${TMPFILE}" "${CFGFILE}" - -if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "yes" ] -then - if /sbin/generate-modprobe.conf >> "${TMPFILE2}" 2> /dev/null - then - mv -f "${TMPFILE2}" "${CFGFILE2}" - else - echo "Warning: could not generate ${CFGFILE2}!" - rm -f "${TMPFILE2}" - fi - - if [ -f "${CFGFILE3}" ] - then - gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" > "${TMPFILE3}" +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 - export TESTING_MODPROBE_CONF="${TMPFILE3}" - if /sbin/generate-modprobe.conf >> "${TMPFILE4}" 2> /dev/null + 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 - mv -f "${TMPFILE4}" "${CFGFILE4}" - - echo >> "${CFGFILE4}" - echo "include /etc/modprobe.conf" >> "${CFGFILE4}" + [[ -e ${CFGFILE2} ]] && mv -f "${CFGFILE2}" "${CFGFILE2}.old" + mv -f "${TMPFILE2}" "${CFGFILE2}" else - echo "Warning: could not generate ${CFGFILE4}!" - rm -f "${TMPFILE4}" + # + # 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 - rm -f "${TMPFILE3}" fi fi # We also call depmod here to stop insmod from complaining that modules.conf # is more recent then modules.dep -# -if [ -d "`depdir`" -a -f /proc/modules ] -then - depmod -a +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