summaryrefstree
path: root/vendor/bin/init.insmod.sh
blob: 75c361a894c0c1cbc334bef6513805f19e033656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/vendor/bin/sh

########################################################
### init.insmod.cfg format:                          ###
### -----------------------------------------------  ###
### [insmod|setprop|enable/moprobe] [path|prop name] ###
### ...                                              ###
########################################################

if [ $# -eq 1 ]; then
  cfg_file=$1
else
  exit 1
fi

if [ -f $cfg_file ]; then
  while IFS="|" read -r action arg
  do
    case $action in
      "insmod") insmod $arg ;;
      "setprop")
        times=1
        setprop $arg 1
        while [ "$?" -ne 0 ]
        do
          if [ $times -gt 128 ]; then
            break
          fi
          let times++
          setprop $arg 1
        done ;;
      "enable") echo 1 > $arg ;;
      "modprobe")
        insmod_arg=${arg}
        for partition in system_dlkm vendor
        do
          modules_dir_base="/${partition}/lib/modules"
          for modules_dir in ${modules_dir_base}/*/ ${modules_dir_base}
          do
            if [ ! -f "${modules_dir}/modules.load" ]; then
              continue
            fi
            case ${insmod_arg} in
              "-b *" | "-b")
                arg="-b $(cat ${modules_dir}/modules.load)" ;;
              "*" | "")
                arg="$(cat ${modules_dir}/modules.load)" ;;
            esac
            modprobe -a -d ${modules_dir} $arg
          done
        done
    esac
  done < $cfg_file
else
  exit 2
fi