From 7ab1626523eb7fa916b19e11ae4d95b5e3c5b87f Mon Sep 17 00:00:00 2001 From: Tracker-Friendly Date: Wed, 30 Aug 2023 17:01:05 +0100 Subject: [PATCH] Improvment --- installer.sh | 120 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 110 insertions(+), 10 deletions(-) diff --git a/installer.sh b/installer.sh index e9c4695..25f10cf 100755 --- a/installer.sh +++ b/installer.sh @@ -21,6 +21,10 @@ fi dialog --title "Welcome" --msgbox "Welcome to the EvolutionOS installer! \n\nThis installer is meant to be straightforward, no need for technical skill. \n\nPress enter to select buttons, tab to move between text boxes, and left / right to move between buttons." 0 0 +if [[ $? = 1 ]]; then + exit 1 +fi + get_disk_type() { local disk_name="$1" @@ -45,10 +49,11 @@ disk_names=$(lsblk --list --nodeps -o NAME | awk 'NR>1') # Function to check if the disk is writable is_disk_writable() { - local disk_name="$1" - touch "/mnt/$disk_name" &>/dev/null - local writable=$? - rm "/mnt/$disk_name" &>/dev/null + if [[ "$(cat /sys/block/$choice/ro)" = "1" ]]; then + writable=1 + else + writable=0 + fi return $writable } @@ -73,11 +78,15 @@ while true; do rm /tmp/disk_choice # Check if the disk is writable - if ! is_disk_writable "$choice"; then + if [[ $(is_disk_writable "$choice") = 1 ]]; then dialog --title "Disk Not Writable" --msgbox "The selected disk is not writable. Please choose another disk." 8 50 continue fi + if [[ $? = 1 ]]; then + exit 1 + fi + # Check if the disk has partitions partitions=$(lsblk "/dev/$choice" | grep -c "part") if [ "$partitions" -gt 0 ]; then @@ -105,6 +114,10 @@ done for i in $(lsblk --list -o NAME /dev/$choice | awk 'NR>2'); do umount /dev/$i + if [[ $? = 32 ]]; then + dialog --msgbox "Specfifed target is busy... Cannot continue" 0 0 + exit 1 + fi done sfdisk --delete /dev/$choice @@ -119,20 +132,32 @@ if [[ $? = 0 ]]; then , 200M , , EOF + if [[ $? = 1 ]]; then + dialog --msgbox "Partitioning failed..." 0 0 + exit 1 + fi fdisk /dev/$choice </tmp/fileselect if [[ $? = 1 ]]; then - dialog --msgbox "Operation cancled" + dialog --msgbox "Operation cancled" 0 0 exit 1 fi filesystem=$(cat /tmp/fileselect) mkfs.$filesystem /dev/$part2 | dialog --title "Creating file system..." --programbox 24 80 + if [[ $? = 1 ]]; then + dialog --msgbox "Partitioning failed..." 0 0 + exit 1 + fi mount /dev/$part2 /mnt mkdir -p /mnt/boot/efi mount /dev/$part1 /mnt/boot/efi @@ -149,6 +174,10 @@ EOF filesystem=$(cat /tmp/fileselect) partmpt1=$(lsblk -n -o NAME --list /dev/$choice | sed -n '2p') mkfs.$filesystem /dev/$part1 | dialog --title "Creating file system..." --programbox 24 80 + if [[ $? = 1 ]]; then + dialog --msgbox "Partitioning failed..." + exit 1 + fi fi else dialog --msgbox "Ok, you will be dropped into a CLI. Please mount the filesystem, when done, at \"/mnt/\". Note that anything except the default partition disk (ESP, Optional Swap, RootFS) is not offically supported and may not work. Enter exit when you are done." 0 0 @@ -160,6 +189,10 @@ for f in sys proc dev; do [ ! -d /mnt/$f ] && mkdir /mnt/$f echo "Mounting /mnt/$f..." mount --rbind /$f /mnt/$f + if [[ $? = 1 ]]; then + dialog --msgbox "Mount failed..." + exit 1 + fi done dialog --clear --title "Select install type" --menu "Which installation type would you like to you:" 0 0 0 "local" "Install without internet" "network" "Download from internet" 2>/tmp/installtype @@ -184,25 +217,51 @@ mkdir -p /mnt/boot/grub if [[ $installtype = "local" ]]; then xbps-install -S -y -r /mnt -i -R /var/cache/xbps/ base-system $_grub | dialog --title "Installing base system..." --programbox 24 80 + if [[ $? = 1 ]]; then + dialog --msgbox "Bootstrap failed..." 0 0 + exit 1 + fi else xbps-install -S -y -r /mnt -R https://evolution-linux.github.io/pkg base-system $_grub | dialog --title "Installing base system..." --programbox 24 80 + if [[ $? = 1 ]]; then + dialog --msgbox "Bootstrap failed..." 0 0 + exit 1 + fi fi xbps-reconfigure -r /mnt -f base-system chroot /mnt xbps-reconfigure -fa | dialog --title "Reconfiguring packages..." --programbox 24 80 +if [[ $? = 1 ]]; then + dialog --msgbox "Configuration failed..." + exit 1 +fi -chroot /mnt grub-install --target=$arch --efi-directory=/hoot/efi --bootloader-id=void_grub --recheck +chroot /mnt grub-install --target=$arch --efi-directory=/boot/efi --bootloader-id=void_grub --recheck +if [[ $? = 1 ]]; then + dialog --msgbox "GRUB Installation failed..." + exit 1 +fi chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg +if [[ $? = 1 ]]; then + dialog --msgbox "GRUB Installation failed..." + exit 1 +fi while true; do dialog --title "Password" --clear --insecure --passwordbox "Enter Admin (root) password. For security reasons, you cannot log in as admin. Press enter to submit." 0 0 2>/tmp/rootpasswd + if [[ $? = 1 ]]; then + exit 1 + fi rootpasswd="$(cat /tmp/rootpasswd)" passwd -R /mnt </tmp/usershort + if [[ $? = 1 ]]; then + exit 1 + fi shusername="$(cat /tmp/usershort)" useradd -R /mnt -m $shusername if [[ $? = 1 ]]; then dialog --title "Illegal characters" --msgbox "You cannot have those characters in a shorthand username. Please enter a new one." + if [[ $? = 1 ]]; then + exit 1 + fi continue else break @@ -222,9 +287,17 @@ while true; do done dialog --title "Username" --clear --inputbox "Enter display username." 0 0 2>/tmp/dpusername +if [[ $? = 1 ]]; then + exit 1 +fi + dpusername=$(cat /tmp/dpusername) + while true; do dialog --title "Password" --clear --insecure --passwordbox "Enter user password" 0 0 2>/tmp/userpasswd 0 0 + if [[ $? = 1 ]]; then + exit 1 + fi userpasswd="$(cat /tmp/userpasswd)" passwd -R /mnt <