From 7c31233858df46570be05c14d9d4c9bf8c60eeff Mon Sep 17 00:00:00 2001 From: Tracker-Friendly Date: Mon, 19 Feb 2024 17:35:51 +0000 Subject: [PATCH] Rewrite --- installer.sh | 487 ++++++++++++++++++--------------------------------- 1 file changed, 172 insertions(+), 315 deletions(-) diff --git a/installer.sh b/installer.sh index 25f10cf..fce3863 100755 --- a/installer.sh +++ b/installer.sh @@ -1,344 +1,201 @@ -#!/bin/bash +#!/bin/sh + +failinstall() { + dialog --title "Error" --msgbox "EvolutionOS was not able to install" 0 0 + clear + exit 1 +} + +create_menu() { + menu="" + for option in "$@"; do + if [[ "$(cat /sys/block/${option}/ro)" = "1" ]]; then + writability="Unwritable" + else + writability="Writable" + fi + menu="${menu} ${option} ${writability}" + done + echo "$menu" +} if [[ $(id -u) -eq 0 ]]; then - : + : else - dialog --title "Run as root" --msgbox "Please run the installer as root!" 0 0 - exit 1 + dialog --title "Run as root" --msgbox "Please run the installer as root!" 0 0 + failinstall fi +if [ $(uname -m) = "i686" ]; then + grub="grub-i386-efi" + arch=i386 +else + grub="grub-x86_64-efi" + arch=x86_64 +fi + + if [[ -x /sys/firmware/efi ]]; then uefi=true else uefi=false fi -dialog --clear --title "Launguage" --menu "Select a language:" 15 50 10 "en_GB" "English UK" "en_US" "English US" - -if [[ $? = 1 ]]; then - exit 1 -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 +choice=$(dialog --menu "Select an installation drive:" 20 60 10 $(create_menu $(parted -l | grep -oE '^Disk /dev/[a-zA-Z0-9]+' | cut -d' ' -f2- | cut -c 6-)) 2>&1 >/dev/tty) -if [[ $? = 1 ]]; then - exit 1 +if [[ "$(cat /sys/block/${choice}/ro)" = "1" ]]; then + dialog --title "Scan disk" --msgbox "You are not able to install evolutionOS on a non-writable disk" 0 0 + failinstall +else + dialog --title "Scan disk" --msgbox "EvolutionOS will now scan your disk drive to check if it can install evolutionOS" 0 0 fi -get_disk_type() { - local disk_name="$1" - - if [[ "$disk_name" =~ ^sd.$ ]]; then - echo "Hard Disk $(echo "${disk_name: -1}" | tr '[:lower:]' '[:upper:]')" - elif [[ "$disk_name" =~ ^emmc.+$ ]]; then - echo "Internal Memory $(echo "${disk_name: -1}" | tr '[:lower:]' '[:upper:]')" - elif [[ "$disk_name" =~ ^nvme.+$ ]]; then - echo "SSD $(echo "${disk_name: -1}" | tr '[:lower:]' '[:upper:]')" - elif [[ "$disk_name" =~ ^fd.+$ ]]; then - echo "Floppy Disk $(echo "${disk_name: -1}" | tr '[:lower:]' '[:upper:]')" - elif [[ "$disk_name" =~ ^sr.$ ]]; then - echo "Disk Drive $(echo "${disk_name: -1}" | tr '[:lower:]' '[:upper:]')" - else - echo "Unknown" - fi -} - -# Getting the disk names using lsblk and awk - -disk_names=$(lsblk --list --nodeps -o NAME | awk 'NR>1') - -# Function to check if the disk is writable -is_disk_writable() { - if [[ "$(cat /sys/block/$choice/ro)" = "1" ]]; then - writable=1 - else - writable=0 - fi - return $writable -} - -# Loop through each disk name and determine its type -while true; do - # Creating the list for dialog - list=() - for disk_name in $disk_names; do - disk_type=$(get_disk_type "$disk_name") - list+=( "$disk_name" "$disk_type" ) - done - - # Using dialog to display the list - dialog --clear --title "Disk List" --menu "Select a disk:" 15 50 10 "${list[@]}" 2>/tmp/disk_choice - - if [[ $? = 1 ]]; then - exit 1 - fi - - # Reading the choice made by the user - choice=$(cat /tmp/disk_choice) - rm /tmp/disk_choice - - # Check if the disk is writable - 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 - dialog --title "Disk with Partitions" --yesno "The selected disk contains data. Do you want to wipe the disk?" 8 50 - response=$? - if [ "$response" -eq 0 ]; then - # User chose Yes, proceed to wipe the disk - # Add your wipe disk command here - echo "Ok, continuing with: $choice" - break - else - # User chose No, return to the selection menu - continue - fi - else - # Disk has no partitions, continue with further actions - echo "Ok, continuing with: $choice" - # Add your additional actions here - # ... - fi - - # Break out of the loop if the user didn't choose to wipe the disk and there are no partitions - break -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 -wipefs -a /dev/$choice -sgdisk -Z /dev/$choice - dialog --yesno "Would you like to use the recommended disk partitioning?" 0 0 if [[ $? = 0 ]]; then - dialog --msgbox "Starting partitioning..." 0 0 - if [[ $uefi = true ]]; then - sfdisk -X gpt -W always /dev/$choice </tmp/fileselect - if [[ $? = 1 ]]; then - 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 - else - echo -e "o\nw" | fdisk /dev/$choice - sfdisk -X mbr -W always /dev/$choice </tmp/fileselect - if [[ $? = 1 ]]; then - dialog --msgbox "Operation cancled" - exit 1 - fi - 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 - bash - dialog --msgbox "Welcome back! Continuing installation..." 0 0 -fi - -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 -installtype=$(cat /tmp/installtype) - -if [ $uefi = true ]; then - if [ $(uname -m) = "i686" ]; then - _grub="grub-i386-efi" - arch=i386 + if [[ $uefi = true ]]; then + parted --script /dev/${choice} mklabel gpt mkpart primary fat32 1MiB 200MiB mkpart primary ext4 200MiB 100% else - _grub="grub-x86_64-efi" - grub=x86_64 + parted --script /dev/${choice} mklabel msdos mkpart primary ext4 1MiB 100% + fi + if [[ $? = 1 ]]; then + dialog --msgbox "Partitioning failed!" 0 0 + failinstall + fi + filesystem=$(dialog --menu "Select a filesystem:" 0 0 0 "ext4" "Fast basic filesystem (recommended)" "btrfs" "Great for data recovery and servers" 2>&1 >/dev/tty) + if [[ $uefi = true ]]; then + if [[ "$filesystem" = "ext4" ]]; then + mkfs.ext4 /dev/${choice}2 | dialog --title "Creating file system..." --programbox 24 80 + else + mkfs.btrfs -f /dev/${choice}2 | dialog --title "Creating file system..." --programbox 24 80 + fi + if [[ $? = 1 ]]; then + dialog --msgbox "Formatting failed!" 0 0 + failinstall + fi + mkfs.fat -v -F 32 /dev/${choice}1 | dialog --title "Creating boot partition..." --programbox 24 80 + if [[ $? = 1 ]]; then + dialog --msgbox "Formatting failed!" 0 0 + failinstall + fi + mount /dev/${choice}2 /mnt + if [[ $? = 1 ]]; then + dialog --msgbox "Mounting failed!" 0 0 + failinstall + fi + mount /dev/${choice}1 /mnt/boot/efi --mkdir + if [[ $? = 1 ]]; then + dialog --msgbox "Mounting ESP failed!" 0 0 + failinstall + fi + else + mkfs.$filesystem /dev/${choice}1 | dialog --title "Creating file system..." --programbox 24 80 + if [[ $? = 1 ]]; then + dialog --msgbox "Formatting failed!" 0 0 + failinstall + fi + mount /dev/${choice}1 /mnt + if [[ $? = 1 ]]; then + dialog --msgbox "Mounting failed!" 0 0 + failinstall + fi fi else - _grub="grub" -fi - -mkdir -p /mnt/var/db/xbps/keys /mnt/usr/share -cp -a /usr/share/xbps.d /mnt/usr/share/ -cp /var/db/xbps/keys/*.plist /mnt/var/db/xbps/keys -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=/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 + while true; do + clear + printf "Ok, welcome to the Linux Shell. Mount root at /" + if [[ $uefi = true ]]; then + printf " and ESP at /boot/efi." + else + printf "." + fi + echo " Type exit when you are done" + ash + dialog --yesno "Have you finished?" 0 0 + if [[ $? = 0 ]]; then + break + else + continue + fi + done fi +installtype=$(dialog --title "Install type" --menu "Choose your installation type" 0 0 0 "local" "Extract from disk (may be out of date)" "network" "Download from internet (requires internet to be set up)" 2>&1 >/dev/tty) 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 </dev/null 2>&1 + if [[ $? = 1 ]]; then + netselect=$(dialog --title "Network" --menu "The network isn't connected. What would you like to do?" 0 0 0 "local" "Go back to extraction from disk" "network" "Manually set up network in the terminal" 2>&1 >/dev/tty) + while true; do + clear + echo "Welcome to the Linux Shell. Type exit when you are done" + ash + dialog --yesno "Have you finished?" 0 0 + if [[ $? = 0 ]]; then + break + else + continue + fi + done + else + mkdir -p /mnt/var/db/xbps/keys/ + cp /var/db/xbps/keys/* /mnt/var/db/xbps/keys/ + if [[ $uefi = true ]]; then + xbps-install -S -y -r /mnt base-system "${grub}" -R https://evolutionos.hectabit.org/pkg -R https://repo-default.voidlinux.org/current | dialog --title "Bootstrapping rootfs..." --programbox 24 80 + else + xbps-install -S -y -r /mnt base-system grub -R https://evolutionos.hectabit.org/pkg -R https://repo-default.voidlinux.org/current | dialog --title "Bootstrapping rootfs..." --programbox 24 80 + fi + break + fi fi - continue - else - break - fi done -while true; do - dialog --title "Username" --clear --inputbox "Enter shorthand username. This will be created as an super user (able to run as root)." 0 0 2>/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 - fi -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 <&1 >/dev/tty) +username=$(dialog --title "Username" --clear --inputbox "Enter your username" 0 0 2>&1 >/dev/tty) +userpasswd=$(dialog --title "Password" --clear --insecure --passwordbox "Enter user password" 0 0 2>&1 >/dev/tty) +hostname=$(dialog --title "Hostname" --clear --inputbox "Enter hostname for computer" 0 0 2>&1 >/dev/tty) +echo -e "$rootpasswd\n$rootpasswd" | xchroot /mnt passwd +xchroot /mnt useradd -m "${username}" +echo -e "$userpasswd\n$userpasswd" | xchroot /mnt passwd "${username}" +echo $hostname > /mnt/etc/hostname +if [[ $uefi = true ]]; then + xchroot /mnt grub-install --efi-directory=/boot/efi /dev/${choice} else - if [[ "$dpname" = "1" ]]; then - exitcode=3 - fi + xchroot /mnt grub-install /dev/${choice} +fi +xchroot /mnt grub-mkconfig -o /boot/grub/grub.cfg +xbps-reconfigure -f glibc-locales -r /mnt +if [[ $? = 1 ]]; then + dialog --msgbox "Package configuration failed!" 0 0 + failinstall +fi +xbps-reconfigure -f -a -r /mnt +if [[ $? = 1 ]]; then + dialog --msgbox "Package configuration failed!" 0 0 + failinstall +fi +genfstab -t UUID /mnt > /mnt/etc/fstab +dialog --yesno "EvolutionOS has been installed! Would you like to reboot?" 0 0 +if [[ $? = 1 ]]; then + clear + exit 0 +else + reboot fi -dialog --title "Done!" --msgbox "Installation now complete." 0 0 -exit $exitcode