OSDN Git Service

6acff0912eaa01d42c929029895c594b62b76d26
[android-x86/external-koush-Superuser.git] / Superuser / assets / update-binary
1 #!/sbin/sh
2 # arg 1 is recovery api version, generally 3.
3 # arg 2 is the pipe fd, to the recovery binary.
4 # communicate with it using the recovery api.
5 # arg 3 is the zip file
6 echo -n -e 'ui_print Installing Superuser...\n' > /proc/self/fd/$2
7 echo -n -e 'ui_print\n' > /proc/self/fd/$2
8
9 # detect binary versions to install
10 X86=$(uname -a | grep x86)
11 I686=$(uname -a | grep i686)
12 I386=$(uname -a | grep i386)
13 if [ ! -z "$X86" -o ! -z "$I686"  -o ! -z "$I386" ]
14 then
15   PLATFORM=x86
16 else
17   PLATFORM=armeabi
18 fi
19
20 cd /tmp
21 mkdir superuser
22 cd superuser
23 unzip -o "$3"
24 if [ "$?" -ne "0" ]
25 then
26   mkdir -p $PLATFORM
27   cp /cache/su $PLATFORM/su
28   cp /cache/Superuser.apk .
29   cp /cache/install-recovery.sh .
30 fi
31
32
33 echo -n -e 'ui_print Installing '$PLATFORM' binaries...\n' > /proc/self/fd/$2
34 echo -n -e 'ui_print\n' > /proc/self/fd/$2
35
36 mount /system
37 rm -f /system/bin/su
38 rm -f /system/xbin/su
39 rm -f /system/app/Superuser.*
40 rm -f /system/app/Supersu.*
41 rm -f /system/app/superuser.*
42 rm -f /system/app/supersu.*
43 rm -f /system/app/SuperUser.*
44 rm -f /system/app/SuperSU.*
45
46 cp $PLATFORM/su /system/xbin/su
47 chown 0:0 /system/xbin/su
48 chmod 6755 /system/xbin/su
49 ln -s /system/xbin/su /system/bin/su
50
51 cp Superuser.apk /system/app
52 chmod 644 /system/app/Superuser.apk
53
54 # if the system is at least 4.3, and there is no su daemon built in,
55 # let's try to install it using install-recovery.sh
56 BUILD_RELEASE_VERSION=$(cat /system/build.prop | grep ro\\.build\\.version\\.release)
57 IS_43=$(echo $BUILD_RELEASE_VERSION | grep 4\\.3)
58 if [ -z "$IS_43" -o "$IS_43" \> "4.3"  -o "$IS_43" == "4.3" ]
59 then
60     # check for rom su daemon before clobbering install-recovery.sh
61     if [ ! -f "/system/etc/.has_su_daemon" ]
62     then
63         echo -n -e 'ui_print Installing Superuser daemon...\n' > /proc/self/fd/$2
64         echo -n -e 'ui_print\n' > /proc/self/fd/$2
65         cp install-recovery.sh /system/etc/install-recovery.sh
66         chmod 755 /system/etc/install-recovery.sh
67         # note that an post install su daemon was installed
68         # so recovery doesn't freak out and recommend you disable
69         # the install-recovery.sh execute bit.
70         touch /system/etc/.installed_su_daemon
71     fi
72 fi
73
74 umount /system