Refactored code based on shellcheck

This commit is contained in:
Jason Hee committed 2016-12-05 15:28:09 +08:00
1 parent b9b66c711f
commit 69b536300d
4 files changed
+52 -42

No files matched your search

+19 -10
View File
@@ -3,7 +3,7 @@
function getCurrentDir() {
local current_dir="${BASH_SOURCE%/*}"
if [[ ! -d "${current_dir}" ]]; then current_dir="$PWD"; fi
echo ${current_dir}
echo "${current_dir}"
}
current_dir=$(getCurrentDir)
@@ -21,12 +21,14 @@ function testSetup () {
}
function testUserAccountCreated() {
local user_exists_code=$(id -u ${test_user_account} > /dev/null 2>&1; echo $?)
assertEquals 0 ${user_exists_code}
local user_exists_code
user_exists_code="$(id -u ${test_user_account} > /dev/null 2>&1; echo $?)"
assertEquals 0 "${user_exists_code}"
}
function testIfUserIsSudo() {
local user_access=$(sudo -l -U ${test_user_account})
local user_access
user_access="$(sudo -l -U ${test_user_account})"
assertContains "(ALL : ALL) ALL" "${user_access}"
}
@@ -36,14 +38,16 @@ function testAddingOfSSHKey() {
local dummy_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBGTO0tsVejssuaYR5R3Y/i73SppJAhme1dH7W2c47d4gOqB4izP0+fRLfvbz/tnXFz4iOP/H6eCV05hqUhF+KYRxt9Y8tVMrpDZR2l75o6+xSbUOMu6xN+uVF0T9XzKcxmzTmnV7Na5up3QM3DoSRYX/EP3utr2+zAqpJIfKPLdA74w7g56oYWI9blpnpzxkEd3edVJOivUkpZ4JoenWManvIaSdMTJXMy3MtlQhva+j9CgguyVbUkdzK9KKEuah+pFZvaugtebsU+bllPTB0nlXGIJk98Ie9ZtxuY3nCKneB+KjKiXrAvXUPCI9mWkYS/1rggpFmu3HbXBnWSUdf [email protected]"
addSSHKey "${test_user_account}" "${dummy_key}"
local ssh_file="$(sudo cat /home/${test_user_account}/.ssh/authorized_keys)"
local ssh_file
ssh_file="$(sudo cat /home/${test_user_account}/.ssh/authorized_keys)"
assertEquals "${ssh_file}" "${dummy_key}"
}
function testChangeSSHConfig() {
changeSSHConfig
local ssh_config="$(sudo cat /etc/ssh/sshd_config)"
local ssh_config
ssh_config="$(sudo cat /etc/ssh/sshd_config)"
assertContains "PasswordAuthentication no" "${ssh_config}"
assertContains "PermitRootLogin no" "${ssh_config}"
}
@@ -51,7 +55,8 @@ function testChangeSSHConfig() {
function testUfw() {
setupUfw
local ufw_status=$(sudo ufw status)
local ufw_status
ufw_status="$(sudo ufw status)"
assertContains "Status: active" "${ufw_status}"
assertContains "OpenSSH" "${ufw_status}"
}
@@ -64,8 +69,11 @@ function testSwap() {
}
function testSwapSettings() {
local swappiness=$(cat /proc/sys/vm/swappiness)
local cache_pressure=$(cat /proc/sys/vm/vfs_cache_pressure)
local swappiness
local cache_pressure
swappiness="$(cat /proc/sys/vm/swappiness)"
cache_pressure="$(cat /proc/sys/vm/vfs_cache_pressure)"
tweakSwapSettings 10 50
@@ -76,7 +84,8 @@ function testSwapSettings() {
}
function testTimezone() {
local timezone="$(cat /etc/timezone)"
local timezone
timezone="$(cat /etc/timezone)"
setTimezone "America/New_York"
assertEquals "America/New_York" "$(cat /etc/timezone)"