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