Update rhod keymaps for new power button scancode
[xdandroid:rootfs.git] / installer
1 #!/bin/sh
2 fail() {
3         /bin/echo "Failed"
4         /bin/echo "$1"
5         exec /bin/sh
6 }
7
8 if [ -d /sdcard/android ] ; then
9         card=/sdcard/android
10 else
11         card=/sdcard
12 fi
13
14 if [ -d /sys/block/mmcblk0/mmcblk0p3 ] ; then
15         DATAPART=1
16 else
17         DATAPART=0
18 fi
19
20 #install the system supplied by $1 of type $2
21 system() {
22         losetup /dev/block/loop1 $card/$1
23         [ $? -eq 0 ] || fail "Failed to find $1 on SD Card"
24         mount -t $2 -o ro,noatime,nodiratime /dev/block/loop1 $card/temp
25         [ $? -eq 0 ] || fail "Failed to mount $1"
26         mke2fs -F /dev/block/mmcblk0p2
27         mount -t ext2 /dev/block/mmcblk0p2 /system
28         cp -a $card/temp/* /system/
29         umount $card/temp
30         umount /system
31         mkdir -p $card/backupsystem
32         mv $card/$1 $card/backupsystem/installed$1
33         [ $? -eq 0 ] || fail "Failed to copy"
34         if [ -f $card/data.img -a $DATAPART -eq 1 ] ; then
35                 userdata
36         else
37                 echo "System upgrade complete"
38                 if [ $DATAPART -eq 1 ] ; then
39                         read -s -n1 -t1 keypress
40                         read -s -n1 -t1 keypress
41                         read -s -n1 -t1 keypress
42                         read -s -n3 -p "VolDn to wipe data, END to continue" keypress
43                         if [ "$keypress" = "\e[2" ] ; then
44                                 echo ""
45                                 echo "Clearing your data parition"
46                                 mke2fs -F /dev/block/mmcblk0p3
47                         else
48                                 echo ""
49                         fi
50                 fi
51         fi
52 }
53
54 userdata() {
55         echo "Writing data.img onto data partition"
56         mke2fs -F /dev/block/mmcblk0p3
57         losetup /dev/block/loop0 $card/data.img
58         mount -t ext2 /dev/block/loop0 $card/temp
59         mount -t ext2 /dev/block/mmcblk0p3 /data
60         cp -a $card/temp/* /data/
61         umount $card/temp
62         umount /data
63         mkdir -p $card/backupsystem
64         mv $card/data.img $card/backupsystem/data.img
65 }
66
67 PATH=/sbin:/system/sbin:/system/bin:/bin:/system/xbin:/system/xbin/bb:/data/local/bin
68
69 /bin/echo ""
70 /bin/echo "Welcome to Android Installer"
71 mkdir $card/temp
72
73 # update your system from system.sqsh on sdcard
74 if [ -f $card/system.sqsh ] ; then
75         read -s -n1 -t1 keypress
76         read -s -n1 -t1 keypress
77         read -s -n1 -t1 keypress
78         read -s -n3 -p "Press Voldn to upgrade, END to continue." keypress
79         if [ "$keypress" = "\e[2" ] ; then
80                 echo ""
81                 echo "Using SquashFS system"
82                 system system.sqsh squashfs
83         fi
84 elif [ -f $card/system.ext2 ] ; then
85         read -s -n1 -t1 keypress
86         read -s -n1 -t1 keypress
87         read -s -n1 -t1 keypress
88         read -s -n3 -p "Press Voldn to upgrade, END to continue." keypress
89         if [ "$keypress" = "\e[2" ] ; then
90                 echo ""
91                 echo "Using ext2FS system"
92                 system system.ext2 ext2
93         fi
94 elif [ -f $card/system.img ] ; then
95         read -s -n1 -t1 keypress
96         read -s -n1 -t1 keypress
97         read -s -n1 -t1 keypress
98         read -s -n3 -p "Press Voldn to upgrade, END to continue." keypress
99         if [ "$keypress" = "\e[2" ] ; then
100                 echo ""
101                 echo "Using CramFS system"
102                 system system.img cramfs
103         fi
104 fi
105 if [ $DATAPART -eq 1 ] ; then
106         if [ -f $card/data.img ] ; then
107                 read -s -n1 -t1 keypress
108                 read -s -n1 -t1 keypress
109                 read -s -n1 -t1 keypress
110                 read -s -n3 -p "Press Voldn to use data.img, END to continue." keypress
111                 if [ "$keypress" = "\e[2" ] ; then
112                         echo ""
113                         userdata
114                 fi
115                 echo ""
116         fi
117         read -s -n1 -t1 keypress
118         read -s -n1 -t1 keypress
119         read -s -n1 -t1 keypress
120         read -s -n3 -p "Press Voldn to backup data, END to continue." keypress
121         if [ "$keypress" = "\e[2" ] ; then
122                 echo ""
123                 echo "Backing up your data partition"
124                 mount -t ext2 /dev/block/mmcblk0p3 /data
125                 mkdir -p $card/backupsystem
126                 if [ -f $card/backupsystem/databackup.img ] ; then
127                         rm $card/backupsystem/databackup.img
128                 fi
129                 dd if=/dev/zero of=$card/backupsystem/databackup.img bs=1048576 count=256
130                 mke2fs -F $card/backupsystem/databackup.img
131                 losetup /dev/block/loop0 $card/backupsystem/databackup.img
132                 mount -t ext2 /dev/block/loop0 $card/temp
133                 cp -a /data/* $card/temp
134                 umount /data
135                 umount $card/temp
136         fi
137         echo ""
138         read -s -n1 -t1 keypress
139         read -s -n1 -t1 keypress
140         read -s -n1 -t1 keypress
141         read -s -n3 -p "Press Voldn to wipe data, END to continue." keypress
142         if [ "$keypress" = "\e[2" ] ; then
143                 echo ""
144                 echo "Clearing your data partition"
145                 mke2fs -F /dev/block/mmcblk0p3
146         fi
147 fi
148 echo ""
149 echo "Thanks for using the Android utilities"
150 rmdir $card/temp
151 read -s -n1 -t1 keypress
152 read -s -n1 -t1 keypress
153 read -s -n1 -t1 keypress
154 read -s -n1 -p "Press any key to boot"