#!/bin/bash set -euo pipefail BASEDIR="$(dirname "${0}" | sed "s|^\.|${PWD}|")" cat << EOF ####################################### ## ## ## $(cat "${baseDir}/title") Script ## ## ## ## Jean ## ## ## ####################################### ################# ## ## ## Configure ## ## ## ################# EOF printf \ 'zolFedoraVer="2-6"\n' | \ tee \ "${baseDir}/system.conf" \ &> \ /dev/null printf \ '(NVMe) SSD or HDD?\n' select option in 'SSD' 'HDD' do case "${option}" in 'SSD'|'HDD') break ;; *) printf \ 'Invalid option\n' ;; esac done printf \ "diskType=\"${option}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null printf \ '\033[2J\033[H' printf \ '\nGet disk from:\n' select option in '/dev/disk/by-id/' '/dev/' do case "${option}" in '/dev/disk/by-id/'|'/dev/') break ;; *) printf \ 'Invalid option\n' ;; esac done printf \ '\033[2J\033[H' if [[ "${option}" == '/dev/disk/by-id/' ]]; then drives="$(ls -Ago /dev/disk/by-id/ | grep -v 'sr' | grep -v 'dm-' | grep -v 'nvme-eui.' | grep -v '\-part' | grep -v 'wwn-' | grep -v '_[1-9] -> ' | grep -v 'total' | sed 's|^.*\:[0-5][0-9] ||g; s| -> .*$||g' | tr -d '[:blank:]')" printf \ '\nSelect the disk you want to use:\n' drives=( ${drives} ) shopt -s extglob menu="@(${drives[0]}" for ((i=1;i<${#drives[@]};i++)); do menu+="|${drives[$i]}" done menu+=")" select drive in "${drives[@]}" do case ${drive} in ${menu}) break ;; *) printf \ 'Invalid option\n' ;; esac done printf \ "disk=\"/dev/disk/by-id/${drive}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null elif [[ "${option}" == '/dev/' ]]; then drives="$(lsblk -do name | grep -v 'loop' | grep -v 'sr' | grep -v 'zram' | grep -v 'NAME' | tr -d '[:blank:]')" printf \ '\nSelect the disk you want to use:\n' drives=( ${drives} ) shopt -s extglob menu="@(${drives[0]}" for ((i=1;i<${#drives[@]};i++)); do menu+="|${drives[$i]}" done menu+=")" select drive in "${drives[@]}" do case ${drive} in ${menu}) break ;; *) printf \ 'Invalid option\n' ;; esac done printf \ "disk=\"/dev/${drive}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null fi printf \ '\033[2J\033[H' hostname='-' while [[ "${hostname}" == '-' ]] || [[ -z "${hostname}" ]] || [[ "${hostname}" = *' '* ]] || [[ "${hostname}" = *_* ]]; do printf \ '\nEnter a hostname for this machine (no spaces or underscores):\n' read \ -r \ hostname if [[ "${hostname}" = *' '* ]] || [[ "${hostname}" = *_* ]]; then printf \ 'ERROR:\tNo spaces or underscores in the hostname!\n' fi done printf \ "hostname=\"${hostname}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null printf \ '\033[2J\033[H' username='-' while [[ "${username}" == '-' ]] || [[ -z "${username}" ]] || [[ "${username}" = *' '* ]] || [[ "${username}" = *[A-Z]* ]]; do printf \ '\nEnter a name for the new user account (lowercase, no spaces):\n' read \ -r \ username if [[ "${username}" = *' '* ]] || [[ "${username}" = *[A-Z]* ]]; then printf \ 'ERROR:\tNo spaces or uppercase letters in the username!\n' fi done printf \ "username=\"${username}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null printf \ '\033[2J\033[H' printf \ '\nEnable SWAP?\n' select option in 'yes' 'no' do case "${option}" in 'yes'|'no') break ;; *) printf \ 'Invalid option\n' ;; esac done printf \ "enableSwap=\"${option}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null printf \ '\033[2J\033[H' printf \ '\nEnable encryption?\n' select option in 'yes' 'no' do case "${option}" in 'yes'|'no') break ;; *) printf \ 'Invalid option\n' ;; esac done printf \ "encryption=\"${option}\"\n" | \ tee \ --append \ "${baseDir}/system.conf" \ &> \ /dev/null printf \ '\033[2J\033[H' cat << EOF Configuration stored in '${baseDir}/system.conf' Press any key to return to the main menu EOF read \ -srn \ 1