OSDN Git Service

Merge remote-tracking branch 'x86/nougat-x86' into oreo-x86
[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 if [ -z "$1" ]; then
17         v=8_y
18         u=1
19 else
20         v=8_z
21         u=2
22 fi
23
24 if [ -s /system/lib$1/libhoudini.so ]; then
25         log -pi -thoudini "found /system/lib$1/libhoudini.so"
26 elif [ -e /system/etc/houdini$v.sfs ]; then
27         mount /system/etc/houdini$v.sfs $dest_dir
28 else
29         if mountpoint -q $dest_dir; then
30                 kill -9 `fuser -m $dest_dir`
31                 umount -f $dest_dir
32         fi
33         mkdir -p /data/arm
34         cd /data/arm
35         while ! mount houdini$v.sfs $dest_dir; do
36                 while [ "$(getprop net.dns1)" = "" ]; do
37                         sleep 10
38                 done
39                 wget ${urls[$u%6]} -cO houdini$v.sfs && continue
40                 rm -f houdini$v.sfs
41                 sleep 30
42                 let u+=3
43         done
44 fi
45
46 [ -s /system/lib$1/libhoudini.so ] || mount --bind $dest_dir/libhoudini.so /system/lib$1/libhoudini.so
47
48 # this is to add the supported binary formats via binfmt_misc
49
50 if [ ! -e $binfmt_misc_dir/register ]; then
51         modprobe binfmt_misc
52         mount -t binfmt_misc none $binfmt_misc_dir
53 fi
54
55 cd $binfmt_misc_dir
56 if [ -e register ]; then
57         [ -e /system/bin/houdini$1 ] && dest_dir=/system/bin
58         # register Houdini for arm binaries
59         if [ -z "$1" ]; then
60                 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
61                 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
62         else
63                 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
64                 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
65         fi
66         if [ -e arm${1}_exe ]; then
67                 houdini_bin=1
68         fi
69 else
70         log -pe -thoudini "No binfmt_misc support"
71 fi
72
73 if [ $houdini_bin -eq 0 ]; then
74         log -pe -thoudini "houdini$1 enabling failed!"
75 else
76         log -pi -thoudini "houdini$1 enabled"
77 fi
78
79 exit 0