#
# By Chih-Wei Huang <cwhuang@linux.org.tw>
-# Last updated 2018/01/26
#
# License: GNU Public License
# We explicitely grant the right to use the scripts
menufile=/tmp/menu-$$
CPIO=cpio
+OS_TITLE=${OS_TITLE:-Android-x86}
rebooting()
{
auto_partition()
{
[ "$AUTO_INSTALL" = "force" ] || dialog --title " Auto Installer " --defaultno --yesno \
- "\nYou have chosen the AUTO installation.\n\nThe installer will erase the whole /dev/$1 and install Android-x86 to it.\n\nThis is the last confirmation. Are you sure to do so?" 12 61
+ "\nYou have chosen the AUTO installation.\n\nThe installer will erase the whole /dev/$1 and install $OS_TITLE to it.\n\nThis is the last confirmation. Are you sure to do so?" 12 61
[ $? -ne 0 ] && rebooting
if [ -z "$efi" ]; then
echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/$1
p=1
else
- sgdisk --zap-all /dev/$1 > /dev/tty6
+ sgdisk --zap-all /dev/$1
sgdisk --new=1::+260M --typecode=1:EF00 --largest-new=2 --typecode=2:8300 /dev/$1
p=2
fi > /dev/tty6
answer=`find_partition $1 $p`
[ -n "$answer" ] && break
done
+ [ -n "$efi" ] && mkdosfs -n EFI /dev/`find_partition $1 1`
}
partition_drive()
auto_partition $choice
return 1
fi
- dialog --title " Confirm " --defaultno --yesno "\n Do you want to use GPT?" 7 29
- if [ $? -eq 0 ]; then
- cgdisk /dev/$choice
+ if fdisk -l /dev/$choice | grep -q GPT; then
+ part_tool=cgdisk
+ elif fdisk -l /dev/$choice | grep -q doesn.t; then
+ dialog --title " Confirm " --defaultno --yesno "\n Do you want to use GPT?" 7 29
+ [ $? -eq 0 ] && part_tool=cgdisk || part_tool=cfdisk
else
- cfdisk /dev/$choice
+ part_tool=cfdisk
fi
+ $part_tool /dev/$choice
if [ $? -eq 0 ]; then
retval=1
else
} END {
printf("\"\" \"\"\n\"Create/Modify partitions\" \"\"\n\"Detect devices\" \"\"")
}' > $menufile
- choose "Choose Partition" "Please select a partition to install Android-x86:\n\nRecommended minimum free space - 4GB | Optimum free space >= 8GB\n\nPartition | Filesystem | Label | Size | Drive name/model"
+ choose "Choose Partition" "Please select a partition to install $OS_TITLE:\n\nRecommended minimum free space - 4GB | Optimum free space >= 8GB\n\nPartition | Filesystem | Label | Size | Drive name/model"
return $retval
}
[ -n "$VESA" ] && vga=" vga=788 modeset=0"
echo -e "${GRUB_OPTIONS:-default=0\ntimeout=6\nsplashimage=/grub/android-x86.xpm.gz\n}root (hd0,$1)\n" > $menulst
- create_entry "Android-x86 $VER" quiet $cmdline
- create_entry "Android-x86 $VER (Debug mode)" $cmdline DEBUG=2
- create_entry "Android-x86 $VER (Debug nomodeset)" nomodeset $cmdline DEBUG=2
- create_entry "Android-x86 $VER (Debug video=LVDS-1:d)" video=LVDS-1:d $cmdline DEBUG=2
+ create_entry "$OS_TITLE $VER" quiet $cmdline
+ create_entry "$OS_TITLE $VER (Debug mode)" $cmdline DEBUG=2
+ create_entry "$OS_TITLE $VER (Debug nomodeset)" nomodeset $cmdline DEBUG=2
+ create_entry "$OS_TITLE $VER (Debug video=LVDS-1:d)" video=LVDS-1:d $cmdline DEBUG=2
}
create_winitem()
losetup -d /dev/loop7
}
+gen_img()
+{
+ if [ "$fs" = "vfat" ]; then
+ ( dd bs=1M count=$1 if=/dev/zero | pv -ns $1m | dd of=$2 ) 2>&1 \
+ | progress_bar "Creating `basename $2`" "Expect to write $1 MB..."
+ else
+ dd if=/dev/zero bs=1 count=0 seek=$1M of=$2
+ fi
+}
+
create_img()
{
bname=`basename $2`
dialog --title " Question " --nook --nocancel --inputbox \
"\nPlease input the size of the $bname in MB:" 8 63 $1 2> $tempfile
size=`cat $tempfile`
- [ 0$size -le 0 ] && size=1024
- ( dd bs=1M count=$size if=/dev/zero | pv -ns ${size}m | dd of=$2 ) 2>&1 \
- | progress_bar "Creating $bname" "Expect to write $size MB..."
+ [ 0$size -le 0 ] && size=2048
+ gen_img $size $2
}
create_data_img()
{
dialog --title " Confirm " --yesno \
- "\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
+ "\nThe installer is going to create a disk image to save the user data. At least 2048MB free disk space is recommended.\n\nAre you sure to create the image?" 11 62
if [ $? -eq 0 ]; then
- if create_img 512 data.img; then
+ if create_img 2048 data.img; then
losetup /dev/loop6 data.img
make_ext4fs -L /data /dev/loop6 > /dev/tty6
fi
try_upgrade()
{
[ -d $1 ] && return
- PREV_VERS="$PREV_VERS 7.1-rc2 7.1-rc1 6.0-r3 6.0-r2 6.0-r1 6.0-rc2 6.0-rc1 5.1-rc1 4.4-r5 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"
+ PREV_VERS="$PREV_VERS 7.1-r2 7.1-r1 7.1-rc2 7.1-rc1 6.0-r3 6.0-r2 6.0-r1 6.0-rc2 6.0-rc1 5.1-rc1 4.4-r5 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"
for v in $PREV_VERS; do
local prev
if [ -d hd/$v ]; then
disk=$(basename `dirname $part`)
}
-install_to()
+wait_for_device()
{
local t=`echo /sys/block/*/$1/partition`
[ -f "$t" ] || return 1
echo add > `dirname $t`/uevent
sleep 1
done
+}
+
+install_to()
+{
+ wait_for_device $1 || return 1
cd /
mountpoint -q /hd && umount /hd
[ -n "$AUTO_UPDATE" ] && FORCE_FORMAT=no || FORCE_FORMAT=ext4
[ -z "$efi" ] && adialog --title " Confirm " --no-label Skip --defaultno --yesno \
"\n Do you want to install boot loader GRUB?" 7 47
if [ $? -eq 0 ]; then
- cp -af /grub /hd
get_part_info $1
+ if fdisk -l /dev/$disk | grep -q GPT; then
+ umount /hd
+ dialog --title " Warning " --defaultno --yesno \
+ "\nFound GPT on /dev/$disk. The legacy GRUB can't be installed to GPT. Do you want to convert it to MBR?\n\nWARNING: This is a dangerous operation. You should backup your data first." 11 63
+ [ $? -eq 1 ] && rebooting
+ plist=$(sgdisk --print /dev/$disk | awk '/^ / { printf "%s:", $1 }' | sed 's/:$//')
+ sgdisk --gpttombr=$plist /dev/$disk > /dev/tty6
+ until try_mount rw /dev/$1 /hd; do
+ sleep 1
+ done
+ fi
+ cp -af /grub /hd
p=$(($p-1))
create_menulst $p
create_winitem $1 $d
[ $? -ne 0 ] && return 255
fi
- [ -n "$efi" ] && adialog --title " Confirm " --no-label Skip --defaultno --yesno \
+ [ -n "$efi" ] && adialog --title " Confirm " --no-label Skip --yesno \
"\n Do you want to install EFI GRUB2?" 7 39
if [ $? -eq 0 ]; then
- for i in `list_disks`; do
+ [ -z "$AUTO_INSTALL" -o -n "$AUTO_UPDATE" ] && for i in `list_disks`; do
disk=`basename $i`
esp=`sgdisk --print /dev/$disk 2> /dev/null | grep EF00 | awk '{print $1}'`
[ -n "$esp" ] && boot=`find_partition $disk $esp` && break
done
if [ -z "$esp" ]; then
get_part_info $1
- boot=`basename $(blkid /dev/$disk* | grep vfat | cut -d: -f1 | head -1)`
- [ -z "$boot" ] && boot=`find_partition $disk 1`
+ boot=$(blkid /dev/$disk* | grep vfat | cut -d: -f1 | head -1)
+ [ -z "$boot" ] && boot=`find_partition $disk 1` || boot=`basename $boot`
esp=`cat /sys/block/$disk/$boot/partition`
fi
mkdir -p efi
mountpoint -q efi && umount efi
- while [ 1 ]; do
- [ -n "$AUTO_INSTALL" -a -z "$AUTO_UPDATE" ] && mkdosfs -n EFI /dev/$boot
- try_mount rw /dev/$boot efi && break
+ wait_for_device $boot
+ until try_mount rw /dev/$boot efi; do
dialog --title " Confirm " --defaultno --yesno "\n Cannot mount /dev/$boot.\n Do you want to format it?" 8 37
[ $? -eq 0 ] && mkdosfs -n EFI /dev/$boot
done
grubcfg=efi/boot/grub/x86_64-efi/grub.cfg
bootefi=BOOTx64.EFI
fi
- mkdir -p `dirname $grubcfg` efi/efi/Android
- cp -af grub2/efi/boot/* efi/efi/Android
- sed -i "s|VER|$VER|; s|CMDLINE|$cmdline|" efi/efi/Android/android.cfg
+ if [ -d efi/efi/boot -a ! -s efi/efi/boot/android.cfg ]; then
+ efidir=/efi/Android
+ else
+ efidir=/efi/boot
+ rm -rf efi/efi/Android
+ fi
+ mkdir -p `dirname $grubcfg` efi$efidir
+ cp -af grub2/efi/boot/* efi$efidir
+ sed -i "s|VER|$VER|; s|CMDLINE|$cmdline|; s|OS_TITLE|$OS_TITLE|" efi$efidir/android.cfg
[ -s efi/boot/grub/grubenv ] || ( printf %-1024s "# GRUB Environment Block%" | sed 's/k%/k\n/; s/ /###/g' > efi/boot/grub/grubenv )
echo -e 'set timeout=5\nset debug_mode="(DEBUG mode)"' > $grubcfg
# Our grub-efi doesn't support ntfs directly.
# Copy boot files to ESP so grub-efi could read them
if [ "$fs" = "fuseblk" ]; then
- cp -f src/kernel src/initrd.img efi/efi/Android
- echo -e "set kdir=/efi/Android\nset src=SRC=/$asrc" >> $grubcfg
+ cp -f src/kernel src/initrd.img efi$efidir
+ echo -e "set kdir=$efidir\nset src=SRC=/$asrc" >> $grubcfg
else
echo -e "set kdir=/$asrc" >> $grubcfg
fi
efibootmgr | grep -Eo ".{0,6}Android-x86" | cut -c1-4 > /tmp/efientries
if [ -s /tmp/efientries ]; then
set_answer_if_auto 1
- adialog --title " Question " --defaultno --yesno "\nEFI boot entries for previous Android-x86 installations were found.\n\nDo you wish to delete them?" 10 61
+ adialog --title " Question " --yesno "\nEFI boot entries for previous Android-x86 installations were found.\n\nDo you wish to delete them?" 10 61
[ $? -eq 0 ] && while read entry; do efibootmgr -Bb "$entry" > /dev/tty4 2>&1; done < /tmp/efientries
fi
- efibootmgr -v -c -d /dev/$disk -p $esp -L "Android-x86 $VER" -l /efi/Android/$bootefi > /dev/tty4 2>&1
+ efibootmgr -v -c -d /dev/$disk -p $esp -L "Android-x86 $VER" -l $efidir/$bootefi > /dev/tty4 2>&1
+
+ if [ -s efi/startup.nsh ]; then
+ sed -i "s|\\\\efi\\\\Android|$efidir|; s|/|\\\\|g" efi/startup.nsh
+ else
+ echo $efidir/$bootefi | sed 's|/|\\|g' > efi/startup.nsh
+ fi
fi
set_answer_if_auto 0
adialog --title " Question " --defaultno --yesno \
"\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
- instal_rw=$?
-
- files="mnt/$SRC/kernel mnt/$SRC/initrd.img mnt/$SRC/$RAMDISK"
- if [ $instal_rw -eq 0 ]; then
- if [ "$fs" = "vfat" -o "$fs" = "fuseblk" ]; then
- [ -e /sfs/system.img ] && sysimg="/sfs/system.img" || sysimg="mnt/$SRC/system.*"
- else
- sysimg="android/system"
- fi
+ if [ $? -eq 0 -a -e /sfs/system.img ]; then
+ sysimg="/sfs/system.img"
else
sysimg="mnt/$SRC/system.*"
fi
- files="$files $sysimg"
+ files="mnt/$SRC/kernel mnt/$SRC/initrd.img mnt/$SRC/$RAMDISK $sysimg"
size=0
for s in `du -sk $files | awk '{print $1}'`; do
size=$(($size+$s))
cd hd/$asrc
rm -rf system*
( ( cd /; find $files | $CPIO -H newc -o ) | pv -ns ${size}k | ( $CPIO -iud > /dev/null; echo $? > /tmp/result )) 2>&1 \
- | progress_bar "Installing Android-x86 to $1" "Expect to write $size KB..."
+ | progress_bar "Installing $OS_TITLE to $1" "Expect to write $size KB..."
result=$((`cat /tmp/result`*255))
if [ $result -eq 0 ]; then
dialog --infobox "\n Syncing to disk..." 5 27
sync
+ cd /
return $result
}
{
case "$AUTO_INSTALL" in
[Uu]*)
- answer=`basename $(blkid | grep -v loop | sort | grep Android-x86 | cut -d: -f1 | head -1)`
- [ -z "$answer" ] && answer=`basename $(blkid | grep -v loop | sort | grep ext4 | cut -d: -f1 | head -1)`
- AUTO_UPDATE=$answer
+ answer=${AUTO_UPDATE:-$(blkid | grep -v loop | grep -v iso9660 | sort | grep Android-x86 | cut -d: -f1 | head -1)}
+ answer=${answer:-$(blkid | grep -v loop | sort | grep ext4 | cut -d: -f1 | head -1)}
+ [ -b "$answer" -o -b /dev/$answer ] && answer=`basename $answer` || answer=
+ AUTO_UPDATE=${answer:-$AUTO_UPDATE}
;;
*)
[ -z "$answer" ] && set_answer_if_auto Create
until install_hd; do
if [ $retval -eq 255 ]; then
dialog --title ' Error! ' --yes-label Retry --no-label Reboot \
- --yesno '\nInstallation failed! Please check if you have enough free disk space to install Android-x86.' 8 51
+ --yesno "\nInstallation failed! Please check if you have enough free disk space to install $OS_TITLE." 8 51
[ $? -eq 1 ] && rebooting
fi
done
- [ -n "$VESA" ] || runit="Run Android-x86"
+ [ -n "$VESA" ] || runit="Run $OS_TITLE"
dialog --clear --title ' Congratulations! ' \
- --menu "\n Android-x86 is installed successfully.\n " 11 51 13 \
+ --menu "\n $OS_TITLE is installed successfully.\n " 11 51 13 \
"$runit" "" "Reboot" "" 2> $tempfile
case "`cat $tempfile`" in
Run*)