dahdi-modules 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. MODULES="dahdi"
  3. DAHDI_MODULES_FILE="/etc/dahdi/modules"
  4. usage() {
  5. cat <<EOF
  6. $0: loads / unloads DAHDI kernel modules
  7. Usage: $0 <load|unload>
  8. * load: Loads all modules listed in /etc/dahdi/modules (one per line)
  9. * unload: Unloads the DAHDI modules (all the modules that are dependencies
  10. of $MODULES).
  11. EOF
  12. }
  13. # recursively unload a module and its dependencies, if possible.
  14. # where's modprobe -r when you need it?
  15. # inputs: module to unload.
  16. # returns: the result from
  17. unload_module() {
  18. module="$1"
  19. line=`lsmod 2>/dev/null | grep "^$1 "`
  20. if [ "$line" = '' ]; then return; fi # module was not loaded
  21. set -- $line
  22. # $1: the original module, $2: size, $3: refcount, $4: deps list
  23. mods=`echo $4 | tr , ' '`
  24. ec_modules=""
  25. # xpp_usb keeps the xpds below busy if an xpp hardware is
  26. # connected. Hence must be removed before them:
  27. case "$module" in xpd_*) mods="xpp_usb $mods";; esac
  28. for mod in $mods; do
  29. case "$mod" in
  30. dahdi_echocan_*)
  31. ec_modules="$mod $ec_modules"
  32. ;;
  33. *)
  34. # run in a subshell, so it won't step over our vars:
  35. (unload_module $mod)
  36. ;;
  37. esac
  38. done
  39. # Now that all the other dependencies are unloaded, we can unload the
  40. # dahdi_echocan modules. The drivers that register spans may keep
  41. # references on the echocan modules before they are unloaded.
  42. for mod in $ec_modules; do
  43. (unload_module $mod)
  44. done
  45. rmmod $module
  46. }
  47. unload_modules() {
  48. for module in "$@"; do
  49. unload_module $module
  50. done
  51. }
  52. load_modules() {
  53. modules=`sed -e 's/#.*$//' $DAHDI_MODULES_FILE 2>/dev/null`
  54. for line in $modules; do
  55. modprobe $line
  56. done
  57. }
  58. case "$1" in
  59. load) load_modules "$@";;
  60. unload) unload_modules $MODULES;;
  61. *) usage;;
  62. esac