installer: remove unused functions, pointless case, recursive calls and faulty breaks

I suspect the recursive calls were to work around the error caused by break
being called in a case statement which itself is within a while loop - the break
causes the while loop to terminate, bringing the installer to a grinding halt... whoops.

Now, menu_main() is called only from the main process loop, which we don't exit accidentally.

I've removed an entire case statement from do_install_quick() as this function either
performs an installation, or it doesn't - the case statement is pointless.

Due to the removal of whitespace, add ?w=1 in github.com when reviewing.
This commit is contained in:
MilhouseVH 2018-05-16 00:17:48 +01:00
parent c1167e0bcb
commit d2ab6680a7

View File

@ -103,6 +103,7 @@ create_device_list() {
if [ "$DEVICES" = "" ]; then
msg_no_device
return 1
fi
for i in $DEVICES; do
@ -111,6 +112,7 @@ create_device_list() {
DEVICE_NAME=$(echo $DEVICE_MODEL ${DEVICE_SIZE} | sed 's/ /_/g')
DEVICE_LIST="$DEVICE_LIST $i $DEVICE_NAME"
done
return 0
}
do_install_quick() {
@ -119,137 +121,132 @@ do_install_quick() {
MSG_MENU="\nUse the up/down arrows to select the device you wish to install to.\n\nPlease select a device:"
MSG_CANCEL="Back"
create_device_list
create_device_list || return
whiptail --backtitle "$BACKTITLE" --cancel-button "$MSG_CANCEL" \
$DIALOG_OPTIONS --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \
$DEVICE_LIST 2> $TMPDIR/device_for_install
$DIALOG_OPTIONS --title "$MSG_TITLE" --menu "$MSG_MENU" 20 50 5 \
$DEVICE_LIST 2> $TMPDIR/device_for_install
[ $? -ne 0 ] && return
# 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|")
INSTALL_DEVICE=$(cat "$TMPDIR/device_for_install")
INSTALL_DEVICE_FULL=$(echo $DEVICE_LIST | sed "s|.*$INSTALL_DEVICE \([^ ]*\).*|$INSTALL_DEVICE \1|")
case $INSTALL_DEVICE in
"/dev/mmcblk"*|"/dev/nvme"*)
PART1="p1"
PART2="p2"
;;
*)
PART1="1"
PART2="2"
;;
esac
case $INSTALL_DEVICE in
"/dev/mmcblk"*|"/dev/nvme"*)
PART1="p1"
PART2="p2"
;;
*)
PART1="1"
PART2="2"
;;
esac
prompt_gpt
prompt_backup_unpack
prompt_gpt
prompt_backup_unpack
# check for confirmation (twice!)
MSG_TITLE="Confirmation before installing"
MSG_DETAIL="\nIf you continue the contents of the target disk will be wiped out:\n\n$INSTALL_DEVICE_FULL\n\n"
DIALOG_OPTIONS="--defaultno"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
$DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
if [ $? -ne 0 ]; then
menu_main
fi
# check for confirmation (twice!)
MSG_TITLE="Confirmation before installing"
MSG_DETAIL="\nIf you continue the contents of the target disk will be wiped out:\n\n$INSTALL_DEVICE_FULL\n\n"
DIALOG_OPTIONS="--defaultno"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
$DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
[ $? -ne 0 ] && return
MSG_TITLE="Confirmation before installing"
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"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
$DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
if [ $? -ne 0 ]; then
menu_main
fi
MSG_TITLE="Confirmation before installing"
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"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" \
$DIALOG_OPTIONS --yesno "$MSG_DETAIL" 0 0
[ $? -ne 0 ] && return
# start the progress bar (whiptail --gauge)
{
# remove all partitions
msg_progress_install "1" "Get all partitions $INSTALL_DEVICE"
get_partition $INSTALL_DEVICE
# start the progress bar (whiptail --gauge)
{
# remove all partitions
msg_progress_install "1" "Get all partitions $INSTALL_DEVICE"
get_partition $INSTALL_DEVICE
msg_progress_install "5" "Wiping disk $INSTALL_DEVICE"
dd if=/dev/zero of=$INSTALL_DEVICE bs=4096 count=1024 2>>$LOGFILE
msg_progress_install "5" "Wiping disk $INSTALL_DEVICE"
dd if=/dev/zero of=$INSTALL_DEVICE bs=4096 count=1024 2>>$LOGFILE
# create 2 new partitions (first $PARTSIZE_SYSTEM, second rest)
msg_progress_install "7" "Creating label on $INSTALL_DEVICE"
if [ "$GPT" = "1" ]; then
parted -s $INSTALL_DEVICE mklabel gpt >> $LOGFILE 2>&1
else
parted -s $INSTALL_DEVICE mklabel msdos >> $LOGFILE 2>&1
fi
# create 2 new partitions (first $PARTSIZE_SYSTEM, second rest)
msg_progress_install "7" "Creating label on $INSTALL_DEVICE"
if [ "$GPT" = "1" ]; then
parted -s $INSTALL_DEVICE mklabel gpt >> $LOGFILE 2>&1
else
parted -s $INSTALL_DEVICE mklabel msdos >> $LOGFILE 2>&1
fi
msg_progress_install "9" "Writing Master Boot Record on $INSTALL_DEVICE"
if [ "$GPT" = "1" ]; then
cat /usr/share/syslinux/gptmbr.bin > $INSTALL_DEVICE
else
cat /usr/share/syslinux/mbr.bin > $INSTALL_DEVICE
fi
msg_progress_install "9" "Writing Master Boot Record on $INSTALL_DEVICE"
if [ "$GPT" = "1" ]; then
cat /usr/share/syslinux/gptmbr.bin > $INSTALL_DEVICE
else
cat /usr/share/syslinux/mbr.bin > $INSTALL_DEVICE
fi
partsize_system_start=$PARTSIZE_SYSTEM_OFFSET
partsize_system_end=$(((PARTSIZE_SYSTEM * 1024 * 1024 / 512) + partsize_system_start - 1))
partsize_storage_start=$((partsize_system_end + 1))
partsize_storage_end=-1024
partsize_system_start=$PARTSIZE_SYSTEM_OFFSET
partsize_system_end=$(((PARTSIZE_SYSTEM * 1024 * 1024 / 512) + partsize_system_start - 1))
partsize_storage_start=$((partsize_system_end + 1))
partsize_storage_end=-1024
msg_progress_install "10" "Creating partition on $INSTALL_DEVICE"
parted -s $INSTALL_DEVICE unit s mkpart primary fat32 -- $partsize_system_start $partsize_system_end >> $LOGFILE 2>&1
msg_progress_install "10" "Creating partition on $INSTALL_DEVICE"
parted -s $INSTALL_DEVICE unit s mkpart primary fat32 -- $partsize_system_start $partsize_system_end >> $LOGFILE 2>&1
msg_progress_install "13" "Creating partition on $INSTALL_DEVICE"
parted -s $INSTALL_DEVICE unit s mkpart primary ext4 -- $partsize_storage_start $partsize_storage_end >> $LOGFILE 2>&1
msg_progress_install "13" "Creating partition on $INSTALL_DEVICE"
parted -s $INSTALL_DEVICE unit s mkpart primary ext4 -- $partsize_storage_start $partsize_storage_end >> $LOGFILE 2>&1
msg_progress_install "16" "Setup bootflag on partition 1 of $INSTALL_DEVICE"
parted -s $INSTALL_DEVICE set 1 boot on >> $LOGFILE 2>&1
if [ "$GPT" = "1" ]; then
parted -s $INSTALL_DEVICE set 1 legacy_boot on >> $LOGFILE 2>&1
fi
msg_progress_install "16" "Setup bootflag on partition 1 of $INSTALL_DEVICE"
parted -s $INSTALL_DEVICE set 1 boot on >> $LOGFILE 2>&1
if [ "$GPT" = "1" ]; then
parted -s $INSTALL_DEVICE set 1 legacy_boot on >> $LOGFILE 2>&1
fi
msg_progress_install "20" "Tell the kernel we have a new partition table on $INSTALL_DEVICE"
partprobe $INSTALL_DEVICE >> $LOGFILE 2>&1
msg_progress_install "20" "Tell the kernel we have a new partition table on $INSTALL_DEVICE"
partprobe $INSTALL_DEVICE >> $LOGFILE 2>&1
# create filesystem
msg_progress_install "23" "Creating filesystem on ${INSTALL_DEVICE}1"
mkfs.vfat ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
# create filesystem
msg_progress_install "23" "Creating filesystem on ${INSTALL_DEVICE}1"
mkfs.vfat ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
msg_progress_install "25" "Set uuid and disklabel $DISKLABEL_SYSTEM on ${INSTALL_DEVICE}${PART1}"
dosfslabel ${INSTALL_DEVICE}${PART1} $DISKLABEL_SYSTEM >> $LOGFILE 2>&1
msg_progress_install "25" "Set uuid and disklabel $DISKLABEL_SYSTEM on ${INSTALL_DEVICE}${PART1}"
dosfslabel ${INSTALL_DEVICE}${PART1} $DISKLABEL_SYSTEM >> $LOGFILE 2>&1
msg_progress_install "28" "Creating filesystem on ${INSTALL_DEVICE}${PART2}"
mke2fs -t ext4 -m 0 ${INSTALL_DEVICE}${PART2} >> $LOGFILE 2>&1
msg_progress_install "28" "Creating filesystem on ${INSTALL_DEVICE}${PART2}"
mke2fs -t ext4 -m 0 ${INSTALL_DEVICE}${PART2} >> $LOGFILE 2>&1
msg_progress_install "30" "Set uuid and disklabel $DISKLABEL_STORAGE on ${INSTALL_DEVICE}${PART2}"
tune2fs -U random -L $DISKLABEL_STORAGE ${INSTALL_DEVICE}${PART2} >> $LOGFILE 2>&1
msg_progress_install "30" "Set uuid and disklabel $DISKLABEL_STORAGE on ${INSTALL_DEVICE}${PART2}"
tune2fs -U random -L $DISKLABEL_STORAGE ${INSTALL_DEVICE}${PART2} >> $LOGFILE 2>&1
UUID_SYSTEM="$(blkid --output udev ${INSTALL_DEVICE}${PART1} | grep ^ID_FS_UUID= | cut -d= -f2)"
UUID_STORAGE="$(blkid --output udev ${INSTALL_DEVICE}${PART2} | grep ^ID_FS_UUID= | cut -d= -f2)"
UUID_SYSTEM="$(blkid --output udev ${INSTALL_DEVICE}${PART1} | grep ^ID_FS_UUID= | cut -d= -f2)"
UUID_STORAGE="$(blkid --output udev ${INSTALL_DEVICE}${PART2} | grep ^ID_FS_UUID= | cut -d= -f2)"
echo "UUID_SYSTEM : ${UUID_SYSTEM}" >> $LOGFILE
echo "UUID_STORAGE: ${UUID_STORAGE}" >> $LOGFILE
echo "UUID_SYSTEM : ${UUID_SYSTEM}" >> $LOGFILE
echo "UUID_STORAGE: ${UUID_STORAGE}" >> $LOGFILE
# mount system partition
msg_progress_install "35" "Creating $TMPDIR/part1"
mkdir -p $TMPDIR/part1 >> $LOGFILE 2>&1
# mount system partition
msg_progress_install "35" "Creating $TMPDIR/part1"
mkdir -p $TMPDIR/part1 >> $LOGFILE 2>&1
msg_progress_install "40" "Mounting ${INSTALL_DEVICE}${PART1} to $TMPDIR/part1"
mount -t vfat ${INSTALL_DEVICE}${PART1} $TMPDIR/part1 >> $LOGFILE 2>&1
msg_progress_install "40" "Mounting ${INSTALL_DEVICE}${PART1} to $TMPDIR/part1"
mount -t vfat ${INSTALL_DEVICE}${PART1} $TMPDIR/part1 >> $LOGFILE 2>&1
# installing syslinux
msg_progress_install "50" "Installing syslinux to $TMPDIR/part1"
syslinux -i ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
# installing syslinux
msg_progress_install "50" "Installing syslinux to $TMPDIR/part1"
syslinux -i ${INSTALL_DEVICE}${PART1} >> $LOGFILE 2>&1
# install system files
msg_progress_install "60" "Installing Kernel"
cp /flash/KERNEL $TMPDIR/part1 >> $LOGFILE 2>&1
# install system files
msg_progress_install "60" "Installing Kernel"
cp /flash/KERNEL $TMPDIR/part1 >> $LOGFILE 2>&1
msg_progress_install "65" "Installing System"
cp /flash/SYSTEM $TMPDIR/part1 >> $LOGFILE 2>&1
sync
msg_progress_install "65" "Installing System"
cp /flash/SYSTEM $TMPDIR/part1 >> $LOGFILE 2>&1
sync
# configuring bootloader
msg_progress_install "80" "Setup bootloader with boot label = $DISKLABEL_SYSTEM and disk label = $DISKLABEL_STORAGE"
mkdir -p $TMPDIR/part1/EFI/BOOT
cat << EOF > $TMPDIR/part1/syslinux.cfg
# configuring bootloader
msg_progress_install "80" "Setup bootloader with boot label = $DISKLABEL_SYSTEM and disk label = $DISKLABEL_STORAGE"
mkdir -p $TMPDIR/part1/EFI/BOOT
cat << EOF > $TMPDIR/part1/syslinux.cfg
DEFAULT linux
PROMPT 0
@ -257,7 +254,8 @@ LABEL linux
KERNEL /KERNEL
APPEND boot=UUID=$UUID_SYSTEM disk=UUID=$UUID_STORAGE $SYSLINUX_PARAMETERS quiet
EOF
cat << EOF > $TMPDIR/part1/EFI/BOOT/grub.cfg
cat << EOF > $TMPDIR/part1/EFI/BOOT/grub.cfg
set timeout="0"
set default="LibreELEC"
@ -266,55 +264,46 @@ menuentry "LibreELEC" {
linux /KERNEL boot=UUID=$UUID_SYSTEM disk=UUID=$UUID_STORAGE quiet
}
EOF
# uefi boot / hybrid mode
cp /usr/share/syslinux/bootx64.efi $TMPDIR/part1/EFI/BOOT
cp /usr/share/syslinux/ldlinux.e64 $TMPDIR/part1/EFI/BOOT
cp /usr/share/grub/bootia32.efi $TMPDIR/part1/EFI/BOOT
sync
# umount system partition, remove mountpoint
msg_progress_install "85" "Unmount $TMPDIR/part1"
umount $TMPDIR/part1 >> $LOGFILE 2>&1
# uefi boot / hybrid mode
cp /usr/share/syslinux/bootx64.efi $TMPDIR/part1/EFI/BOOT
cp /usr/share/syslinux/ldlinux.e64 $TMPDIR/part1/EFI/BOOT
cp /usr/share/grub/bootia32.efi $TMPDIR/part1/EFI/BOOT
sync
msg_progress_install "87" "Remove $TMPDIR/part1"
rmdir $TMPDIR/part1 >> $LOGFILE 2>&1
# umount system partition, remove mountpoint
msg_progress_install "85" "Unmount $TMPDIR/part1"
umount $TMPDIR/part1 >> $LOGFILE 2>&1
if [ "$BACKUP_UNPACK" = "1" ]; then
# mount storage partition
msg_progress_install "89" "Creating $TMPDIR/part2"
mkdir -p $TMPDIR/part2 >> $LOGFILE 2>&1
msg_progress_install "87" "Remove $TMPDIR/part1"
rmdir $TMPDIR/part1 >> $LOGFILE 2>&1
msg_progress_install "90" "Mounting ${INSTALL_DEVICE}${PART2} to $TMPDIR/part2"
mount -t ext4 ${INSTALL_DEVICE}${PART2} $TMPDIR/part2 >> $LOGFILE 2>&1
if [ "$BACKUP_UNPACK" = "1" ]; then
# mount storage partition
msg_progress_install "89" "Creating $TMPDIR/part2"
mkdir -p $TMPDIR/part2 >> $LOGFILE 2>&1
msg_progress_install "92" "Restoring backup"
[ -f /flash/backup.tar.bz2 ] && tar -xjf /flash/backup.tar.bz2 -C $TMPDIR/part2 >> $LOGFILE 2>&1
[ -f /flash/backup.zip ] && unzip -qq /flash/backup.zip -d $TMPDIR/part2 >> $LOGFILE 2>&1
sync
msg_progress_install "90" "Mounting ${INSTALL_DEVICE}${PART2} to $TMPDIR/part2"
mount -t ext4 ${INSTALL_DEVICE}${PART2} $TMPDIR/part2 >> $LOGFILE 2>&1
# umount system partition, remove mountpoint
msg_progress_install "97" "Unmount $TMPDIR/part2"
umount $TMPDIR/part2 >> $LOGFILE 2>&1
msg_progress_install "92" "Restoring backup"
[ -f /flash/backup.tar.bz2 ] && tar -xjf /flash/backup.tar.bz2 -C $TMPDIR/part2 >> $LOGFILE 2>&1
[ -f /flash/backup.zip ] && unzip -qq /flash/backup.zip -d $TMPDIR/part2 >> $LOGFILE 2>&1
sync
msg_progress_install "100" "Remove $TMPDIR/part2"
rmdir $TMPDIR/part2 >> $LOGFILE 2>&1
fi
} | whiptail --backtitle "$BACKTITLE" --gauge "Please wait while your system is being setup ..." 6 73 0
# umount system partition, remove mountpoint
msg_progress_install "97" "Unmount $TMPDIR/part2"
umount $TMPDIR/part2 >> $LOGFILE 2>&1
# install complete
MSG_TITLE="@DISTRONAME@ Install Complete"
MSG_DETAIL="You may now remove the install media and reboot.\n"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_DETAIL" 7 52
msg_progress_install "100" "Remove $TMPDIR/part2"
rmdir $TMPDIR/part2 >> $LOGFILE 2>&1
fi
} | whiptail --backtitle "$BACKTITLE" --gauge "Please wait while your system is being setup ..." 6 73 0
menu_main
;;
1)
menu_main
;;
255)
do_poweroff
;;
esac
# install complete
MSG_TITLE="@DISTRONAME@ Install Complete"
MSG_DETAIL="You may now remove the install media and reboot.\n"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_DETAIL" 7 52
}
msg_no_device() {
@ -323,18 +312,6 @@ msg_no_device() {
MSG_INFOBOX=" No devices were found. "
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_INFOBOX" 9 73
menu_main
}
msg_target_space() {
# show an error dialog for missing space
MSG_TITLE="TARGET SPACE"
MSG_INFOBOX="Not enough target space!\nInstallation aborted.\n"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox "$MSG_INFOBOX" 9 73
menu_main
}
msg_progress_install() {
@ -348,15 +325,6 @@ msg_progress_install() {
echo XXX
}
msg_install_ready() {
# show a dialog that we have installed
MSG_TITLE="INFORMATION"
whiptail --backtitle "$BACKTITLE" --title "$MSG_TITLE" --msgbox " $1" 7 73
menu_main
}
prompt_gpt() {
GPT="0"
UEFI="0"
@ -403,16 +371,16 @@ out during the installation. \
whiptail --backtitle "$BACKTITLE" --cancel-button "$MSG_CANCEL" \
--title "$MSG_TITLE" --menu "$MSG_MENU" 18 73 3 \
1 "Install @DISTRONAME@" \
2 "Installation log" \
2 "View installation log" \
3 "Reboot" 2> $TMPDIR/mainmenu
case $? in
0)
ITEM_MAINMENU=$(cat "$TMPDIR/mainmenu")
case $ITEM_MAINMENU in
1) do_install_quick; break;;
2) logfile_show; break;;
3) do_reboot;
1) do_install_quick;;
2) logfile_show;;
3) do_reboot;;
esac
;;
1)
@ -426,8 +394,6 @@ out during the installation. \
logfile_show() {
whiptail --textbox "$LOGFILE" 20 73 --scrolltext --backtitle "$BACKTITLE"
clear
menu_main
}
do_reboot() {