[package] add compcache (#4481)
[openwrt-10.03/.git] / package / compcache / files / compcache.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3 START=19
4
5 load_modules() {
6         local section="$1"
7         config_get "size_kbytes" "$section" "size_kbytes"
8         config_get_bool "enabled" "$section" "enabled" '1'
9         if [ "$enabled" -gt 0 ]; then
10                 if [ "`lsmod | grep 'compcache'`" != "" ]; then
11                         echo "compcache allready loaded"
12                 else
13                         insmod xvmalloc
14                         insmod lzo1x
15                         insmod compcache compcache_size_kbytes=$size_kbytes
16                 fi
17         fi
18 }
19
20 remove_modules() {
21         local section="$1"
22         config_get_bool "enabled" "$section" "enabled" '1'
23         if [ "$enabled" -gt 0 ]; then
24                 [ "`cat /proc/swaps | grep 'ramzswap0'`" != "" ] && swapoff /dev/ramzswap0
25                 [ "`lsmod | grep 'compcache'`" != "" ] && rmmod compcache > /dev/null
26                 [ "`lsmod | grep 'lzo1x'`" != "" ] && rmmod lzo1x > /dev/null
27                 [ "`lsmod | grep 'xvmalloc'`" != "" ] && rmmod xvmalloc > /dev/null
28         fi
29 }
30
31 start() {
32         config_load "compcache"
33         config_foreach load_modules "compcache"
34 }
35
36 stop() {
37         config_load "compcache"
38         config_foreach remove_modules "compcache"
39 }