Magellan Linux

Diff of /trunk/initscripts/common/sbin/modules-update

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/unlabeled-1.1.1/magellan-initscripts/sbin/modules-update revision 2 by niro, Mon Dec 13 22:52:07 2004 UTC trunk/magellan-initscripts/sbin/modules-update revision 1278 by niro, Thu May 12 16:03:35 2011 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # vim:ts=4
3    # Distributed under the terms of the GNU General Public License v2
4  #  #
5  # This is the modules-update script for Debian GNU/Linux.  # This script will do:
6  # Written by Wichert Akkerman <wakkerma@debian.org>  #  - create /etc/modules.conf from /etc/modules.d/*
7  # Copyright (C) 1998, 1999 Software in the Public Interest  #  - create /etc/modprobe.conf from /etc/modprobe.d/*
8    #  - update modules.dep if modules.conf has been updated so depmod doesnt whine
9  # Modifications by Daniel Robbins <drobbins@gentoo.org>, Gentoo Technologies, Inc.  #
10  # 02 Sep 2001 -- Removed "arch" stuff since I see no reason to have support for varying  # This is all for backwards compatibility.  In the perfect world, we would be
11  # CPU architectures on a single system.  # running a linux-2.6 kernel and not have any modules.d directory.  Then there
12    # would be no work for us as module-init-tools automatically scans modprobe.d.
13  # More Modifications by Niels Rogalla <niro@magellan-linux.net> for Megallan Linux  # Until that happens, we'll keep scanning and warning and being a pita.
14  # Hacked some entries to fit into Magellan:  #
15  # functions.sh & kernel-2.5 stuff not needed  
   
 # 06.09.2004 Added kernel 2.6 stuff <niro@magellan-linux.net>  
   
 CFGFILE="/etc/modules.conf"  
 TMPFILE="${CFGFILE}.$$"  
 CFGFILE2="/etc/modprobe.conf"  
 TMPFILE2="${CFGFILE2}.$$"  
 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"  
16    
17  #source /sbin/functions.sh  MROOT="${MROOT%/}/"
18  source /etc/init.d/functions  [ "${MROOT}" = "${MROOT#/}" ] && MROOT="${PWD}/${MROOT}"
19    cd "${MROOT}"
20    
21    argv0=${0##*/}
22    . /etc/init.d/functions || {
23     echo "${argv0}: Could not source /etc/init.d/functions!" 1>&2
24     exit 1
25    }
26    umask 022
27    esyslog() { :; }
28    export PATH=/sbin:${PATH}
29    
30  KERNEL_2_5="no"  #
31    # Setup some variables
32    #
33    
34  #if [ "$(get_KV)" -ge "$(KV_to_int '2.5.48')" ]  HEADER="### This file is automatically generated by modules-update"
35  #then  HEADER_OLD="### This file is automatically generated by update-modules"
36  # KERNEL_2_5="yes"  VERSION="1.5"
 #fi  
37    
38  #needed for kernel 2.6  #
39  if [ "$(kernel_major_version)" == "2.6" ]  # Parse command-line
40  then  #
41   KERNEL_2_5="yes"  
42    VERBOSE=0
43    DEBUG=0
44    FORCE="false"
45    BACKUP="false"
46    KV=
47    while [ -n "$1" ] ; do
48     case $1 in
49     --assume-kernel=*) KV=${1#*=};;
50     -b|--backup)       BACKUP="true";;
51     -f|--force|force)  FORCE="true";;
52     -v|--verbose)      ((VERBOSE+=1));;
53     -d|--debug)        ((DEBUG+=1));;
54     -V|--version)      exec echo "${argv0}: ${VERSION}";;
55     -h|--help)
56     cat <<-EOF
57     Usage: modules-update [options]
58    
59     Options:
60     --assume-kernel=KV  Assume the kernel is at least version KV
61     -b, --backup        Backup existing config files (add .old ext)
62     -f, --force         Force execution in face of bad things
63     -v, --verbose       Be a bit more verbose in what we do
64     -d, --debug         Helpful debug output
65     -V, --version       Dump version info
66     -h, --help          This help screen, duh
67     EOF
68     exit 0
69     ;;
70     *)
71     echo "Error: I don't understand $1"
72     exit 1
73     ;;
74     esac
75     shift
76    done
77    
78    if [ ! -w ./etc ] ; then
79     echo "You must be root to do this"
80     exit 2
81  fi  fi
82    
83    [ ${DEBUG} -gt 0 ] && set -x
84    
85  set -e  veinfo() { [ ${VERBOSE} -gt 0 ] && echo "$*" ; return 0 ; }
86    vewarn() { [ ${VERBOSE} -gt 0 ] && echo "$*" ; return 0 ; }
87    
88  # Reset the sorting order since we depend on it  [ "${MROOT}" != "/" ] && veinfo "Operating on MROOT = '${MROOT}'"
 export LC_COLLATE="C"  
89    
90  depdir() {  #
91   dep="`egrep '[[:space:]]*depfile' ${CFGFILE} | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,'`"  # Let's check the optimal case first: nothing to do
92   if [ -z "${dep}" ]  #
93   then  if ! ${FORCE} ; then
94      dep="/lib/modules/$(uname -r)"   if [ ! -d "./etc/modules.d" ] ; then
95   fi   if [ ! -d "./etc/modprobe.d" ] ; then
96     veinfo "No /etc/modules.d or /etc/modprobe.d dir; Nothing to do!"
97     exit 0
98    
99   echo "${dep}"   elif [ -e "./etc/modprobe.conf" ] ; then
100  }   vewarn "You should put settings in /etc/modprobe.d/ rather than modprobe.conf"
101    
102  CFGFILES="${CFGFILE}"   elif [ -e "./etc/modules.conf" ] ; then
103     vewarn "If you only run linux-2.4, you should delete /etc/modules.conf"
104    
105  if [ "${KERNEL_2_5}" = "yes" ]   else
106  then   veinfo "We have just /etc/modprobe.d; Nothing to do!"
107   CFGFILES="${CFGFILES} ${CFGFILE2} ${CFGFILE4}"   exit 0
108     fi
109     else
110     vewarn "You have /etc/modules.d, so things need to get coalesced"
111     fi
112  fi  fi
113    
114  for x in ${CFGFILES}  #
115  do  # Build list of config files to generate and verify none
116   if [ -f "${x}" ]  # have been modified in any way
117   then  #
118   if ! sed -ne 1p "${x}" | egrep -q "^${HEADER}"  for x in modprobe.conf modules.conf ; do
119   then   x="./etc/${x}"
120   echo "Error: the current ${x} is not automatically generated."   [ -r ${x} ] || continue
121    
122   if [ "$1" != "force" ]   _header="$(sed -ne 1p ${x})"
123   then   if [ "${_header}" != "${HEADER}" ] && [ "${_header}" != "${HEADER_OLD}" ]; then
124   echo "Use \"modules-update force\" to force (re)generation."   echo "Warning: ${x#.} has not been automatically generated"
125   exit 1  
126   else   if ${FORCE} ; then
127   echo "force specified, (re)generating file anyway."   echo "--force specified, (re)generating file anyway"
128   fi   else
129     echo "Use \"modules-update force\" to force (re)generation"
130     exit 1
131   fi   fi
132   fi   fi
133  done  done
134    
 if [ 0 -ne "`id -u`" ]  
 then  
  echo "You have to be root to do this."  
  exit 2  
 fi  
135    
136  if [ -e "${CFGFILE}" ]  #
137    # If the system doesnt have old modutils, then this is prob linux-2.6 only
138    #
139    if type -P modprobe.old > /dev/null || \
140       LC_ALL=C modprobe -V 2>/dev/null | grep -qs "modprobe version"
141  then  then
142   cp -f "${CFGFILE}" "${CFGFILE}".old   GENERATE_OLD="true"
143    else
144     GENERATE_OLD="false"
145  fi  fi
146  if [ "${KERNEL_2_5}" = "yes" ]  
147  then  
148   if [ -e "${CFGFILE2}" ]  # Reset the sorting order since we depend on it
149   then  export LC_COLLATE="C"
150   cp -f "${CFGFILE2}" "${CFGFILE2}".old  
151   fi  KV=${KV:-$(uname -r)}
152   if [ -e "${CFGFILE4}" ]  
153   then  
154   cp -f "${CFGFILE4}" "${CFGFILE4}".old  #
155    #  Desc: backup a config file if need be and replace with new one
156    # Usage: backup <old config file to backup> <new config file to replace with>
157    #    Ex: backup /etc/modules.conf /etc/modules.conf.tempfile
158    #
159    backup() {
160     if ${BACKUP} && [ -e "$1" ] ; then
161     mv -f "$1" "$1".old
162   fi   fi
163  fi   mv -f "$2" "$1"
164    }
165    
166    
167    #
168    #  Desc: Create module header
169    # Usage: create_header <config dir>
170    #    Ex: create_header /etc/modules.d
171    create_header() {
172     local moddir=$1
173    
174     cat <<-EOF
175     ${HEADER}
176     #
177     # Please do not edit this file directly. If you want to change or add
178     # anything please take a look at the files in ${moddir} and read
179     # the manpage for modules-update(8).
180     #
181     EOF
182    }
183    
184    
 echo "${HEADER}" > "${TMPFILE}"  
 cat <<EOF >> "${TMPFILE}"  
185  #  #
186  # Please do not edit this file directly. If you want to change or add  #  Desc: Combine all config files in a dir and place output in a file
187  # anything please take a look at the files in ${MODDIR} and read  # Usage: generate_config <output config file> <config dir> <reference config dir> <silent>
188  # the manpage for modules-update.  #    Ex: generate_config /etc/modules.conf /etc/modules.d
189  #  #
190  EOF  generate_config() {
191  if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "yes" ]   local config=$1
192  then   local moddir=$2
193   sed -e "s:the files in ${MODDIR}:${CFGFILE}:" \   local refdir=$3
194   "${TMPFILE}" > "${TMPFILE2}"   local silent=$4
195     local tmpfile="${config}.$$"
196    
197     [ -z "${silent}" ] && echo "Updating ${config#./etc/}"
198    
199     create_header ${refdir:-${moddir}} > "${tmpfile}"
200    
201     for cfg in "${moddir}"/* ; do
202     [ -d "${cfg}" ] && continue
203     [ ! -r "${cfg}" ] && continue
204    
205     # Skip backup and RCS files #20597
206     case ${cfg} in *~|*.bak|*,v) continue;; esac
207    
208     # If config file is found in the reference dir, then skip it
209     [ -n "${refdir}" ] && [ -e "${refdir}/${cfg##*/}" ] && continue
210    
211     (
212     echo "### modules-update: start processing ${cfg#.}"
213     if [ -x "${cfg}" ] ; then
214     # $cfg can be executable; nice touch, Wichert! :)
215     "${cfg}"
216     else
217     cat "${cfg}"
218     fi
219     echo
220     echo "### modules-update: end processing ${cfg#.}"
221     echo
222     ) >> "${tmpfile}"
223     done
224    
225   if [ -f "${CFGFILE3}" ]   backup "${config}" "${tmpfile}"
226   then  
227   sed -e "s:the files in ${MODDIR}:${CFGFILE3}:" \   return 0
228   "${TMPFILE}" > "${TMPFILE4}"  }
229   fi  
230    
231    #
232    # Generate the old modules.conf file based upon all the snippets in
233    # modules.d.  Since modprobe doesnt handle modules.d, we need to gather
234    # the files together in modules.conf for it.
235    #
236    
237    if [ ! -d "./etc/modules.d" ] ; then
238     veinfo "No need to generate modules.conf :)"
239    
240    elif ${FORCE} || is_older_than ./etc/modules.conf ./etc/modules.d ; then
241     generate_config ./etc/modules.conf ./etc/modules.d
242    
243    else
244     veinfo "modules.conf: already up-to-date wheatness"
245  fi  fi
246    
247  for cfg in "${MODDIR}"/* "${CONF}"  #
248  do  # Call depmod to keep insmod from complaining that modules.conf is more
249   [ -d "${cfg}" ] && continue  # recent then the modules.dep file.
250    #
251   [ ! -r "${cfg}" ] && continue  if [ -e "./etc/modules.conf" ] ; then
252     depfile=$(
253   [ -n "`echo "${cfg}" | awk '!/~$|\.bak$/ { print $0 }'`" ] || continue   # the modules.conf file has optional syntax:
254     # depfile=/path/to/modules.dep
255   echo "### modules-update: start processing ${cfg}" >> "${TMPFILE}"   ret=$(sed -n -e '/^[[:space:]]*depfile=/s:.*=::p' ./etc/modules.conf)
256     eval echo "${ret:-/lib/modules/${KV}/modules.dep}"
257   if [ -x ${cfg} ]   )
258   then  
259   # $cfg can be executable; nice touch, Wichert! :)   if [ -d "${depfile%/*}" ] ; then
260   "${cfg}" >> "${TMPFILE}"   if [ ./etc/modules.conf -nt "${depfile}" ] ; then
261     arch=$(uname -m)
262     echo "Updating modules.dep"
263     for cfg in /lib/modules/${KV}/build /usr/src/linux-${KV} \
264               /lib/modules/${KV} /boot /usr/src/linux ""
265     do
266     cfg=".${cfg}/System.map"
267     for suffix in -genkernel-${arch}-${KV} -genkernel-'*'-${KV} -${KV} "" ; do
268     scfg=$(echo ${cfg}${suffix})
269     scfg=${scfg%% *}
270     [ -f "${scfg}" ] && cfg=${scfg} && break 2
271     done
272     cfg=""
273     done
274     [ -n "${cfg}" ] && cfg="-F ${cfg}"
275     depmod -b "${ROOT}" -a ${cfg} ${KV}
276     veinfo "Ran: depmod -b '${ROOT}' -a ${cfg} ${KV}"
277     else
278     veinfo "modules.dep: already up-to-date goodness"
279     fi
280   else   else
281   cat "${cfg}" >> "${TMPFILE}"   vewarn "The dir '${depfile}' does not exist, skipping call to depmod"
282   fi   fi
283    fi
  echo >> "${TMPFILE}"  
  echo "### modules-update: end processing ${cfg}" >> "${TMPFILE}"  
  echo >> "${TMPFILE}"  
 done  
284    
 mv -f "${TMPFILE}" "${CFGFILE}"  
285    
286  if [ -x /sbin/generate-modprobe.conf -a "${KERNEL_2_5}" = "yes" ]  #
287  then  # Generate the new modprobe.conf file if possible.  What this entails is
288   if /sbin/generate-modprobe.conf >> "${TMPFILE2}" 2> /dev/null  # grabbing details from the old modprobe via the -c option and sticking
289   then  # it in the newer config file.  This is useful for backwards compat support
290   mv -f "${TMPFILE2}" "${CFGFILE2}"  # and for packages that provide older style /etc/modules.d/ files but not
291   else  # newer style /etc/modprobe.d/ files.
292   echo "Warning: could not generate ${CFGFILE2}!"  #
293   rm -f "${TMPFILE2}"  # First we try to use the script `generate-modprobe.conf` from the
294   fi  # module-init-tools and if that fails us, we try and generate modprobe.conf
295    # ourselves from the /etc/modules.d/ files.
296    #
297    if ! type -P generate-modprobe.conf > /dev/null ; then
298     vewarn "Skipping /etc/modprobe.conf generation (generate-modprobe.conf doesn't exist)"
299    
300    elif ! ${FORCE} && ! is_older_than ./etc/modprobe.conf ./etc/modules.d ./etc/modprobe.d ; then
301     veinfo "modprobe.conf: already up-to-date nutness"
302    
303    elif [ ! -e ./etc/modules.conf -a ! -e ./etc/modules.d ] ; then
304     veinfo "No need to generate modprobe.conf :)"
305     rm -f ./etc/modprobe.conf
306    
307    else
308     #
309     # First, bitch like crazy
310     #
311     for f in ./etc/modules.d/* ; do
312     # hack: ignore baselayout ;x
313     case ${f##*/} in
314     aliases|i386) continue;;
315     esac
316     [ -e "${f}" ] || continue
317     if [ ! -e "./etc/modprobe.d/${f##*/}" ] ; then
318     echo "Please file a bug about ${f#.}: it needs an /etc/modprobe.d/${f##*/}"
319     fi
320     done
321    
322     generated_ok=0
323     tmpfile="./etc/modprobe.conf.$$"
324    
325   if [ -f "${CFGFILE3}" ]   #
326   then   # First we try to use regular generate-modprobe.conf
327   gawk '$0 !~ /^[[:space:]]*include/ { print $0 }' "${CFGFILE3}" > "${TMPFILE3}"   #
328     if ${GENERATE_OLD} ; then
329   export TESTING_MODPROBE_CONF="${TMPFILE3}"   echo "Updating modprobe.conf"
330   if /sbin/generate-modprobe.conf >> "${TMPFILE4}" 2> /dev/null   create_header /etc/modprobe.d > "${tmpfile}"
331     if generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
332       >> "${tmpfile}" 2> "${tmpfile}.err"
333   then   then
334   mv -f "${TMPFILE4}" "${CFGFILE4}"   backup "./etc/modprobe.conf" "${tmpfile}"
335     generated_ok=1
336     else
337     [[ ${VERBOSE} -gt 0 ]] && cat "${tmpfile}.err"
338     echo "Warning: could not generate /etc/modprobe.conf!"
339     fi
340     fi
341    
342   echo >> "${CFGFILE4}"   #
343   echo "include /etc/modprobe.conf" >> "${CFGFILE4}"   # If the helper script failed, we fall back to doing it by hand
344     #
345     if [[ ${generated_ok} -eq 0 ]] ; then
346     echo "Updating modprobe.conf by hand"
347    
348     generate_config ./etc/modprobe.conf ./etc/modules.d ./etc/modprobe.d 0
349     create_header /etc/modprobe.d > "${tmpfile}"
350    
351     # Just use generate-modprobe.conf to filter compatible syntax
352     if TESTING_MODPROBE_CONF=./etc/modprobe.conf \
353       generate-modprobe.conf ${ASSUME_KV:+--assume-kernel=${KV}} \
354       >> "${tmpfile}" 2> "${tmpfile}.err"
355     then
356     # we use mv here instead of backup_config() as the call to
357     # generate_config() above already took care of the backup
358     mv -f "${tmpfile}" "./etc/modprobe.conf"
359   else   else
360   echo "Warning: could not generate ${CFGFILE4}!"   [[ ${VERBOSE} -gt 0 ]] && cat "${tmpfile}.err"
361   rm -f "${TMPFILE4}"   echo "Warning: could not generate /etc/modprobe.conf!"
362   fi   fi
  rm -f "${TMPFILE3}"  
363   fi   fi
 fi  
364    
365  # We also call depmod here to stop insmod from complaining that modules.conf   #
366  # is more recent then modules.dep   # Now append all the new files ... modprobe will not scan /etc/modprobe.d/
367  #   # if /etc/modprobe.conf exists, so we need to append /etc/modprobe.conf with
368  if [ -d "`depdir`" -a -f /proc/modules ]   # /etc/modprobe.d/* ... http://bugs.gentoo.org/145962
369  then   #
370   depmod -a   if [[ -e ./etc/modprobe.conf ]] ; then
371  fi   for cfg in ./etc/modprobe.d/* ; do
372     [ -d "${cfg}" ] && continue
373     [ ! -r "${cfg}" ] && continue
374    
375     # Skip backup and RCS files #20597
376     case ${cfg} in *~|*.bak|*,v) continue;; esac
377    
378     (
379     echo
380     echo "### modules-update: start processing ${cfg#.}"
381     cat "${cfg}"
382     echo "### modules-update: end processing ${cfg#.}"
383     ) >> "./etc/modprobe.conf"
384     done
385     fi
386    
387     rm -f "${tmpfile}" "${tmpfile}.err"
388    fi
389    
390  # vim:ts=4  : # make sure we fall through with 0 exit status

Legend:
Removed from v.2  
changed lines
  Added in v.1278