diff --git a/installer.sh b/installer.sh new file mode 100755 index 0000000..fa73b27 --- /dev/null +++ b/installer.sh @@ -0,0 +1,282 @@ +#!/bin/bash + +if [[ $(id -u) -eq 0 ]]; then + : +else + dialog --title "Run as root" --msgbox "Please run the installer as root!" 0 0 + exit 1 +fi + +# Function to check if the username exists in the chrooted environment +function check_username_existence() { + chroot_dir="/mnt" + username="$1" + + if [ -z "$username" ]; then + echo "Error: Username cannot be empty." + exit 1 + fi + + if chroot "$chroot_dir" id "$username" &>/dev/null; then + echo "Error: Username '$username' already exists." + exit 1 + fi +} + +# Function to check for illegal characters in the username +function check_illegal_characters_username() { + username="$1" + illegal_characters=": \t\n\r\b\0'\"" + + for char in $(echo -n "$username" | grep -o .); do + if [[ "$illegal_characters" == *"$char"* ]]; then + echo "Error: Username contains illegal character '$char'." + exit 1 + fi + done +} + +# Function to check for illegal characters in the password + +function check_illegal_characters() { + password="$1" + illegal_characters=": \t\n\r\b\0'\"" + + if [[ -z $password ]]; then + echo "Password cannot be empty" + exit 1 + fi + + for char in $(echo -n "$password" | grep -o .); do + if [[ "$illegal_characters" == *"$char"* ]]; then + echo "Error: Password contains illegal character '$char'." + exit 1 + fi + done +} + +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 + +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() { + local disk_name="$1" + touch "/mnt/$disk_name" &>/dev/null + local writable=$? + rm "/mnt/$disk_name" &>/dev/null + 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"; then + dialog --title "Disk Not Writable" --msgbox "The selected disk is not writable. Please choose another disk." 8 50 + continue + 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 +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" + exit 1 + fi + filesystem=$(cat /tmp/fileselect) + mkfs.$filesystem /dev/$part2 | dialog --title "Creating file system..." --programbox 24 80 + 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 + 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..." >$LOG + mount --rbind /$f mnt/$f >$LOG 2>&1 +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" + else + _grub="grub-x86_64-efi" + 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 +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 +fi + +xbps-reconfigure -r /mnt -f base-system +chroot /mnt xbps-reconfigure -fa | dialog --title "Reconfiguring packages..." --programbox 24 80 + +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 + rootpasswd="$(cat /tmp/rootpasswd)" + check_illegal_characters "$rootpasswd" + if [[ $? = 1 ]]; then + dialog --title "Illegal characters" --msgbox "You cannot have those characters in a password. Please enter a new one." + 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 + shusername="$(cat /tmp/usershort)" + check_illegal_characters_username "$shusername" + if [[ $? = 1 ]]; then + dialog --title "Illegal characters" --msgbox "You cannot have those characters in a shorthand username. Please enter a new one." + continue + else + check_username_existence "$shusername" + if [[ $? = 1 ]]; then + dialog --title "Already exists" --msgbox "You cannot have a username already used by the system. Please enter a new one." + else + break + fi + fi +done + +dialog --title "Username" --clear --inputbox "Enter display username." 0 0 2>/tmp/dpusername +dpusername=$(cat /tmp/dpusername) +while true; do + dialog --title "Password" --clear --insecure --passwordbox "Enter user password" 0 0 2>/tmp/userpasswd + userpasswd="$(cat /tmp/userpasswd)" + check_illegal_characters "$userpasswd" + if [[ $? = 1 ]]; then + dialog --title "Illegal characters" --msgbox "You cannot have those characters in a password. Please enter a new one." + continue + else + break + fi +done + +dialog --title "Done!" --msgbox "Hello, and welcome to my minceraft tutorial" diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..3767560 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +bash + +echo Hello