#!/bin/bash
-# run/kill Android from Linux
+# run/kill Android from Linux, the hackjob script
# (c) Grazvydas "notaz" Ignotas, 2012
set -e -x
if [ "`id -u`" != "0" ]; then
- gksudo -m "Android needs root privileges to run, please enter your password" $0
- exit 0
+ # gksudo causes logging not to work somehow..
+ # so use it to only ask for password, use sudo to re-run the script
+ gksudo -m "Android needs root privileges to run, please enter your password" id
+ exec sudo -n $0
fi
root=/mnt/android
mpoint_main=`pwd`
kernel_ver=`uname -r`
+exitcode=1
-trap onexit 1 2 3 15 EXIT
+trap onexit INT QUIT TERM EXIT
+trap '' HUP
err()
{
sleep 0.5
- for i in `seq 5`; do
+ for i in `seq 4`; do
sdmounts=`grep -e '\.android_secure' -e 'secure/asec' -e 'mnt/sdcard' /proc/mounts`
if [ -n "$sdmounts" ]; then
echo "$sdmounts" | awk '{print $2}' | xargs umount
fi
- umount $root/mnt/asec
- umount $root/debug
- umount $root/dev/pts
- umount $root/dev
- umount $root/proc
- umount $root/sys
- umount $root/data
- umount $root/system || umount -i $root/system
-
- sleep 1
+ omounts=`grep "$root/" /proc/mounts | awk '{print $2}'`
+ if [ -n "$omounts" ]; then
+ for m in $omounts; do
+ if ! umount $m; then
+ umount -i $m
+ fi
+ done
+ fi
+
+ sleep 0.5
if umount $root; then
break;
fi
/etc/init.d/NetworkManager start
/etc/init.d/slim-init start
fi
+
+ if ! ps a | grep -q 'pnd_run.*run_gingerbread.sh'; then
+ # something killed pnd_run, have to clean up for it
+ cat > /tmp/clean_android.sh <<EOF
+ #!/bin/bash
+ trap '' HUP
+ sleep 3
+ umount $mpoint_main
+ umount $mpoint_main # needed twice??
+ losetup -a | awk -F ':' '{ print \$1 }' | xargs losetup -d 2> /dev/null
+ rm $0
+EOF
+ cd /tmp/
+ chmod +x /tmp/clean_android.sh
+ /tmp/clean_android.sh &
+ sleep 1
+ fi
+ exit $exitcode
}
mount --bind $mpoint_main/system/ $root/system/
mount -o loop,rw,noatime data.ext4 $root/data
-mkdir -p $root/vendor
+mkdir -p $root/vendor/
# handle SGX
mkdir -p $root/vendor/pvr
ifconfig wlan0 down
set -e
-cp /etc/pointercal $root/vendor/
-cp /lib/modules/$kernel_ver/kernel/drivers/net/wireless/wl1251/wl1251_sdio.ko $root/vendor/
+cp -v /etc/pointercal $root/vendor/
+cp -v /lib/modules/$kernel_ver/kernel/drivers/net/wireless/wl1251/wl1251_sdio.ko $root/vendor/
mkdir -p $root/vendor/firmware
-cp /lib/firmware/brf6300.bin $root/vendor/firmware/
+cp -v /lib/firmware/brf6300.bin $root/vendor/firmware/
# some cleanup
rm -rf $root/acct/uid/*
# real init can't be killed this way
killall init
+
+# done, run exit handler indirectly
+exitcode=0
mkdir -p pandora/pvr
cp ../../device/openpandora/pandora/pnd/gingerbread.png pandora/
cp ../../device/openpandora/pandora/pnd/gingerbread.pxml pandora/
-cp ../../device/openpandora/pandora/pnd/run.sh pandora/
+cp ../../device/openpandora/pandora/pnd/run_gingerbread.sh pandora/
cp ../../device/openpandora/pandora/pnd/readme.txt pandora/
cp -r ../../device/openpandora/pandora/pvr/3* pandora/pvr/
mv /tmp/pnd_android/rootfs.ext2 pandora/default_rootfs.ext2