2 # By Chih-Wei Huang <cwhuang@linux.org.tw>
3 # Last updated 2012/07/07
5 # License: GNU Public License
6 # We explicitely grant the right to use the scripts
7 # with Android-x86 project.
17 dialog --title " Rebooting... " --nocancel --pause "" 8 41 1
25 dialog --clear --title " $1 " \
26 --menu "$2" 20 71 13 --file $menufile 2> $tempfile
29 choice=`cat $tempfile`
35 for i in /sys/block/[shv]d[a-z] /sys/block/mmcblk?; do
36 if [ ! -d $i ]; then # pathname expansion failed
39 echo -n `basename $i` >> $menufile
40 if [ -f $i/removable -a `cat $i/removable` -eq 0 ]; then
41 echo -n ' "Harddisk ' >> $menufile
43 echo -n ' "Removable' >> $menufile
45 if [ -f $i/size ]; then
46 echo -n " (" `cat $i/size` "blocks)" >> $menufile
50 count=`wc -l $menufile | awk '{ print $1 }'`
51 if [ $count -eq 0 ]; then
52 dialog --title " Error " --msgbox \
53 "\nOK. There is no hard drive to edit partitions." 8 49
56 if [ $count -eq 1 ]; then
57 choice=`awk '{ print $1 }' $menufile`
60 choose "Choose Drive" "Please select a drive to edit partitions:"
62 if [ $retval -eq 0 ]; then
63 dialog --title " Confirm " --defaultno --yesno "\n Do you want to use GPT?" 7 29
80 blkid | grep -v -E "^/dev/block/|^/dev/loop" | cut -b6- | sort | awk '{
82 for (i = NF; i > 1; --i)
83 if (match($i, "^TYPE")) {
87 gsub(/TYPE=|"/, "", t)
88 printf("%s\t%s\n", $1, t)
91 lsblk=`ls /sys/block | grep -v -E "loop|ram|sr|boot|rpmb"`
94 for i in /sys/block/$d/$d* /sys/block/$d; do
95 [ -e $i/partition ] && p=1
96 [ $p -eq 1 -a "$i" = "/sys/block/$d" ] && break
97 echo $i | grep -q -E "boot|rpmb" && continue
98 [ -d $i ] && ( grep "`basename $i:`" $tempfile || echo "`basename $i` unknown" )
102 printf("\"%-13s%-17s", $1, $2)
103 system("cd /sys/block; for f in "$1"/device/model "$1"/device/name */"$1"/../device/model */"$1"/../device/name; do [ -e $f ] && echo -n `cat $f` && break; done")
106 printf("\"Create/Modify partitions\" \"\"\n\"Detect devices\" \"\"")
108 choose "Choose Partition" "Please select a partition to install Android-x86:"
114 dialog --clear --title " $1 " --gauge "\n $2" 8 70
120 echo -e '"Do not format" ""\next3 ""\next2 ""\nntfs ""\nfat32 ""' > $menufile
121 choose "Choose filesystem" "Please select a filesystem to format $1:"
138 if [ -n "$cmd" ]; then
139 dialog --title " Confirm " --defaultno --yesno \
140 "\n You chose to format $1 to $choice.\n All data in that partition will LOSE.\n\n Are you sure to format the partition $1?" 10 51
141 [ $? -ne 0 ] && return 1
142 $cmd Android-x86 /dev/$1 | awk '{
143 # FIXME: very imprecise progress
144 if (match($0, "done"))
145 printf("%d\n", i+=33)
146 }' | progress_bar "Formatting" "Formatting partition $1..."
154 echo -e "title $title\n\tkernel /$asrc/kernel$vga $@ SRC=/$asrc\n\tinitrd /$asrc/initrd.img\n" >> $menulst
159 menulst=/hd/grub/menu.lst
160 [ -n "$VESA" ] && vga=" vga=788 modeset=0"
161 echo -e "${GRUB_OPTIONS:-default=0\ntimeout=6\nsplashimage=/grub/android-x86.xpm.gz\n}root (hd0,$1)\n" > $menulst
163 create_entry "Android-x86 $VER" quiet $cmdline
164 create_entry "Android-x86 $VER (Debug mode)" $cmdline DEBUG=2
165 create_entry "Android-x86 $VER (Debug nomodeset)" nomodeset $cmdline DEBUG=2
166 create_entry "Android-x86 $VER (Debug video=LVDS-1:d)" video=LVDS-1:d $cmdline DEBUG=2
171 win=`fdisk -l /dev/$(echo $1 | cut -b-3) | grep ^/dev | cut -b6-12,55- | awk '{
172 if (match($2, "NTFS"))
175 if [ -n "$win" ]; then
176 dialog --title " Confirm " --yesno \
177 "\nThe installer found a Windows partition in /dev/$win.\n\nDo you want to create a boot item for Windows?" 9 59
178 [ $? -ne 0 ] && return 1
179 wp=$((`echo $win | cut -b4-`-1))
180 echo -e "title Windows\n\trootnoverify (hd$d,$wp)\n\tchainloader +1\n" >> $menulst
188 dialog --title " Confirm " --defaultno --yesno \
189 "\n $bname exists. Overwrite it?" 7 38
190 [ $? -ne 0 ] && return 255
193 dialog --title " Question " --nook --nocancel --inputbox \
194 "\nPlease input the size of the $bname in MB:" 8 63 $1 2> $tempfile
196 [ 0$size -le 0 ] && size=1024
197 ( dd bs=1M count=$size if=/dev/zero | pv -ns ${size}m | dd of=$2 ) 2>&1 \
198 | progress_bar "Creating $bname" "Expect to write $size MB..."
203 dialog --title " Confirm " --yesno \
204 "\nThe installer is going to create a disk image to save the user data. At least 512MB free disk space is recommended.\n\nAre you sure to create the image?" 11 62
206 if [ $? -eq 0 ]; then
207 if create_img 512 data.img; then
208 losetup /dev/loop6 data.img
209 mke2fs -jL /data /dev/loop6 > /dev/tty6
211 [ $? -ne 0 ] && dialog --msgbox "\n Failed to create data.img." 7 33
213 dialog --title " Warning " --msgbox \
214 "\nOK. So data will be save to a RAMDISK(tmpfs), and lose after power off." 8 49
221 PREV_VERS="4.4-r4 4.4-r3 4.4-r2 4.4-r1 4.4-RC2 4.4-RC1 4.4-test 4.3-test 4.2-test 4.0-r1 4.0-RC2 4.0-RC1"
222 for v in $PREV_VERS; do
224 if [ -d $prev ]; then
225 dialog --title " Question " --yesno \
226 "\nAn older Android-x86 version $v is detected.\nWould you like to upgrade it?" 8 55
227 if [ $? -eq 0 ]; then
229 rm -rf $1/data/dalvik-cache/* $1/data/system/wpa_supplicant
230 sed -i 's/\(ctrl_interface=\)\(.*\)/\1wlan0/' $1/data/misc/wifi/wpa_supplicant.conf
241 h=`echo $d | awk '{ printf("%c", $1+97) }'`
242 for part in /sys/block/[shv]d$h/$1 /sys/block/mmcblk$d/$1; do
243 [ -d $part ] && break 2
247 p=`cat $part/partition`
248 disk=$(basename `dirname $part`)
254 mountpoint -q /hd && umount /hd
257 try_mount rw /dev/$1 /hd && break
258 dialog --clear --title " Error " --defaultno --yesno \
259 "\n Cannot mount /dev/$1\n Do you want to format it?" 8 37
260 [ $? -ne 0 ] && return 255
263 fs=`cat /proc/mounts | grep /dev/$1 | awk '{ print $3 }'`
264 cmdline=`sed "s|\(initrd.*img\s*\)||; s|quiet\s*||; s|\(vga=\w\+\?\s*\)||; s|\(DPI=\w\+\?\s*\)||; s|\(INSTALL=\w\+\?\s*\)||; s|\(SRC=\S\+\?\s*\)||; s|\(DEBUG=\w\+\?\s*\)||; s|\(BOOT_IMAGE=\S\+\?\s*\)||" /proc/cmdline`
267 dialog --title " Confirm " --no-label Skip --defaultno --yesno \
268 "\n Do you want to install boot loader GRUB?" 7 47
269 if [ $? -eq 0 ]; then
275 rm -f /hd/boot/grub/stage1
276 echo "(hd$d) /dev/$disk" > /hd/grub/device.map
277 echo "setup (hd$d) (hd$d,$p)" | grub --device-map /hd/grub/device.map > /dev/tty5
278 [ $? -ne 0 ] && return 255
281 dialog --title " Confirm " --no-label Skip --defaultno --yesno \
282 "\n Do you want to install EFI GRUB2?" 7 39
283 if [ $? -eq 0 ]; then
285 for i in /sys/block/$disk/$disk*; do
286 [ 0`cat $i/partition` -eq 1 ] && b=$i
287 [ $(blkid /dev/`basename $i` | grep -c vfat) -ne 0 ] && b=$i && break
290 mountpoint -q /hd && umount /hd
291 dialog --title " Confirm " --defaultno --yesno \
292 "\n Do you want to format the boot partition\n /dev/$boot?" 8 45
293 [ $? -eq 0 ] && mkdosfs -n EFI /dev/$boot
295 try_mount rw /dev/$boot /hd && break
296 dialog --title " Confirm " --yesno \
297 "\n Cannot mount /dev/$boot\n Do you want to format it?" 8 37
298 [ $? -eq 0 ] && mkdosfs -n EFI /dev/$boot
300 cp -af /grub2/efi /hd
301 mkdir -p /hd/boot/grub
302 grubcfg=/hd/boot/grub/grub.cfg
303 echo -e "set timeout=5\n\n" > $grubcfg
304 echo -e "menuentry \"Android-x86 $VER\" {\n\tsearch --set=root --file /$asrc/kernel\n\tlinux /$asrc/kernel quiet $cmdline \n\tinitrd /$asrc/initrd.img\n}" >> $grubcfg
305 echo -e "menuentry \"Android-x86 $VER (DEBUG mode)\" {\n\tsearch --set=root --file /$asrc/kernel\n\tlinux /$asrc/kernel $cmdline DEBUG=2\n\tinitrd /$asrc/initrd.img\n}" >> $grubcfg
306 if [ -e /hd/EFI/Microsoft/Boot/bootmgfw.efi ]; then
307 echo -e "menuentry \"Windows (UEFI)\" {\n\tsearch --set=root --file /EFI/Microsoft/Boot/bootmgfw.efi\n\tchainloader /EFI/Microsoft/Boot/bootmgfw.efi\n}" >> $grubcfg
309 mountpoint -q /hd && umount /hd
310 try_mount rw /dev/$1 /hd
313 dialog --title " Question " --yesno \
314 "\nDo you want to install /system directory as read-write?\n\nMaking /system be read-write is easier for debugging, but it needs more disk space and longer installation time." 10 61
317 files="mnt/$SRC/kernel mnt/$SRC/initrd.img mnt/$SRC/ramdisk.img"
318 if [ $instal_rw -eq 0 ]; then
319 if [ "$fs" = "vfat" -o "$fs" = "fuseblk" ]; then
320 [ -e /sfs/system.img ] && sysimg="/sfs/system.img" || sysimg="mnt/$SRC/system.*"
322 sysimg="android/system"
325 sysimg="mnt/$SRC/system.*"
327 files="$files $sysimg"
329 for s in `du -sk $files | awk '{print $1}'`; do
336 ( ( cd /; find $files | $CPIO -H newc -o ) | pv -ns ${size}k | ( $CPIO -iud > /dev/null; echo $? > /tmp/result )) 2>&1 \
337 | progress_bar "Installing Android-x86" "Expect to write $size KB..."
338 result=$((`cat /tmp/result`*255))
340 if [ $result -eq 0 ]; then
341 for d in android mnt sfs ./$SRC; do
342 [ -d $d ] && mv $d/* . && rmdir $d
346 [ -d $f ] || chmod 644 $f
359 dialog --infobox "\n Syncing to disk..." 5 27
367 select_dev || rebooting
379 dialog --title " Detecting... " --nocancel --pause "" 8 41 1
388 if [ $retval -eq 255 ]; then
389 dialog --title ' Error! ' --yes-label Retry --no-label Reboot \
390 --yesno '\nInstallation failed! Please check if you have enough free disk space to install Android-x86.' 8 51
391 [ $? -eq 1 ] && rebooting
395 [ -n "$VESA" ] || runit="Run Android-x86"
396 dialog --clear --title ' Congratulations! ' \
397 --menu "\n Android-x86 is installed successfully.\n " 11 51 13 \
398 "$runit" "" "Reboot" "" 2> $tempfile
399 case "`cat $tempfile`" in
403 mountpoint -q /sfs && umount /sfs
404 if [ -e /hd/$asrc/system.sfs ]; then
405 mount -o loop /hd/$asrc/system.sfs /sfs
406 mount -o loop /sfs/system.img system
407 elif [ -e /hd/$asrc/system.img ]; then
408 mount -o loop /hd/$asrc/system.img system
410 mount --bind /hd/$asrc/system system
412 if [ -d /hd/$asrc/data ]; then
413 mount --bind /hd/$asrc/data data
414 elif [ -e /hd/$asrc/data.img ]; then
415 mount -o loop /hd/$asrc/data.img data