#
# By Chih-Wei Huang <cwhuang@linux.org.tw>
-# Last updated 2018/01/16
+# Last updated 2018/01/26
#
# License: GNU Public License
# We explicitely grant the right to use the scripts
reboot -f
}
+auto_answer()
+{
+ echo "$answer" > $tempfile
+ unset answer
+ test "`cat $tempfile`" != "0"
+}
+
+set_answer_if_auto()
+{
+ [ -n "$AUTO_INSTALL" ] && answer="$1"
+}
+
+adialog()
+{
+ if [ -n "$answer" ]; then
+ auto_answer
+ else
+ dialog "$@" 2> $tempfile
+ fi
+}
+
choose()
{
- dialog --clear --title " $1 " \
- --menu "$2" 21 79 13 --file $menufile 2> $tempfile
+ adialog --clear --title " $1 " --menu "$2" 21 79 13 --file $menufile
retval=$?
choice=`cat $tempfile`
done
}
+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
+ [ $? -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 --new=1::+260M --typecode=1:EF00 --largest-new=2 --typecode=2:8300 /dev/$1
+ p=2
+ fi > /dev/tty6
+
+ while sleep 1; do
+ answer=`find_partition $1 $p`
+ [ -n "$answer" ] && break
+ done
+}
+
partition_drive()
{
echo -n > $menufile
[ "`basename $i`" = "$booted_from" -o -d $i/$booted_from ] && echo -n " *" >> $menufile
echo '"' >> $menufile
done
- count=`wc -l $menufile | awk '{ print $1 }'`
+ count=`wc -l < $menufile`
if [ $count -eq 0 ]; then
dialog --title " Error " --msgbox \
"\nOK. There is no hard drive to edit partitions." 8 49
return 255
fi
- if [ $count -eq 1 ]; then
- choice=`awk '{ print $1 }' $menufile`
+
+ if [ $count -eq 1 -o "$AUTO_INSTALL" = "force" ]; then
+ drive=1
+ else
+ drive=`basename $AUTO_INSTALL`
+ fi
+ choice=`awk -v n=$drive '{ if (n == NR || n == $1) print $1 }' $menufile`
+ if [ -b /dev/$choice ]; then
retval=0
else
choose "Choose Drive" "Please select a drive to edit partitions:\n\n* - Installer source"
fi
if [ $retval -eq 0 ]; then
+ if [ -n "$AUTO_INSTALL" ]; then
+ 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
{
local cmd
echo -e '"Do not format" ""\next4 ""\nntfs ""\nfat32 ""' > $menufile
+ set_answer_if_auto $FORCE_FORMAT
choose "Choose filesystem" "Please select a filesystem to format $1:"
case "$choice" in
ext4)
;;
esac
if [ -n "$cmd" ]; then
- dialog --title " Confirm " --defaultno --yesno \
- "\n You chose to format $1 to $choice.\n All data in that partition will be LOST.\n\n Are you sure to format the partition $1?" 10 51
+ [ -n "$AUTO_INSTALL" ] || dialog --title " Confirm " --defaultno --yesno \
+ "\n You chose to format $1 to $choice.\n All data in that partition will be LOST.\n\n Are you sure to format the partition $1?" 10 59
[ $? -ne 0 ] && return 1
$cmd Android-x86 /dev/$1 | awk '{
# FIXME: very imprecise progress
else
continue
fi
- dialog --title " Question " --yesno \
+ set_answer_if_auto 1
+ adialog --title " Question " --yesno \
"\nAn older version $v is detected.\nWould you like to upgrade it?" 8 51
if [ $? -eq 0 ]; then
mv $prev $1
done
cd /
mountpoint -q /hd && umount /hd
+ [ -n "$AUTO_UPDATE" ] && FORCE_FORMAT=no || FORCE_FORMAT=ext4
while [ 1 ]; do
format_fs $1
try_mount rw /dev/$1 /hd && break
dialog --clear --title " Error " --defaultno --yesno \
"\n Cannot mount /dev/$1\n Do you want to format it?" 8 37
[ $? -ne 0 ] && return 255
+ FORCE_FORMAT=ext4
done
fs=`cat /proc/mounts | grep /dev/$1 | awk '{ print $3 }'`
- 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*\)||; s|\(iso-scan/filename=\S\+\?\s*\)||; s|[[:space:]]*$||" /proc/cmdline`
+ cmdline=`sed "s|\(initrd.*img\s*\)||; s|quiet\s*||; s|\(vga=\w\+\?\s*\)||; s|\(DPI=\w\+\?\s*\)||; s|\(AUTO_INSTALL=\w\+\?\s*\)||; s|\(INSTALL=\w\+\?\s*\)||; s|\(SRC=\S\+\?\s*\)||; s|\(DEBUG=\w\+\?\s*\)||; s|\(BOOT_IMAGE=\S\+\?\s*\)||; s|\(iso-scan/filename=\S\+\?\s*\)||; s|[[:space:]]*$||" /proc/cmdline`
[ -n "$INSTALL_PREFIX" ] && asrc=$INSTALL_PREFIX || asrc=android-$VER
- [ -z "$efi" ] && dialog --title " Confirm " --no-label Skip --defaultno --yesno \
+ set_answer_if_auto 1
+ [ -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
[ $? -ne 0 ] && return 255
fi
- [ -n "$efi" ] && dialog --title " Confirm " --no-label Skip --defaultno --yesno \
+ [ -n "$efi" ] && adialog --title " Confirm " --no-label Skip --defaultno --yesno \
"\n Do you want to install EFI GRUB2?" 7 39
if [ $? -eq 0 ]; then
for i in `list_disks`; do
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
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
# Checking for old EFI entries, removing them and adding new depending on bitness
efibootmgr | grep -Eo ".{0,6}Android-x86" | cut -c1-4 > /tmp/efientries
if [ -s /tmp/efientries ]; then
- dialog --title " Question " --defaultno --yesno "\nEFI boot entries for previous Android-x86 installations were found.\n\nDo you wish to delete them?" 10 61
+ 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
[ $? -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
fi
- dialog --title " Question " --defaultno --yesno \
+ 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=$?
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" "Expect to write $size KB..."
+ | progress_bar "Installing Android-x86 to $1" "Expect to write $size KB..."
result=$((`cat /tmp/result`*255))
if [ $result -eq 0 ]; then
install_hd()
{
+ 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
+ ;;
+ *)
+ [ -z "$answer" ] && set_answer_if_auto Create
+ ;;
+ esac
+
select_dev || rebooting
retval=1
case "$choice" in