genmodconf 2.7 KB

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