OSDN Git Service

76423c00bd9c75a73c6317b8cccb60a5528463a9
[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 ARCH=$(uname -m)
11
12 # x86 needs to match: i486, i686, x86_64, ...
13 if echo "$ARCH" | grep -q 86; then
14   PLATFORM=x86
15 elif [ "$ARCH" = "mips" -o "$ARCH" = "mips64" ]; then
16   PLATFORM=mips
17 else
18   PLATFORM=armeabi
19 fi
20
21 cd /tmp
22 mkdir superuser
23 cd superuser
24 unzip -o "$3"
25 if [ "$?" -ne "0" ]
26 then
27   mkdir -p $PLATFORM
28   cp /cache/su $PLATFORM/su
29   cp /cache/Superuser.apk .
30   cp /cache/install-recovery.sh .
31 fi
32
33
34 echo -n -e 'ui_print Installing '$PLATFORM' binaries...\n' > /proc/self/fd/$2
35 echo -n -e 'ui_print\n' > /proc/self/fd/$2
36
37 mount /system
38 chattr -i /system/bin/su
39 chattr -i /system/xbin/su
40 rm -f /system/bin/su
41 rm -f /system/xbin/su
42 rm -f /system/app/Superuser.*
43 rm -f /system/app/Supersu.*
44 rm -f /system/app/superuser.*
45 rm -f /system/app/supersu.*
46 rm -f /system/app/SuperUser.*
47 rm -f /system/app/SuperSU.*
48
49 cp $PLATFORM/su /system/xbin/su
50 chown 0:0 /system/xbin/su
51 chmod 6755 /system/xbin/su
52 ln -s /system/xbin/su /system/bin/su
53
54 cp Superuser.apk /system/app
55 chmod 644 /system/app/Superuser.apk
56
57 # if the system is at least 4.3, and there is no su daemon built in,
58 # let's try to install it using install-recovery.sh
59 BUILD_RELEASE_VERSION="$(grep 'ro\.build\.version\.release' /system/build.prop)"
60 VERSION="${BUILD_RELEASE_VERSION##*=}"
61 MAJ=${VERSION%%.*}
62 MIN=${VERSION#*.}
63 MIN=${MIN//.*}
64
65 if [ "$MAJ" -ge 4 -a "$MIN" -ge 3 ]
66 then
67   # on 4.3+, the daemon need not be setuid.
68   chmod 0755 /system/xbin/su
69   # check for rom su daemon before clobbering install-recovery.sh
70   if [ ! -f "/system/etc/.has_su_daemon" ]
71   then
72       echo -n -e 'ui_print Installing Superuser daemon...\n' > /proc/self/fd/$2
73       echo -n -e 'ui_print\n' > /proc/self/fd/$2
74       chattr -i /system/etc/install-recovery.sh
75       cp install-recovery.sh /system/etc/install-recovery.sh
76       chmod 755 /system/etc/install-recovery.sh
77       # note that an post install su daemon was installed
78       # so recovery doesn't freak out and recommend you disable
79       # the install-recovery.sh execute bit.
80       touch /system/etc/.installed_su_daemon
81   fi
82 fi
83
84 umount /system