| 1 | #!/bin/sh |
| 2 | |
| 3 | # this script makes an attempt to build a proper set of rules |
| 4 | # for loading the DAHDI modules and automatically running dahdi_xcfg |
| 5 | # |
| 6 | # it accepts two parameters: |
| 7 | # the root prefix to be used for finding/creating the files |
| 8 | # the list of module names being installed |
| 9 | # |
| 10 | # the process is as follows: |
| 11 | # |
| 12 | # the file can be located at /etc/modprobe.conf (combined with all |
| 13 | # other rules), /etc/modprobe.d/dahdi (DAHDI only) or /etc/modules.d/dahdi |
| 14 | # (DAHDI only) |
| 15 | # |
| 16 | # when the file is DAHDI rules only, then we don't preserve the existing |
| 17 | # contents of the file; the system administrator can put desired options and |
| 18 | # overrides in a separate file with a name that appears earlier in the sort |
| 19 | # order, so there is no need to edit the file produced by this script |
| 20 | # |
| 21 | # when the file is combined with all other rules, then we make a backup |
| 22 | # of it and remove all the old DAHDI rules we can find, replacing them with |
| 23 | # new ones |
| 24 | # |
| 25 | # in addition, versions of module-init-tools 3.2.0 and later |
| 26 | # have the ability to pass module parameters specified on the modprobe command |
| 27 | # line to commands in 'install' rules, thus keeping them from being lost, so |
| 28 | # we try to determine what version is installed and take advantage of that |
| 29 | |
| 30 | toolver=`/sbin/modprobe --version 2>/dev/null| awk '{print $3}' | cut -d. -f2 | cut -d- -f1` |
| 31 | if [ ${toolver} -ge 2 ]; then |
| 32 | cmdopts=\$CMDLINE_OPTS |
| 33 | fi |
| 34 | if [ -d ${1}/etc/modprobe.d ]; then |
| 35 | target=${1}/etc/modprobe.d/dahdi |
| 36 | elif [ -d ${1}/etc/modules.d ]; then |
| 37 | target=${1}/etc/modules.d/dahdi |
| 38 | elif [ -f ${1}/etc/modprobe.conf ]; then |
| 39 | target=${1}/etc/modprobe.conf |
| 40 | combined=1 |
| 41 | elif [ -f ${1}/etc/conf.modules ]; then |
| 42 | target=${1}/etc/conf.modules |
| 43 | combined=1 |
| 44 | else |
| 45 | echo No suitable location for module rules can be found... exiting. |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | if [ -n "${combined}" ]; then |
| 50 | if [ -f ${target} ]; then |
| 51 | mv ${target} ${target}.bak |
| 52 | cat ${target}.bak | grep -v "alias char-major-250" | grep -v "alias char-major-196" > ${target} |
| 53 | fi |
| 54 | else |
| 55 | if [ -f ${target} ]; then |
| 56 | mv ${target} ${target}.bak |
| 57 | fi |
| 58 | echo "# automatically generated file; do not edit" > ${target} |
| 59 | fi |
| 60 | |
| 61 | echo Building ${target}... |
| 62 | |
| 63 | for mod in ${2}; do |
| 64 | if ! grep -q "install ${mod} " ${target}; then |
| 65 | echo "install ${mod} /sbin/modprobe --ignore-install ${mod} ${cmdopts} && /sbin/ztcfg" >> ${target} |
| 66 | fi |
| 67 | done |
| 68 | |
| 69 | if [ -z "${combined}" ]; then |
| 70 | echo "***" |
| 71 | echo "*** WARNING:" |
| 72 | echo "*** If you had custom settings in ${target}," |
| 73 | echo "*** they have been moved to ${target}.bak." |
| 74 | echo "***" |
| 75 | echo "*** In the future, do not edit ${target}, but" |
| 76 | echo "*** instead put your changes in another file" |
| 77 | echo "*** in the same directory so that they will not" |
| 78 | echo "*** be overwritten by future DAHDI updates." |
| 79 | echo "***" |
| 80 | fi |