Improvment

This commit is contained in:
Tracker-Friendly 2023-08-30 17:01:05 +01:00
parent ca23fc70b5
commit 7ab1626523
1 changed files with 110 additions and 10 deletions

View File

@ -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 <<EOF
t
1
EOF
if [[ $? = 1 ]]; then
dialog --msgbox "Partitioning failed..." 0 0
exit 1
fi
part1=$(lsblk -n -o NAME --list /dev/$choice | sed -n '2p')
part2=$(lsblk -n -o NAME --list /dev/$choice | sed -n '3p')
mkfs.fat -F 32 /dev/$part1
dialog --clear --title "Filesystem Type" --menu "Select a filesystem:" 0 0 0 "ext4" "Basic file system (recommended)" "btrfs" "Great for data recovery" "xfs" "High performence, but may need extra RAM" 2>/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 <<EOF
$rootpasswd
$rootpasswd
EOF
if [[ $? = 1 ]]; then
dialog --title "Illegal characters" --msgbox "You cannot have those characters in a password. Please enter a new one."
dialog --title "Illegal characters" --msgbox "You cannot have those characters in a password. Please enter a new one." 0 0
if [[ $? = 1 ]]; then
exit 1
fi
continue
else
break
@ -211,10 +270,16 @@ 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
@ -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 <<EOF
$userpasswd
@ -232,13 +305,40 @@ $userpasswd
EOF
if [[ $? = 1 ]]; then
dialog --title "Illegal characters" --msgbox "You cannot have those characters in a password. Please enter a new one." 0 0
if [[ $? = 1 ]]; then
exit 1
fi
continue
else
break
fi
done
chroot /mnt chfn -f "$dpusername" $shusername
chroot /mnt usermod -a -G video $shusername
if [[ $? = 1 ]]; then
dialog --msgbox "Adding user to video group failed... The system should still work, though you may need to do that later. Installation continuing..."
vguser=1
fi
dialog --title "Done!" --msgbox "Hello, and welcome to my minceraft tutorial" 0 0
chroot /mnt chfn -f "$dpusername" $shusername
if [[ $? = 1 ]]; then
dialog --msgbox "Display username changing failed... The system should still work, though your display name will not be displayed. Installation continuing..."
dpname=1
fi
exitcode=0
if [[ "$vkuser" = "1"; ]]; then
exitcode=2
if [[ "$dpname" = "1" ]]; then
exitcode=4
fi
else
if [[ "$dpname" = "1" ]]; then
exitcode=3
fi
fi
dialog --title "Done!" --msgbox "Installation now complete." 0 0
exit $exitcode