2 # run/kill Android from Linux
3 # (c) Grazvydas "notaz" Ignotas, 2012
6 if [ "`id -u`" != "0" ]; then
7 gksudo -m "Android needs root privileges to run, please enter your password" $0
15 trap onexit 1 2 3 15 EXIT
19 zenity --error --text "$1"
27 list="/sbin/ueventd /system/bin/logcat /system/bin/sh /system/bin/servicemanager
28 /system/bin/vold /system/bin/netd /system/bin/rild /system/bin/installd /sbin/adbd
29 /system/bin/mediaserver /system/bin/keystore /system/bin/debuggerd
30 /system/bin/dbus-daemon"
33 p=`ps -C $pb -o pid=,cmd= | grep $pr | awk '{print $1}'`
34 test -n "$p" && echo kill $p $pr && kill $p
38 p=`ps -C $pb -o pid=,cmd= | grep $pr | awk '{print $1}'`
39 test -n "$p" && echo kill -9 $p $pr && kill -9 $p
41 list2=`ps ax | grep -v grep | grep -e ':.. /system/' -e ':.. /data/' -e ' android\.' | awk '{print $1}'`
42 list3=`lsof | grep '/dev/binder' | awk '{print $2}' | uniq`
43 for p in $list2 $list3; do
44 test -n "$p" && echo kill $p && kill $p
50 sdmounts=`grep -e '\.android_secure' -e 'secure/asec' -e 'mnt/sdcard' /proc/mounts`
51 if [ -n "$sdmounts" ]; then
52 echo "$sdmounts" | awk '{print $2}' | xargs umount
62 umount $root/system || umount -i $root/system
70 if ! pidof X > /dev/null; then
71 # need to restore SGX, X and friends
72 rmmod bufferclass_ti omaplfb pvrsrvkm
73 /etc/init.d/pvr-init start
74 rmmod wl1251_sdio # hmh
75 /etc/init.d/NetworkManager start
76 /etc/init.d/slim-init start
81 # logger, binder and ashmem
83 if ! test -e /dev/log_events; then
87 if ! test -e /dev/binder; then
91 if ! test -e /dev/ashmem; then
96 if test ! -e /dev/log_events -o ! -e /dev/binder -o ! -e /dev/ashmem; then
97 err "could not load required Android modules,\n\
98 perhaps you are running unsupported\nfirmware/kernel."
102 if ! test -e rootfs.ext2; then
103 if ! cp -v pandora/default_rootfs.ext2 rootfs.ext2; then
104 err "file copy failed, not enough space?"
109 if ! test -e data.ext4; then
110 size=`zenity --entry --text="\
111 Android needs a partition to store it's data and installed programs.\n\
112 This will be stored in preallocated file of size that you have to select now.\n\
113 Android documentation recommends at least 150MB, going below 50MB will cause\n\
114 problems, as well as over 2GB if you are running from FAT partitioned card.\n\n\
115 Please select size of Android data partition (in megabytes):\n\
116 (creation may take several minutes after you press OK)" \
118 if test -z "$size" || ! dd if=/dev/zero of=data.ext4 bs=1M count=$size; then
119 err "failed to create file, not enough space? bad input?"
122 if ! mkfs.ext4 -O ^has_journal -m 0 -F data.ext4; then
123 err "failed to create filesystem"
128 if ! fsck.ext4 -y data.ext4 || ! fsck.ext2 -y rootfs.ext2; then
129 if [ "$?" -ge "4" ]; then
130 err "file corruption detected, try clearing appdata."
136 mount -o loop,rw,noatime rootfs.ext2 $root
137 mount --bind $mpoint_main/system/ $root/system/
138 mount -o loop,rw,noatime data.ext4 $root/data
140 mkdir -p $root/vendor
143 mkdir -p $root/vendor/pvr
144 echo "0 0 android" > $root/vendor/pvr/egl.cfg
146 # load the right SGX driver
147 sgx_kernel_loaded=false
148 if ! grep -q '1.5.15.2766' /proc/pvr/version 2> /dev/null; then
149 echo have to change SGX kernel driver
150 /etc/init.d/pvr-init stop || true
151 if test -d $mpoint_main/pandora/pvr/$kernel_ver; then
152 # found with this android release
153 pvrbase=$mpoint_main/pandora/pvr/$kernel_ver
154 elif test -d /lib/modules/$kernel_ver/kernel/drivers/gpu/pvr/1.5.15.2766; then
156 pvrbase=/lib/modules/$kernel_ver/kernel/drivers/gpu/pvr/1.5.15.2766
159 if [ "x$pvrbase" != "x" ]; then
160 if insmod $pvrbase/pvrsrvkm.ko && insmod $pvrbase/omaplfb.ko; then
161 sgx_kernel_loaded=true
163 insmod $pvrbase/bufferclass_ti.ko || true
167 sgx_kernel_loaded=true
172 if $sgx_kernel_loaded; then
173 es=`cat /etc/powervr-esrev`
174 if [ "x$es" = "x" ]; then
175 err "unable to determine SGX version"
178 # for some braindead reason 103 is named 121 too
180 if [ "$es" = "es5" ]; then
183 ln -fs /system/lib/$es/libGLESv2_POWERVR_SGX530_121.so $root/vendor/pvr/
184 ln -fs /system/lib/$es/libGLESv1_CM_POWERVR_SGX530_121.so $root/vendor/pvr/
186 ln -fs /system/bin/$es/pvrsrvinit $root/vendor/pvr/
187 ln -fs /system/lib/$es/libPVRScopeServices.so $root/vendor/pvr/
188 ln -fs /system/lib/$es/libglslcompiler.so $root/vendor/pvr/
189 ln -fs /system/lib/$es/libsrv_um.so $root/vendor/pvr/
190 ln -fs /system/lib/$es/libIMGegl.so $root/vendor/pvr/
192 echo "0 1 POWERVR_SGX530_$sgx_ver" >> $root/vendor/pvr/egl.cfg
197 if ! $sgx_user_ready; then
198 err "SGX driver load failed, no 3D support"
201 # stop X and interfering things, get wifi ready
203 if pidof xfce4-session > /dev/null; then
204 user=`cat /tmp/currentuser`
205 # most often doesn't work :(
206 #if ! test -z "$user"; then
207 # su -c 'xfce4-session-logout --logout' $user
210 /etc/init.d/NetworkManager stop
212 /etc/init.d/wl1251-init start
213 /etc/init.d/slim-init stop
214 sleep 1 # for wlan0, hmh..
215 chvt 2 & # may hang..
217 killall chvt 2> /dev/null || true
221 cp /etc/pointercal $root/vendor/
222 cp /lib/modules/$kernel_ver/kernel/drivers/net/wireless/wl1251/wl1251_sdio.ko $root/vendor/
223 mkdir -p $root/vendor/firmware
224 cp /lib/firmware/brf6300.bin $root/vendor/firmware/
227 rm -rf $root/acct/uid/*
235 if nc -V 2> /dev/null | grep -q GNU; then
236 # GNU nc always fails
237 msg=`nc -l -p 36936 localhost || true`
239 msg=`nc -l localhost 36936`
241 if [ "x$msg" = "xquit" ]; then
244 echo "unknown message: $msg"
247 # real init can't be killed this way