File tree 2 files changed +42
-3
lines changed
2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,27 @@ function changeSSHConfig() {
39
39
function setupUfw() {
40
40
sudo ufw allow OpenSSH
41
41
yes y | sudo ufw enable
42
+ }
43
+
44
+ function createSwap() {
45
+ local swapmem=$(( $(getPhysicalMemory) * 2 ))
46
+
47
+ # Anything over 4GB in swap is probably unnecessary as a RAM fallback
48
+ if [[ ${swapmem} > 4 ]]; then
49
+ phymem=4
50
+ fi
51
+
52
+ sudo fallocate -l ${swapmem} G /swapfile
53
+ sudo chmod 600 /swapfile
54
+ sudo mkswap /swapfile
55
+ sudo swapon /swapfile
56
+ }
57
+
58
+ function getPhysicalMemory() {
59
+ local phymem=$( free -g| awk ' /^Mem:/{print $2}' )
60
+ if [[ ${phymem} == ' 0' ]]; then
61
+ echo 1
62
+ else
63
+ echo ${phymem}
64
+ fi
42
65
}
Original file line number Diff line number Diff line change @@ -56,15 +56,21 @@ function testUfw() {
56
56
assertContains " OpenSSH" " ${ufw_status} "
57
57
}
58
58
59
+ function testSwap() {
60
+ createSwap
61
+
62
+ assertContains " /swapfile" " $( ls -lh /swapfile) "
63
+ assertContains " /swapfile" " $( sudo swapon --show) "
64
+ }
65
+
59
66
function testTeardown () {
60
67
echo " Test Teardown"
61
68
62
69
deleteTestUser
63
70
revertSudoers
64
71
revertSSHConfig
65
-
66
- sudo ufw delete allow OpenSSH
67
- sudo ufw disable
72
+ revertUfw
73
+ deleteSwap
68
74
}
69
75
70
76
# ## Helper Functions ###
@@ -89,4 +95,14 @@ function revertSSHConfig() {
89
95
sudo rm -rf /etc/ssh/sshd_config.old
90
96
}
91
97
98
+ function revertUfw() {
99
+ sudo ufw delete allow OpenSSH
100
+ sudo ufw disable
101
+ }
102
+
103
+ function deleteSwap() {
104
+ sudo swapoff /swapfile
105
+ sudo rm /swapfile
106
+ }
107
+
92
108
runUnitTests
You can’t perform that action at this time.
0 commit comments