OSDN Git Service

98028092a2325c7e31b0b1d476997f8b5c735813
[android-x86/device-generic-common.git] / nativebridge / bin / enable_nativebridge
1 #!/system/bin/sh
2
3 PATH=/system/bin:/system/xbin
4
5 houdini_bin=0
6 dest_dir=/system/lib$1/arm$1
7 binfmt_misc_dir=/proc/sys/fs/binfmt_misc
8
9 urls[0]=http://t.cn/RBJ7mfG
10 urls[1]=http://t.cn/RBJ7eml
11 urls[2]=http://t.cn/RBJzLwu
12 urls[3]=http://goo.gl/96BPKe
13 urls[4]=http://goo.gl/v6c4Co
14 urls[5]=http://goo.gl/CtKjxx
15
16 mount_sfs()
17 {
18         mount -o 'context="u:object_r:system_file:s0"' $1 $2
19 }
20
21 if [ -z "$1" ]; then
22         v=8_y
23         u=1
24 else
25         v=8_z
26         u=2
27 fi
28
29 if [ -s /system/lib$1/libhoudini.so ]; then
30         log -pi -thoudini "found /system/lib$1/libhoudini.so"
31 elif [ -e /system/etc/houdini$v.sfs ]; then
32         mount_sfs /system/etc/houdini$v.sfs $dest_dir
33 else
34         if mountpoint -q $dest_dir; then
35                 kill -9 `fuser -m $dest_dir`
36                 umount -f $dest_dir
37         fi
38         mkdir -p /data/arm
39         cd /data/arm
40         while ! mount_sfs houdini$v.sfs $dest_dir; do
41                 while [ "$(getprop net.dns1)" = "" ]; do
42                         sleep 10
43                 done
44                 wget ${urls[$u%6]} -cO houdini$v.sfs && continue
45                 rm -f houdini$v.sfs
46                 sleep 30
47                 let u+=3
48         done
49 fi
50
51 [ -s /system/lib$1/libhoudini.so ] || mount --bind $dest_dir/libhoudini.so /system/lib$1/libhoudini.so
52
53 # this is to add the supported binary formats via binfmt_misc
54
55 if [ ! -e $binfmt_misc_dir/register ]; then
56         modprobe binfmt_misc
57         mount -t binfmt_misc none $binfmt_misc_dir
58 fi
59
60 cd $binfmt_misc_dir
61 if [ -e register ]; then
62         [ -e /system/bin/houdini$1 ] && dest_dir=/system/bin
63         # register Houdini for arm binaries
64         if [ -z "$1" ]; then
65                 echo ':arm_exe:M::\\x7f\\x45\\x4c\\x46\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28::'"$dest_dir/houdini:P" > register
66                 echo ':arm_dyn:M::\\x7f\\x45\\x4c\\x46\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x00\\x28::'"$dest_dir/houdini:P" > register
67         else
68                 echo ':arm64_exe:M::\\x7f\\x45\\x4c\\x46\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7::'"$dest_dir/houdini64:P" > register
69                 echo ':arm64_dyn:M::\\x7f\\x45\\x4c\\x46\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x00\\xb7::'"$dest_dir/houdini64:P" > register
70         fi
71         if [ -e arm${1}_exe ]; then
72                 houdini_bin=1
73         fi
74 else
75         log -pe -thoudini "No binfmt_misc support"
76 fi
77
78 if [ $houdini_bin -eq 0 ]; then
79         log -pe -thoudini "houdini$1 enabling failed!"
80 else
81         log -pi -thoudini "houdini$1 enabled"
82 fi
83
84 exit 0