forked from mbernst/lab8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-setup.sh
227 lines (188 loc) · 4.86 KB
/
check-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
short_system=$(uname -s)
sys_vagrant="0"
sys_cygwin="0"
sys_osx="0"
mongo_missing="0"
node_missing="0"
heroku_missing="0"
npm_missing="0"
# set this to the number of the current lab
cur_lab=8
system=$(uname -a)
if [ "$system" == "Linux precise32 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux" ]
then
sys_vagrant="1"
echo "Running on Vagrant guest"
user=$(whoami)
if [ "$user" != "root" ]
then
echo "ERROR: You must run this script with sudo"
exit
fi
elif [ $short_system == "Darwin" ]
then
sys_osx="1"
echo "Running on Mac OSX"
else
sys_cygwin="1"
echo "Running on Windows"
fi
if [ "$sys_vagrant" == "1" ]
then
# on vagrant guest
required_pkg=( "mongo" "heroku" "node" "npm")
all_present="1"
for i in ${required_pkg[@]}
do
binloc="$(which $i)"
if [ "${#binloc}" == "0" ]
then
echo "You don't have $i"
all_present="0"
if [ "$i" == "mongo" ]
then
mongo_missing="1"
elif [ "$i" == "heroku" ]
then
heroku_missing="1"
elif [ "$i" == "node" ]
then
node_missing="1"
elif [ "$i" == "npm" ]
then
npm_missing="1"
fi
fi
done
if [ "$mongo_missing" == "1" ]
then
echo "Installing MongoDB..."
mongo_res=$(
mkdir -p /data/db;
chown vagrant /data/db;
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10;
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list;
apt-get update;
apt-get install -y mongodb-10gen;)
mongo_loc=$(which mongo)
if [ "${#mongo_loc}" == "0" ]
then
echo "Auto install failed."
else
echo "Auto install succeeded"
fi
fi
if [ "$heroku_missing" == "1" ]
then
heroku_res=$(echo "Installing Heroku Toolbelt...";
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh)
heroku_loc=$(which heroku)
if [ "${#heroku_loc}" == "0" ]
then
echo "Auto install failed."
else
echo "Auto install succeeded"
fi
fi
if [ "$node_missing" == "1" ]
then
echo "Installing nodejs"
node_res=$(apt-get -y install nodejs)
node_loc=$(which node)
if [ "${#node_loc}" == "0" ]
then
echo "Auto install failed."
else
echo "Auto install succeeded"
fi
fi
if [ "$npm_missing" == "1" ]
then
echo "Installing npm"
npm_res=$(apt-get -y install npm)
npm_loc=$(which npm)
if [ "${#npm_loc}" == "0" ]
then
echo "Auto install failed."
else
echo "Auto install succeeded"
fi
fi
# current lab hardcoded
node_status=$(cd lab4;npm ls 2>&1)
if [[ $node_status == *"UNMET DEPENDENCY"* ]]
then
echo "FAIL: Node is missing packages"
echo "Attempting to repair."
install_status=$(cd lab4; npm -y install --no-bin-links)
node_status=$(cd lab4;npm ls 2>&1)
if [[ $node_status != *"UNMET DEPENDENCY"* ]]
then
echo "PASS: Repair successful. All node packages installed."
fi
fi
# change ssh timeout to fix disconnect issues
ssh_result=$(grep "Setup SSH timeouts" /etc/ssh/sshd_config | wc -l | xargs)
if [ $ssh_result != "1" ]
then
echo "Patching ssh timeout configuration."
echo -e "\n# Setup SSH timeouts\nClientAliveInterval 30\nClientAliveCountMax 4" >> /etc/ssh/sshd_config
echo -e "\n# Setup SSH timeouts\nServerAliveInterval 30\nServerAliveCountMax 4" >> /etc/ssh/ssh_config
/etc/init.d/ssh restart > /dev/null
fi
if [ $all_present == "1" ]
then
echo "PASS: Vagrant is correctly set up."
fi
else
if [ "$sys_osx" == "1" ]
then
#on osx host system
dirloc="$(pwd)"
IFS=/ read -a dirarr <<< "$dirloc"
if [ "${dirarr[4]}" != "introHCI" ]
then
echo "FAIL: Either you are not running this script in the introHCI directory or your directory is named incorrectly."
else
echo "PASS: introHCI directory named and positioned correctly"
fi
elif [ "$sys_cygwin" == "1" ]
then
dirloc="$(pwd)"
IFS=/ read -a dirarr <<< "$dirloc"
if [ "${dirarr[5]}" != "introHCI" ]
then
echo "FAIL: Either you are not running this script in the introHCI directory or your directory is named incorrectly."
else
echo "PASS: introHCI directory named and positioned correctly"
fi
fi
vagrant_check=$(grep MSB Vagrantfile | wc -l | xargs)
if [ $vagrant_check == "4" ]
then
echo "PASS: You are using the correct Vagrantfile"
else
echo "FAIL: CS147 Vagrantfile not found. Are you running this in the introHCI directory?"
fi
missing_dirs="0"
hcidirs=$(ls)
# current lab hardcoded
for i in {1..6}
do
target_dir="lab$i"
if [[ $hcidirs == *"$target_dir"* ]]
then
echo "Found $target_dir"
else
echo "ERROR: Cannot find $target_dir"
missing_dirs="1"
fi
done
if [ $missing_dirs == "1" ]
then
echo "FAIL: Your introHCI directory is missing the above lab folders."
else
echo "PASS: All required lab directories present."
fi
fi