Skip to content

Commit

Permalink
Added setup cleanup functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonheecs committed Dec 1, 2016
1 parent 244e4db commit 0c80eb4
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 1,549 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
*.log
.DS_Store
!results/.gitkeep
results/*
/results/*
17 changes: 14 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ function includeDependencies() {
source "${current_dir}/setupLibrary.sh"
}

current_dir=$(getCurrentDir)
includeDependencies

function setupSwap() {
createSwap
mountSwap
tweakSwapSettings "10" "50"
saveSwapSettings
}

current_dir=$(getCurrentDir)
includeDependencies
function cleanup() {
if [[ -f "/etc/sudoers.bak" ]]; then
revertSudoers
fi
}

read -p "Enter the username of the new user account:" username
read -s -p "Enter new UNIX password:" password
Expand All @@ -33,14 +39,19 @@ if [[ "${password}" != "${password_confirmation}" ]]; then
exit 1
fi

trap cleanup EXIT SIGHUP SIGINT SIGTERM

addUserAccount "${username}" "${password}"

read -rp $'Paste in the public SSH key for the new user:\n' sshKey
disableSudoPassword "${username}"
addSSHKey "${username}" "${sshKey}"
changeSSHConfig
setupUfw
setupSwap
setTimezone "Asia/Singapore"
configureNTP

sudo service ssh restart
sudo service ssh restart

cleanup
20 changes: 18 additions & 2 deletions setupLibrary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function addUserAccount() {
local silent_mode=${3}

if [[ ${silent_mode} == "true" ]]; then
sudo adduser --disabled-password --gecos '' ${username}
sudo adduser --disabled-password --gecos '' "${username}"
else
sudo adduser --disabled-password ${username}
sudo adduser --disabled-password "${username}"
fi

echo "${username}:${password}" | sudo chpasswd
Expand Down Expand Up @@ -119,4 +119,20 @@ function getPhysicalMemory() {
else
echo ${phymem}
fi
}

# Disables the sudo password prompt for a user account by editing /etc/sudoers
# Arguments:
# Account username
function disableSudoPassword() {
local username="${1}"

sudo cp /etc/sudoers /etc/sudoers.bak
sudo bash -c "echo '${1} ALL=(ALL) NOPASSWD: ALL' | (EDITOR='tee -a' visudo)"
}

# Reverts the original /etc/sudoers file before this script is ran
function revertSudoers() {
sudo cp /etc/sudoers.bak /etc/sudoers
sudo rm -rf /etc/sudoers.bak
}
71 changes: 0 additions & 71 deletions tests/Vagrant/Vagrantfile.precise32

This file was deleted.

71 changes: 0 additions & 71 deletions tests/Vagrant/Vagrantfile.precise64

This file was deleted.

Loading

0 comments on commit 0c80eb4

Please sign in to comment.