From f02c3ba077dfbab48b28b5a0d50755e2cf706d10 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Thu, 25 Nov 2021 03:58:27 -0600 Subject: [PATCH] Near full install --- Misc/Arch-LuksCrpy-Install.bash | 207 +++++++++++++++++++++++++++++++- 1 file changed, 203 insertions(+), 4 deletions(-) diff --git a/Misc/Arch-LuksCrpy-Install.bash b/Misc/Arch-LuksCrpy-Install.bash index 3c30635..47005fd 100755 --- a/Misc/Arch-LuksCrpy-Install.bash +++ b/Misc/Arch-LuksCrpy-Install.bash @@ -1,5 +1,25 @@ #!/bin/bash -#!/bin/bash + +confirmation() { + local message + message="${1}" + + local choice + + while :; do + read -p "${message}" -n 1 -r choice + echo $choice + case "${choice}" in + y | Y) + return 0 + ;; + n | N) + return 1 + ;; + *) echo -e "\nInput must be either y, Y, n, or N" ;; + esac + done +} echo_rgb() { # Echo a colored string to the terminal based on rgb values @@ -133,18 +153,197 @@ get_available_disks() { echo "${ret_val}" } +list_disks() { + local disks + disks="${1}" + + local count + count=0 + log "info" "Available disks" + for disk in ${disks}; do + echo " "${count}\.\) "${disk}" + count=$(( count + 1 )) + done +} + +get_num_of_elems() { + local count + count=0 + for elem in ${1}; do + count=$(( count + 1 )) + done + + echo "${count}" +} + install() { + if ! host "google.com" > /dev/null; then + log "error" "Unable to reach google, network is down. This script requires network connectivity with active DNS resolution" + exit 1 + fi + local DISK_BASE_PATH + DISK_BASE_PATH="/dev/" + local available_disks log "info" "Querying system for available disks..." available_disks="$(get_available_disks)" + disk_count="$(get_num_of_elems "${available_disks}")" + disk_count=$(( disk_count - 1)) + + + local disk_selected + local install_disk + local install_path + local count + local valid_disk_selected + valid_disk_selected=1 + while [[ "${valid_disk_selected}" != 0 ]]; do + list_disks "${available_disks}" + read -p "Select a disk number to install arch linux to: " disk_selected + + if [ ${disk_selected} -eq ${disk_selected} 2> /dev/null ]; then + : + else + log "error" "A number was not passed" + continue + fi - log "info" "Available disks: " - for disk in ${available_disks}; do - echo " - $(important "${disk}")" + if [[ "${disk_selected}" -gt "${disk_count}" ]]; then + log "error" "Invalid disk number passed, received ${disk_selected}, but the maximum disk number is ${disk_count}" + elif [[ "${disk_selected}" -lt 0 ]]; then + log "error" "Invalid disk number passed, received ${disk_selected} which was less than 0" + else + for disk in ${available_disks}; do + if [[ ${count} -eq ${disk_selected} ]]; then + install_disk="${disk}" + install_path="${DISK_BASE_PATH}/${install_disk}" + valid_disk_selected=0 + fi + count=$(( count + 1 )) + done + fi + done + log "info" "Disk selected given as $(important "${install_disk}")" + + if [[ ! -e "${install_path}" ]]; then + log "error" "The given disk, $(important "${install_disk}") does not exist at $(important "${install_path}")" + exit 1 + fi + + if ! confirmation "Begin installation of Arch Linux to $(important "${install_disk}") (y/N)? "; then + log "info" "Confirmation recieved negative, going back to options..." + exit + fi + + log "info" "Installing Arch to disk $(important "${install_disk}")" + + log "info" "Wiping partitions on disk $(important "${install_disk}")" + sfdisk --delete "${install_path}" >/dev/null + log "info" "Wiped partitions on $(important "${install_disk}")" + log "info" "Securely erasing remaining data on $(important "${install_disk}")" + # echo YES | cryptsetup open --type plain -d /dev/urandom "${install_path}" to_be_wiped > /dev/null + # dd bs=1M if=/dev/zero of=/dev/mapper/to_be_wiped status=progress 2> /dev/null + # cryptsetup close to_be_wiped + log "info" "Writing new partitions to $(important "${install_disk}")" + (echo n + echo + echo + echo +512M + echo ef00 + echo n + echo + echo + echo + echo 8300 + echo w) | gdisk "${install_path}" + log "info" "Wrote partitions" + log "info" "Encrypting $(important "${install_disk}")" + echo YES | cryptsetup -y -v luksFormat "${install_path}" + log "info" "Requesting opening of $(important "${install_disk}")" + cryptsetup open "${install_path}" cryptroot + log "info" "Creating file systems..." + mkdfs.fat -F32 "${install_path}" + mkfs.ext4 "/dev/mapper/cryptroot" + log "info" "Created file systems" + + mount /dev/mapper/cryptroot /mnt + mkdir /mnt/boot + mount "${install_path}" /mnt/boot + local mem_amount + mem_amount="$(grep MemTotal /proc/meminfo | tr -s " " | cut -d " " -f2)" + mem_amount=$(( mem_amount * 3/2 )) + log "info" "Creating swap file with memory amount: $(important "${mem_amount}") mebibytes" + dd if=/dev/zero of=/mnt/swapfile bs=1M count="${mem_amount}" status=progress + chmod 600 /mnt/swapfile + mkswap /mnt/swapfile + swapon /mnt/swapfile + log "info" "Finished creating swap file" + + local packages + packages="base base-devel linux linux-headers linux-firmware neovim" + log "info" "Doing primary installation with pacstrap" + log "info" "Installing the following packages:" + for pkg in ${packages}; do + echo " - ${pkg}" done + pacstrap /mnt base base-devel linux linux-headers linux-firmware neovim + log "info" "Finished installing packages" + log "info" "Generating fstab" + genfstab -U /mnt >> /mnt/etc/fstab + log "info" "Finished generating fstab" + log "info" "Switching to new installation" + arch-chroot /mnt + log "info" "Configuring hosts and hostname" + echo "arch" > /etc/hostname + cat << __EOF__ > "/etc/hosts" +127.0.0.1 localhost +::1 localhost +127.0.1.1 arch.localdomain arch +__EOF__ + + log "info" "Setting locale to en_US.UTF-8" + echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen + locale-gen + echo "LANG=en_US.UTF-8" > /etc/locale.conf + + log "info" "Setting root password to $(important "toor")" + echo "toor" | passwd root --stdin + log "info" "Installing boot loader" + local ucode + while read -r; do + if [[ "${REPLY}" = "*VendorID*" ]]; then + if [[ "${REPLY}" = "*AMD*" ]]; then + ucode="amd-ucode" + else + ucode="intel-ucode" + fi + fi + done <<< "$(lscpu)" + pacman -S grub efibootmgr "${ucode}" + local disk_uuid + disk_uuid="$(blkid -s UUID -o value "${install_path}")" + echo disk uuid: $disk_uuid + while read -r; do + if [[ "${REPLY}" = "*GRUB_CMD_LINE*" ]]; then + echo "GRUB_CMDLINE_LINUX=\"cryptdevice=UUID=${disk_uuid}:cryptroot\"" + else + echo "${REPLY}" + fi + done <<< "$(cat /etc/default/grub)" + + grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB + grub-mkconfig -o /boot/grub/grub.cfg + + log "info" "Finished installing bootloader" + + log "info" "Installing network manager" + pacman -S networkmanager + systemctl enable NetworkManager + log "info" "Finished!" + log "info" "Next steps: update localities if incorrect, add your user" } main() {