OSDN Git Service

Add auto installation function
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 26 Jan 2018 09:19:05 +0000 (17:19 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 26 Jan 2018 09:19:05 +0000 (17:19 +0800)
A new variable AUTO_INSTALL is introduced to kernel cmdline:

* AUTO_INSTALL=n - auto install Android-x86 to the n-th disk or /dev/$n
                   if n is a device node name. If the specified disk
                   doesn't exist, the installer will ask you to select
                   the target disk.

* AUTO_INSTALL=force - auto install Android-x86 to the first disk
                   without any confirmation.

* AUTO_INSTALL=update - auto update Android-x86 to the first partition
                   with label Android-x86, or the first ext4 partition
                   and install boot loader.

boot/isolinux/isolinux.cfg
initrd/init
install/grub2/efi/boot/android.cfg
install/scripts/1-install

index 48ca8fd..d958dc1 100644 (file)
@@ -27,6 +27,11 @@ label debug
        append initrd=/initrd.img CMDLINE DEBUG=2 SRC= DATA=
 
 label install
-       menu label Installation - ^Install Android-x86 to harddisk
+       menu label ^Installation - Install Android-x86 to harddisk
        kernel /kernel
        append initrd=/initrd.img CMDLINE INSTALL=1 DEBUG=
+
+label auto_install
+       menu label ^Audo_Installation - Auto Install to harddisk
+       kernel /kernel
+       append initrd=/initrd.img CMDLINE AUTO_INSTALL=1 DEBUG=
index 4916241..fac5485 100755 (executable)
@@ -3,7 +3,7 @@
 # By Chih-Wei Huang <cwhuang@linux.org.tw>
 # and Thorsten Glaser <tg@mirbsd.org>
 #
-# Last updated 2018/01/12
+# Last updated 2018/01/26
 #
 # License: GNU Public License
 # We explicitely grant the right to use the scripts
 
 PATH=/sbin:/bin:/system/bin:/system/xbin; export PATH
 
+# auto installation
+[ -n "$AUTO_INSTALL" ] && INSTALL=1
+
 # configure debugging output
-if [ -n "$DEBUG" ]; then
+if [ -n "$DEBUG" -o -n "$INSTALL" ]; then
        LOG=/tmp/log
        set -x
 else
index dfe5cc1..d7a02a5 100644 (file)
@@ -39,6 +39,7 @@ add_entry "$live" quiet
 add_entry "$debug_mode" DEBUG=2
 if [ "$installation" ]; then
        add_entry "$installation" INSTALL=1
+       add_entry "Auto $installation" AUTO_INSTALL=1
 fi
 
 if [ "$grub_cpu" = "i386" ]; then
index 9e6830a..04fe390 100644 (file)
@@ -1,6 +1,6 @@
 #
 # 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
@@ -20,10 +20,30 @@ rebooting()
        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`
@@ -46,6 +66,27 @@ list_disks()
        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
@@ -67,19 +108,29 @@ partition_drive()
                [ "`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
@@ -154,6 +205,7 @@ format_fs()
 {
        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)
@@ -169,8 +221,8 @@ format_fs()
                        ;;
        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
@@ -276,7 +328,8 @@ try_upgrade()
                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
@@ -311,19 +364,22 @@ install_to()
        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
@@ -337,7 +393,7 @@ install_to()
                [ $? -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
@@ -354,6 +410,7 @@ install_to()
                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
@@ -384,13 +441,15 @@ install_to()
                # 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=$?
 
@@ -414,7 +473,7 @@ install_to()
        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
@@ -444,6 +503,17 @@ install_to()
 
 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