Skip to content

Commit 0c80eb4

Browse files
committed
Added setup cleanup functions
1 parent 244e4db commit 0c80eb4

11 files changed

+35
-1549
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
*.log
33
.DS_Store
44
!results/.gitkeep
5-
results/*
5+
/results/*

setup.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ function includeDependencies() {
1212
source "${current_dir}/setupLibrary.sh"
1313
}
1414

15+
current_dir=$(getCurrentDir)
16+
includeDependencies
17+
1518
function setupSwap() {
1619
createSwap
1720
mountSwap
1821
tweakSwapSettings "10" "50"
1922
saveSwapSettings
2023
}
2124

22-
current_dir=$(getCurrentDir)
23-
includeDependencies
25+
function cleanup() {
26+
if [[ -f "/etc/sudoers.bak" ]]; then
27+
revertSudoers
28+
fi
29+
}
2430

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

42+
trap cleanup EXIT SIGHUP SIGINT SIGTERM
43+
3644
addUserAccount "${username}" "${password}"
3745

3846
read -rp $'Paste in the public SSH key for the new user:\n' sshKey
47+
disableSudoPassword "${username}"
3948
addSSHKey "${username}" "${sshKey}"
4049
changeSSHConfig
4150
setupUfw
4251
setupSwap
4352
setTimezone "Asia/Singapore"
4453
configureNTP
4554

46-
sudo service ssh restart
55+
sudo service ssh restart
56+
57+
cleanup

setupLibrary.sh

+18-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ function addUserAccount() {
1111
local silent_mode=${3}
1212

1313
if [[ ${silent_mode} == "true" ]]; then
14-
sudo adduser --disabled-password --gecos '' ${username}
14+
sudo adduser --disabled-password --gecos '' "${username}"
1515
else
16-
sudo adduser --disabled-password ${username}
16+
sudo adduser --disabled-password "${username}"
1717
fi
1818

1919
echo "${username}:${password}" | sudo chpasswd
@@ -119,4 +119,20 @@ function getPhysicalMemory() {
119119
else
120120
echo ${phymem}
121121
fi
122+
}
123+
124+
# Disables the sudo password prompt for a user account by editing /etc/sudoers
125+
# Arguments:
126+
# Account username
127+
function disableSudoPassword() {
128+
local username="${1}"
129+
130+
sudo cp /etc/sudoers /etc/sudoers.bak
131+
sudo bash -c "echo '${1} ALL=(ALL) NOPASSWD: ALL' | (EDITOR='tee -a' visudo)"
132+
}
133+
134+
# Reverts the original /etc/sudoers file before this script is ran
135+
function revertSudoers() {
136+
sudo cp /etc/sudoers.bak /etc/sudoers
137+
sudo rm -rf /etc/sudoers.bak
122138
}

tests/Vagrant/Vagrantfile.precise32

-71
This file was deleted.

tests/Vagrant/Vagrantfile.precise64

-71
This file was deleted.

0 commit comments

Comments
 (0)