Compare commits

...

4 Commits

View File

@ -1,33 +1,150 @@
#!/usr/bin/bash #!/usr/bin/bash
# BEGIN: Helper Functions
get_disks () {
local -a FOUND_DISKS
local -n OUTPUT_VAR="${1:?"get_disks: No variable was passed through"}"
if ls /dev/?d? >/dev/null 2>&1; then
FOUND_DISKS+=( /dev/?d? )
fi
if ls /dev/nvmen? >/dev/null 2>&1 ; then
FOUND_DISKS+=( /dev/nvmen? )
fi
OUTPUT_VAR=( ${FOUND_DISKS[@]} )
}
get_choices () {
local PROMPT="$1"
shift
local -n OUTPUT_VAR="$2"
shift
local -a OPTIONS=( $@ )
select item in ${OPTIONS[@]} quit; do
case $item in
quit)
return 0
;;
?)
continue
;;
*)
if [[ "$item" ]]; then
OUTPUT_VAR+=( "$item" )
fi
;;
esac
done
}
get_choice () {
echo "1: $1"
local PROMPT="$1"
local -n OUTPUT_VAR="$2"
shift
shift
local -a OPTIONS=( $@ )
select item in ${OPTIONS[@]} quit; do
case $item in
quit)
return 0
;;
?)
continue
;;
*)
if [[ "$item" ]]; then
OUTPUT_VAR="$item"
return 0
fi
;;
esac
done
}
get_yes_no () {
local PROMPT="${1:?"get_yes_no: Prompt was not provided"} "
local CHOICE_REGEX='(y|n|yes|no)'
local ANSWER
while true; do
read -p "$PROMPT" ANSWER
ANSWER="${ANSWER,,}"
if [[ "$ANSWER" =~ ^$CHOICE_REGEX$ ]]; then
case $ANSWER in
y | yes)
return 0
;;
n | no)
return 1
;;
esac
else
echo "$ANSWER is not acceptible, please try again"
fi
done
}
get_answer () {
local PROMPT="${1:?"get_answer: Prompt was not provided"}"
local -n OUTER_VAR="${2:?"get_answer: Return variable not provided"}"
local ANSWER
while true; do
read -p "$PROMPT" ANSWER
if get_yes_no "Are you sure $ANSWER is what you want? (y/n): "; then
OUTER_VAR="$ANSWER"
return
fi
done
}
# END: Helper Functions
# BEGIN: Variables # BEGIN: Variables
HOSTNAME="ExampleHostname" HOSTNAME=""
BOOT_METHOD="${1:?"Boot method was not provided. (BIOS, EFI)"}" get_answer "What is the hostname of this machine?: " HOSTNAME
BOOT_METHOD="${BOOT_METHOD^^}"
[[ ! "$BOOT_METHOD" =~ ^(EFI|BIOS)$ ]] && { BOOT_METHOD=""
echo "Your boot method $BOOT_METHOD, is not acceptible. Please provide a vaild one" get_choice "What is your boot method?: " BOOT_METHOD BIOS EFI
exit
} DISK=""
declare -a DISKS
get_disks DISKS
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
DISK="${2:?"Disk was not provided"}"
[[ ! -b $DISK ]] && {
echo "Your disk ($DISK) does not exist. Please provide a valid one"
exit
}
EFI_PARTITION=${DISK}1 EFI_PARTITION=${DISK}1
SWAP_PARTITION=${DISK}2 SWAP_PARTITION=${DISK}2
ROOT_PARTITION=${DISK}3 ROOT_PARTITION=${DISK}3
## New Login creds for your new user and the root user ## New Login creds for your new user and the root user
ROOT_PASSWORD="root" ROOT_PASSWORD=""
NEW_USER="username" get_answer "What do you want the root password to be? : " ROOT_PASSWORD
NEW_PASSWORD="password"
TIMEZONE_INFO=America/Chicago NEW_USER=""
LOCALE=en_US.UTF-8 get_answer "What other user do you want to configure on the system? : " NEW_USER
NEW_PASSWORD="password"
get_answer "What do you want the password for $NEW_USER to be? : " NEW_PASSWORD
declare -a TIMEZONES=( $( timedatectl list-timezones ) )
TIMEZONE_INFO=""
get_choice "What is your timezone? : " TIMEZONE_INFO ${TIMEZONES[@]}
declare -a LOCALES=( $( localectl list-locales ) )
LOCALE=""
get_choice "What is your locale? : " LOCALE ${LOCALES[@]}
## Commands to create disks un-interactively with fdisk ## Commands to create disks un-interactively with fdisk
## will clean up comments later with grep command ## will clean up comments later with grep command