OSDN Git Service

DO NOT MERGE temporary fix for broken wget script in CM13.0
[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 cd /data/arm
10 if [ -e /system/lib$1/libhoudini.so ]; then
11         log -pi -thoudini "found /system/lib$1/libhoudini.so"
12 elif [ -e /system/etc/houdini$1.sfs ]; then
13         busybox mount /system/etc/houdini$1.sfs $dest_dir
14 else
15         if mountpoint -q $dest_dir; then
16                 kill -9 `fuser -m $dest_dir`
17                 umount -f $dest_dir
18         fi
19         while ! busybox mount houdini$1.sfs $dest_dir; do
20                 while [ "$(getprop net.dns1)" = "" ]; do
21                         sleep 10
22                 done
23                 if [ -z "$1" ]; then
24                         [ "`uname -m`" = "x86_64" ] && url=http://goo.gl/Knnmyl || url=http://goo.gl/JsoX2C
25                 else
26                         url=http://goo.gl/n6KtQa
27                 fi
28                 busybox wget $url -cO houdini$1.sfs && continue
29                 rm -f houdini$1.sfs
30                 sleep 30
31         done
32 fi
33
34
35 # if you don't see the files 'register' and 'status' in /proc/sys/fs/binfmt_misc
36 # then run the following command:
37 # mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
38
39 # this is to add the supported binary formats via binfmt_misc
40
41 if [ ! -e $binfmt_misc_dir/register ]; then
42         mount -t binfmt_misc none $binfmt_misc_dir
43 fi
44
45 cd $binfmt_misc_dir
46 if [ -e register ]; then
47         # register Houdini for arm binaries
48         if [ -z "$1" ]; then
49                 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
50                 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
51         else
52                 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
53                 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
54         fi
55         if [ -e arm${1}_exe ]; then
56                 houdini_bin=1
57         fi
58 else
59         log -pe -thoudini "No binfmt_misc support"
60 fi
61
62 if [ $houdini_bin -eq 0 ]; then
63         log -pe -thoudini "houdini$1 enabling failed!"
64 else
65         log -pi -thoudini "houdini$1 enabled"
66 fi
67
68 [ "$(getprop ro.zygote)" = "zygote64_32" -a -z "$1" ] && exec $0 64
69
70 exit 0