Compare commits
No commits in common. "9074cf529db6cf300571d7071ade44041349dc4a" and "7d1a2921112d25caa256737529592354a0e6c4f6" have entirely different histories.
9074cf529d
...
7d1a292111
@ -1,150 +1,33 @@
|
||||
#!/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
|
||||
|
||||
HOSTNAME=""
|
||||
get_answer "What is the hostname of this machine?: " HOSTNAME
|
||||
HOSTNAME="ExampleHostname"
|
||||
BOOT_METHOD="${1:?"Boot method was not provided. (BIOS, EFI)"}"
|
||||
BOOT_METHOD="${BOOT_METHOD^^}"
|
||||
|
||||
BOOT_METHOD=""
|
||||
get_choice "What is your boot method?: " BOOT_METHOD BIOS EFI
|
||||
|
||||
DISK=""
|
||||
declare -a DISKS
|
||||
get_disks DISKS
|
||||
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
|
||||
[[ ! "$BOOT_METHOD" =~ ^(EFI|BIOS)$ ]] && {
|
||||
echo "Your boot method $BOOT_METHOD, is not acceptible. Please provide a vaild one"
|
||||
exit
|
||||
}
|
||||
|
||||
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
|
||||
SWAP_PARTITION=${DISK}2
|
||||
ROOT_PARTITION=${DISK}3
|
||||
|
||||
## New Login creds for your new user and the root user
|
||||
ROOT_PASSWORD=""
|
||||
get_answer "What do you want the root password to be? : " ROOT_PASSWORD
|
||||
|
||||
NEW_USER=""
|
||||
get_answer "What other user do you want to configure on the system? : " NEW_USER
|
||||
|
||||
ROOT_PASSWORD="root"
|
||||
NEW_USER="username"
|
||||
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[@]}
|
||||
TIMEZONE_INFO=America/Chicago
|
||||
LOCALE=en_US.UTF-8
|
||||
|
||||
## Commands to create disks un-interactively with fdisk
|
||||
## will clean up comments later with grep command
|
||||
|
Loading…
Reference in New Issue
Block a user