Remove the need for prompting the user for a password (#12)

Relates to issue #9
This commit is contained in:
Jason Hee authored and GitHub committed 2021-08-15 21:47:26 +08:00
1 parent ce73240765
commit 153087929c
4 files changed
+5 -27

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ bash setup.sh
```
# Setup prompts
When the setup script is run, you will be prompted to enter the username and password of the new user account.
When the setup script is run, you will be prompted to enter the username of the new user account.
Following that, you will then be prompted to add a public ssh key (which should be from your local machine) for the new account. To generate an ssh key from your local machine:
```bash
+1 -20
View File
@@ -20,12 +20,10 @@ output_file="output.log"
function main() {
read -rp "Enter the username of the new user account:" username
promptForPassword
# Run setup functions
trap cleanup EXIT SIGHUP SIGINT SIGTERM
addUserAccount "${username}" "${password}"
addUserAccount "${username}"
read -rp $'Paste in the public SSH key for the new user:\n' sshKey
echo 'Running setup script...'
@@ -89,21 +87,4 @@ function setupTimezone() {
echo "Timezone is set to $(cat /etc/timezone)" >&3
}
# Keep prompting for the password and password confirmation
function promptForPassword() {
PASSWORDS_MATCH=0
while [ "${PASSWORDS_MATCH}" -eq "0" ]; do
read -s -rp "Enter new UNIX password:" password
printf "\n"
read -s -rp "Retype new UNIX password:" password_confirmation
printf "\n"
if [[ "${password}" != "${password_confirmation}" ]]; then
echo "Passwords do not match! Please try again."
else
PASSWORDS_MATCH=1
fi
done
}
main
+2 -4
View File
@@ -3,12 +3,10 @@
# Add the new user account
# Arguments:
# Account Username
# Account Password
# Flag to determine if user account is added silently. (With / Without GECOS prompt)
function addUserAccount() {
local username=${1}
local password=${2}
local silent_mode=${3}
local silent_mode=${2}
if [[ ${silent_mode} == "true" ]]; then
sudo adduser --disabled-password --gecos '' "${username}"
@@ -16,8 +14,8 @@ function addUserAccount() {
sudo adduser --disabled-password "${username}"
fi
echo "${username}:${password}" | sudo chpasswd
sudo usermod -aG sudo "${username}"
sudo passwd -d "${username}"
}
# Add the local machine public SSH Key for the new user account
+1 -2
View File
@@ -23,7 +23,6 @@ source "${current_dir}/lib/bunit.shl"
source "${current_dir}/../setupLibrary.sh"
test_user_account=testuser
test_account_password="123%pass_321"
# shellcheck disable=SC2034
VERBOSE_MODE="true"
@@ -32,7 +31,7 @@ VERBOSE_MODE="true"
function testSetup () {
echo "Test Setup"
addUserAccount ${test_user_account} ${test_account_password} true
addUserAccount ${test_user_account} true
}
function testUserAccountCreated() {