-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_ISIS_frontend.sh
More file actions
executable file
·278 lines (239 loc) · 6.18 KB
/
install_ISIS_frontend.sh
File metadata and controls
executable file
·278 lines (239 loc) · 6.18 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
set -x
url="https://github.com/HazCod/ISIS-frontend.git"
user="isis"
dir="/home/$user/ISIS-frontend"
cron="*/1 * * * * /home/isis/ISIS-frontend/check_assignments.py &>/dev/null"
function isPackageInstalled() {
return sudo dpkg-query -l | grep $1 | wc -l
}
function installPackage() {
sudo apt-get -q -y install $1
}
function valid_ip() {
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
function installDependencies {
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
installPackage git
installPackage python
installPackage python-mysqldb
installPackage python-git
installPackage libssl-dev
installPackage iw
installPackage python-imaging
installPackage python-nmap
installPackage python-netaddr
installPackage wpasupplicant
installPackage ettercap-text-only
installPackage isc-dhcp-server
installPackage python-netifaces
installPackage nmap
}
function getFromGit {
/usr/bin/git clone $url $dir
sudo chown isis $dir
}
function checkDefArgs() {
if ! valid_ip $1; then
echo "Please provide a valid IP."
exit 1
fi
def_ip=$1
shift
if ! valid_ip $2; then
echo "Please provide a valid gateway IP.";
exit 1
fi
def_gateway=$2
shift
if ! $3 ~= ^[0-255]{4}$; then
echo "Please provide a valid netmask."
exit 1
fi
def_netmask=$3
shift
if ! valid_ip $4; then
echo "Please provide a valid dns IP.";
exit 1
fi
def_dns=$4
shift
}
function checkArgs() {
if ! valid_ip $1; then
echo "Please provide a valid IP."
exit 1
fi
ip=$1
if ! valid_ip $2; then
echo "Please provide a valid gateway IP.";
exit 1
fi
gateway=$2
if [[ $3 =~ ^[0-255]{4}$ ]]; then
echo "Please provide a valid netmask."
exit 1
fi
netmask=$3
if ! valid_ip $4; then
echo "Please provide a valid dns IP.";
exit 1
fi
dns=$4
}
function writeDefaultsIP() {
cd /etc/network/
echo "auto eth0" >> $1
echo "iface eth0 inet static" >> $1
echo "address $def_ip" >> $1
echo "netmask $def_netmask" >> $1
echo "gateway $def_gateway" >> $1
echo "dns-nameservers $def_dns" >> $1
}
function writeIP() {
sudo echo "auto lo" >> /etc/network/interfaces
sudo echo "iface lo inet loopback" >> /etc/network/interfaces
sudo echo "auto eth0" >> /etc/network/interfaces
sudo echo "iface eth0 inet static" >> /etc/network/interfaces
sudo echo "address $ip" >> /etc/network/interfaces
sudo echo "netmask $netmask" >> /etc/network/interfaces
sudo echo "gateway $gateway" >> /etc/network/interfaces
sudo echo "dns-nameservers $dns" >> /etc/network/interfaces
}
function installIP {
sudo -k
cd /etc/network/
mv interfaces interfaces.old
writeIP
sleep 5s #Silly bash, working faster then allowed.
sudo service networking restart
cd ~
}
function addToSudoers {
sudo adduser isis sudo
sudo echo "$user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
}
function chmodFiles {
sudo chmod -R +x $dir
#find $dir -type f -exec chmod +x {} \;
sudo chown -R isis:isis $dir
#find $dir -type f -exec chown isis {} \;
}
function setCron() {
crontab -l > mycron
echo "$cron" >> mycron
sudo /usr/bin/crontab mycron
rm mycron
}
function addUser {
sudo adduser isis
}
function usage {
echo "install_ISIS_frontend.sh";
echo "----------------------------";
echo "Usage: install_ISIS_frontend.sh [-d ip_address ip_gateway ip_netmask ip_dns] [ip_address ip_gateway ip_netmask ip_dns]";
echo "";
echo "Options:";
echo "-d default If DHCP or given IP settings don't work, it falls back to the following IP settings.";
}
# SCRIPT BEGIN
if [ "$(id -u)" != "0" ]; then
echo "Please run this script as root."
exit 1
fi
# if there are any arguments
if [ $# > 1 ]; then
# if we are giving a default value
if [ $1 = "-d" ]; then
# we must have at least 5 values (-d, ip, gateway, netmask, dns) OR 9 values.
if [ ! $# = 5 ] && ![ $# = 9 ]; then
usage
exit 1
fi
# 5 arguments, so dhcp with fallback defaults
if [ $# = 5]; then
shift
checkDefArgs $1 $2 $3 $4
else
# 9 arguments, so given value with fallback defaults.
shift
checkDefArgs $1 $2 $3 $4
checkArgs $1 $2 $3 $4
fi
# else we need 4 values (ip, gateway, netmask, dns)
elif [ $# = 4 ]; then
checkArgs $1 $2 $3 $4
else
usage
exit 1
fi
fi
function installHostname(){
sudo echo $1 > "/etc/hostname"
sudo sed -i -e "s/raspberrypi/$1/" /etc/hosts
sudo /etc/init.d/hostname.sh start
}
function installAircrack(){
wget http://download.aircrack-ng.org/aircrack-ng-1.2-beta2.tar.gz
tar -xzvf aircrack-ng-1.2-beta2.tar.gz
cd aircrack-ng-1.2-beta2
make
sudo make install
sudo airodump-ng-oui-update
cd ..
rm aircrack-ng-1.2-beta2.tar.gz
}
function installSslstrip(){
wget http://www.thoughtcrime.org/software/sslstrip/sslstrip-0.9.tar.gz
tar zxvf sslstrip-0.9.tar.gz
cd sslstrip-0.9
sudo python ./setup.py install
}
function createServersettings(){
read -p "give the address of the server" address
read -p "give the username of the server" server_username
echo "#!/usr/bin/python">/home/isis/ISIS-frontend/server_settings.py
echo "server_address=\""$address"\"">>/home/isis/ISIS-frontend/server_settings.py
echo "server_username=\""$server_username"\"">>/home/isis/ISIS-frontend/server_settings.py
echo "">>/home/isis/ISIS-frontend/server_settings.py
read -p "enter the name of the database" databaseName
read -p "enter the username of the database" databaseUser
read -p "enter the password for the database" databasePassword
echo "database_name=\""$databaseName"\"">>/home/isis/ISIS-frontend/server_settings.py
echo "database_user=\""$databaseUser"\"">>/home/isis/ISIS-frontend/server_settings.py
echo "database_password=\""$databasePassword"\"">>/home/isis/ISIS-frontend/server_settings.py
}
function copy_ssh(){
python $dir/copy_ssh.py
}
read -p "What hostname/ID should be given to this unit? This must be unique!" host
cd ~
addUser
installIP
installDependencies
getFromGit
installHostname $host
sudo service networking restart
addToSudoers
createServersettings
chmodFiles
setCron
cd ~
installAircrack
installSslstrip
copy_ssh
su isis
# SCRIPT END