os-installer/installer.sh

209 lines
7.6 KiB
Bash
Raw Normal View History

2024-02-19 17:35:51 +00:00
#!/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"
}
2023-07-28 01:07:20 +01:00
if [[ $(id -u) -eq 0 ]]; then
2024-02-19 17:35:51 +00:00
:
2023-07-28 01:07:20 +01:00
else
2024-02-19 17:35:51 +00:00
dialog --title "Run as root" --msgbox "Please run the installer as root!" 0 0
failinstall
2023-07-28 01:07:20 +01:00
fi
2024-02-19 17:35:51 +00:00
if [ $(uname -m) = "i686" ]; then
grub="grub-i386-efi"
arch=i386
2023-07-28 01:07:20 +01:00
else
2024-02-19 17:35:51 +00:00
grub="grub-x86_64-efi"
arch=x86_64
2023-07-28 01:07:20 +01:00
fi
2024-02-19 17:35:51 +00:00
if [[ -x /sys/firmware/efi ]]; then
uefi=true
else
uefi=false
2023-07-28 01:07:20 +01:00
fi
2024-02-22 16:20:48 +00:00
insmod /root/vfat-modules/fat.ko.zst
insmod /root/vfat-modules/vfat.ko.zst
2023-07-28 01:07:20 +01:00
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
2024-02-19 17:35:51 +00:00
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)
2023-07-28 01:07:20 +01:00
2024-02-19 17:35:51 +00:00
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
2023-08-30 17:01:05 +01:00
fi
2023-07-28 01:07:20 +01:00
dialog --yesno "Would you like to use the recommended disk partitioning?" 0 0
if [[ $? = 0 ]]; then
2024-02-19 17:35:51 +00:00
if [[ $uefi = true ]]; then
parted --script /dev/${choice} mklabel gpt mkpart primary fat32 1MiB 200MiB mkpart primary ext4 200MiB 100%
else
parted --script /dev/${choice} mklabel msdos mkpart primary ext4 1MiB 100%
2023-07-28 01:07:20 +01:00
fi
2023-08-30 17:01:05 +01:00
if [[ $? = 1 ]]; then
2024-02-19 17:35:51 +00:00
dialog --msgbox "Partitioning failed!" 0 0
failinstall
2023-08-30 17:01:05 +01:00
fi
2024-02-19 17:35:51 +00:00
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}${part2} | dialog --title "Creating file system..." --programbox 24 80
2024-02-19 17:35:51 +00:00
else
mkfs.btrfs -f /dev/${choice}${part2} | dialog --title "Creating file system..." --programbox 24 80
2024-02-19 17:35:51 +00:00
fi
if [[ $? = 1 ]]; then
dialog --msgbox "Formatting failed!" 0 0
failinstall
fi
mkfs.fat -v -F 32 /dev/${choice}${part1} | dialog --title "Creating boot partition..." --programbox 24 80
2024-02-19 17:35:51 +00:00
if [[ $? = 1 ]]; then
dialog --msgbox "Formatting failed!" 0 0
failinstall
fi
mount /dev/${choice}${part2} /mnt
2024-02-19 17:35:51 +00:00
if [[ $? = 1 ]]; then
dialog --msgbox "Mounting failed!" 0 0
failinstall
fi
2024-02-22 16:20:48 +00:00
mkdir -p /mnt/boot/efi
sh -c "mount /dev/${choice}${part1} /mnt/boot/efi"
2024-02-19 17:35:51 +00:00
if [[ $? = 1 ]]; then
dialog --msgbox "Mounting ESP failed!" 0 0
failinstall
fi
2023-07-28 01:07:20 +01:00
else
mkfs.$filesystem /dev/${choice}${part1} | dialog --title "Creating file system..." --programbox 24 80
2024-02-19 17:35:51 +00:00
if [[ $? = 1 ]]; then
dialog --msgbox "Formatting failed!" 0 0
failinstall
fi
mount /dev/${choice}${part1} /mnt
2024-02-19 17:35:51 +00:00
if [[ $? = 1 ]]; then
dialog --msgbox "Mounting failed!" 0 0
failinstall
fi
2023-07-28 01:07:20 +01:00
fi
else
2024-02-19 17:35:51 +00:00
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
2023-08-30 17:01:05 +01:00
fi
2023-07-30 23:57:56 +01:00
2024-02-19 17:35:51 +00:00
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)
2023-07-28 01:07:20 +01:00
while true; do
2024-02-19 17:35:51 +00:00
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
2024-02-22 16:20:48 +00:00
rm -rf /mnt/etc/dinit.d/rcboot.sh
rm -rf /mnt/root/vfat-modules
mv /mnt/etc/dinit.d/rcboot-real.sh /mnt/etc/dinit.d/rcboot.sh
2024-02-19 17:35:51 +00:00
xbps-remove -OoR dialog parted e2fsprogs btrfs-progs xtools-minimal ncurses -r /mnt -y
if [[ $uefi = false ]]; then
2024-02-22 16:20:48 +00:00
xbps-remove -OoR dosfstools grub-x86_64-efi -r /mnt -y
2024-02-19 17:35:51 +00:00
fi
2024-02-22 16:20:48 +00:00
rm -rf /mnt/usr/bin/evolution-installer
2024-02-19 17:35:51 +00:00
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
2023-08-30 17:01:05 +01:00
fi
2023-07-28 01:07:20 +01:00
done
2024-02-19 17:35:51 +00:00
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
2024-02-22 16:20:48 +00:00
xchroot /mnt grub-install --no-nvram --efi-directory=/boot/efi /dev/${choice}
mkdir -p /mnt/boot/efi/EFI/boot/
mv /mnt/boot/efi/EFI/void*/grubx64.efi /mnt/boot/efi/EFI/boot/bootx64.efi
rm -rf /mnt/boot/efi/EFI/void*
2024-02-19 17:35:51 +00:00
else
xchroot /mnt grub-install /dev/${choice}
2023-08-30 17:01:05 +01:00
fi
2024-02-19 17:35:51 +00:00
xchroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
xbps-reconfigure -f glibc-locales -r /mnt
2023-08-30 17:01:05 +01:00
if [[ $? = 1 ]]; then
2024-02-19 17:35:51 +00:00
dialog --msgbox "Package configuration failed!" 0 0
failinstall
2023-08-30 17:01:05 +01:00
fi
2024-02-19 17:35:51 +00:00
xbps-reconfigure -f -a -r /mnt
2023-08-30 17:01:05 +01:00
if [[ $? = 1 ]]; then
2024-02-19 17:35:51 +00:00
dialog --msgbox "Package configuration failed!" 0 0
failinstall
2023-08-30 17:01:05 +01:00
fi
2024-02-19 17:35:51 +00:00
dialog --yesno "EvolutionOS has been installed! Would you like to reboot?" 0 0
if [[ $? = 1 ]]; then
clear
exit 0
2023-08-30 17:01:05 +01:00
else
2024-02-19 17:35:51 +00:00
reboot
2023-08-30 17:01:05 +01:00
fi
2023-07-30 23:42:52 +01:00