diff --git a/packages/tools/installer/scripts/installer b/packages/tools/installer/scripts/installer index 16a7e75153..56b5a1b3d7 100755 --- a/packages/tools/installer/scripts/installer +++ b/packages/tools/installer/scripts/installer @@ -50,6 +50,9 @@ # cumulative, e.g., "\Zb\Z1" makes the following text bold (perhaps bright) # red. Restore normal settings with "\Zn". +# disable Ctrl+C - can be very dangerous +trap '' 2 + [ -f /etc/installer.conf ] && . /etc/installer.conf || exit 0 dbglg() { @@ -171,22 +174,23 @@ do_install_mbr() { } do_install_quick() { - # show menu MSG_TITLE="\Z4[ QUICK INSTALL MENU ]\Zn" MSG_MENU="\nUse the up/down arrows to select the correct device.\n\n Please select a device:" MSG_CANCEL="Back" + DIALOG_OPTIONS="--defaultno" create_device_list dialog --colors --backtitle "$BACKTITLE" --cancel-label "$MSG_CANCEL" \ - --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \ + $DIALOG_OPTIONS --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \ $DEVICE_LIST 2> $TMPDIR/device_for_install # now we must do everything case $? in 0) INSTALL_DEVICE=$(cat "$TMPDIR/device_for_install") + INSTALL_DEVICE_FULL=$(echo $DEVICE_LIST | sed "s|.*$INSTALL_DEVICE \([^ ]*\).*|$INSTALL_DEVICE \1|") prompt_gpt prompt_ssh @@ -197,6 +201,25 @@ do_install_quick() { EXTLINUX_SSH="ssh" fi + # check for confirmation (twice!) + MSG_TITLE="\Z1[ Confirmation before installing ]\Zn" + MSG_DETAIL="\nIf you continue the target disk will be wiped out:\n\n$INSTALL_DEVICE_FULL\n\n" + DIALOG_OPTIONS="--defaultno" + dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \ + $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0 + if [ $? -ne 0 ]; then + menu_main + fi + + MSG_TITLE="\Z1[ Confirmation before installing ]\Zn" + MSG_DETAIL="\nThis is last chance to abort the installation!\n\nIf you continue the target disk will be wiped out:\n\n$INSTALL_DEVICE_FULL\n\n\n" + DIALOG_OPTIONS="--defaultno" + dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \ + $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0 + if [ $? -ne 0 ]; then + menu_main + fi + # remove all partitions msg_progress_install "1" "get all partitions $INSTALL_DEVICE" get_partition $INSTALL_DEVICE @@ -316,6 +339,124 @@ do_install_quick() { esac } +do_install_custom() { + # show menu + MSG_TITLE="\Z4[ CUSTOM INSTALL MENU ]\Zn" + MSG_MENU="\nUse the up/down arrows to select the correct partition where you want to overwrite KERNEL and SYSTEM files.\n\n Please select a partition:" + MSG_CANCEL="Back" + DIALOG_OPTIONS="--defaultno" + + get_device_unmount + + if [ "$DEVICES" = "" ]; then + msg_no_device + fi + + PARTITION_LIST="" + for device in $DEVICES; do + get_partition $device + for partition in $PARTITIONS; do + LABEL=$(tune2fs -l $device$partition | awk 'BEGIN {FS=":"} /Filesystem volume name/ {gsub(/ /,"",$2); print $2}') + if [ "$LABEL" = "$DISKLABEL_SYSTEM" ]; then + DEVICE_MODEL=$(parted -s $device -m print | grep ^$device | cut -f7 -d ":" | sed "s/;//") + DEVICE_SIZE=$(parted -s $device -m print | grep ^$device | cut -f2 -d ":") + DEVICE_NAME=$(echo $DEVICE_MODEL ${DEVICE_SIZE} | sed 's/ /_/g') + PARTITION_LIST="$PARTITION_LIST $device$partition $DEVICE_NAME" + fi + done + done + + if [ "$PARTITION_LIST" = "" ]; then + msg_no_device + fi + + dialog --colors --backtitle "$BACKTITLE" --cancel-label "$MSG_CANCEL" \ + $DIALOG_OPTIONS --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \ + $PARTITION_LIST 2> $TMPDIR/device_for_install + + # now we must do everything + case $? in + 0) + INSTALL_PARTITION=$(cat "$TMPDIR/device_for_install") + INSTALL_PARTITION_FULL=$(echo $PARTITION_LIST | sed "s|.*$INSTALL_PARTITION \([^ ]*\).*|$INSTALL_PARTITION \1|") + + # check for confirmation (twice!) + MSG_TITLE="\Z1[ Confirmation before copying ]\Zn" + MSG_DETAIL="\nIf you continue the target partition will be\noverwritten with new KERNEL and SYSTEM files:\n\n$INSTALL_PARTITION_FULL\n\n" + DIALOG_OPTIONS="--defaultno" + dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \ + $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0 + if [ $? -ne 0 ]; then + menu_main + fi + + MSG_TITLE="\Z1[ Confirmation before copying ]\Zn" + MSG_DETAIL="\nThis is last chance to abort the copying!\n\nIf you continue the target partition will be\noverwritten with new KERNEL and SYSTEM files:\n\n$INSTALL_PARTITION_FULL\n\n\n" + DIALOG_OPTIONS="--defaultno" + dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" \ + $DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0 + if [ $? -ne 0 ]; then + menu_main + fi + + # mount system partition + msg_progress_install "5" "creating $TMPDIR/part1" + mkdir -p $TMPDIR/part1 >> $LOGFILE 2>&1 + + msg_progress_install "10" "mounting $INSTALL_PARTITION to $TMPDIR/part1" + mount -t ext4 $INSTALL_PARTITION $TMPDIR/part1 >> $LOGFILE 2>&1 + + # check for enough target space + msg_progress_install "15" "checking for space on $INSTALL_PARTITION" + + KERNEL_SIZE=$(stat -t /flash/KERNEL | awk '{print $2}') + SYSTEM_SIZE=$(stat -t /flash/SYSTEM | awk '{print $2}') + SRC_SIZE=$(( $KERNEL_SIZE + $SYSTEM_SIZE )) + + DEST_SIZE=$(df $TMPDIR/part1 | awk '/[0-9]%/{print $4}') + DEST_SIZE=$(( $DEST_SIZE * 1024 )) + if [ -f $TMPDIR/part1/KERNEL ]; then + KERNEL_SIZE=$(stat -t $TMPDIR/part1/KERNEL | awk '{print $2}') + DEST_SIZE=$(( $DEST_SIZE + $KERNEL_SIZE )) + fi + if [ -f $TMPDIR/part1/SYSTEM ]; then + SYSTEM_SIZE=$(stat -t $TMPDIR/part1/SYSTEM | awk '{print $2}') + DEST_SIZE=$(( $DEST_SIZE + $SYSTEM_SIZE )) + fi + + if [ $SRC_SIZE -ge $DEST_SIZE ]; then + umount $TMPDIR/part1 >> $LOGFILE 2>&1 + rmdir $TMPDIR/part1 >> $LOGFILE 2>&1 + msg_target_space + menu_main + fi + + # install system files + msg_progress_install "20" "installing Kernel" + cp /flash/KERNEL $TMPDIR/part1 >> $LOGFILE 2>&1 + + msg_progress_install "40" "installing System" + cp /flash/SYSTEM $TMPDIR/part1 >> $LOGFILE 2>&1 + sync + + # umount system partition, remove mountpoint + msg_progress_install "95" "unmount $TMPDIR/part1" + umount $TMPDIR/part1 >> $LOGFILE 2>&1 + + msg_progress_install "100" "remove $TMPDIR/part1" + rmdir $TMPDIR/part1 >> $LOGFILE 2>&1 + + menu_main + ;; + 1) + menu_main + ;; + 255) + do_poweroff + ;; + esac +} + msg_not_implemented() { # show a dialog that this function is not yet implemented MSG_TITLE="\Z2[ WORK IN PROGRESS ]\Zn" @@ -350,6 +491,16 @@ msg_no_device() { menu_main } +msg_target_space() { + # show an error dialog for missing space + MSG_TITLE="\Z1[ TARGET SPACE ]\Zn" + MSG_INFOBOX="\nNot enough target space!\nCopying aborted.\n" + + dialog --colors --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_INFOBOX" 8 70 + + menu_main +} + msg_install_ready() { # show a dialog that we have installed MSG_TITLE="\Z1[ INFORMATION ]\Zn" @@ -452,7 +603,7 @@ menu_main() { ITEM_MAINMENU=$(cat "$TMPDIR/mainmenu") case $ITEM_MAINMENU in 1) do_install_quick; break;; - 2) menu_custom; break;; + 2) do_install_custom; break;; 3) menu_setup; break;; 4) menu_bios; break;; 5) logfile_show; break;; @@ -503,12 +654,6 @@ menu_bios() { esac } -menu_custom() { - # TODO: show the installmenu - msg_not_implemented - menu_main -} - bios_backup() { # create a backup of the installed bios if [ "$BIOS_UPDATE" = "yes" -a -f "$BIOS_FILE" ]; then