This commit is contained in:
Tracker-Friendly 2024-02-19 17:35:51 +00:00
parent 7ab1626523
commit 7c31233858
1 changed files with 172 additions and 315 deletions

View File

@ -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 <<EOF
, 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" 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 <<EOF
, ,
EOF
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"
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 <<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." 0 0
if [[ $? = 1 ]]; then
exit 1
if [[ "$installtype" = "local" ]]; then
cp -r /bin /home /lib32 /media /opt /root /sbin /var /boot /etc /lib /lib64 /run /usr /mnt
if [[ $? = 1 ]]; then
dialog --msgbox "Copying failed!" 0 0
failinstall
fi
mkdir /mnt/dev /mnt/tmp /mnt/proc /mnt/sys
rm -rf /etc/dinit.d/rcboot.sh
mv /etc/dinit.d/rcboot-real.sh /etc/dinit.d/rcboot.sh
xbps-remove -OoR dialog parted e2fsprogs btrfs-progs xtools-minimal ncurses -r /mnt -y
if [[ $uefi = false ]]; then
xbps-remove -OoR dosfstools grub-x86_64-efi -y
fi
rm -rf /mnt/usr/bin/evolution-installer /mnt/usr/bin/genfstab
break
else
ping -c 1 example.org >/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 <<EOF
$userpasswd
$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 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
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
xbps-reconfigure -r /mnt -f glibc-locales
rootpasswd=$(dialog --title "Password" --clear --insecure --passwordbox "Enter admin (root) password" 0 0 2>&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