-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.py
More file actions
383 lines (347 loc) · 11.9 KB
/
install.py
File metadata and controls
383 lines (347 loc) · 11.9 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import os
import subprocess
import socket
import fcntl
import struct
import urllib
import sys
import getpass
from subprocess import Popen
global rem_file
global loc_file
global message
global user
global master_ip
global ret_ip
def this_ip(ifname):
soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(soc.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
def dlProgress(count, blockSize, totalSize):
percent = int(count*blockSize*100/totalSize)
sys.stdout.write("\r" + message + "%d%%]" % percent)
sys.stdout.flush()
#Future: Combine following define "insert" methods
def insertRootRhost():
master_in_file = False
slave_in_file = False
directory = "/root/.rhosts"
this_user = "root"
for line in open(directory):
if "Master " + this_user in line:
master_in_file = True
if "Slave " + this_user in line:
slave_in_file = True
with open(directory, "a") as rhosts:
if master_in_file == False:
rhosts.write("\nMaster " + this_user)
if slave_in_file == False:
rhosts.write("\nSlave " + this_user)
def insertMasterRhost(master_user_add):
directory = "/home/" + master_user_add + "/.rhosts"
master_in_file = False
for line in open(directory):
if "Master " + master_user_add in line:
master_in_file = True
with open(directory, "a") as rhosts:
if master_in_file == False:
rhosts.write("\nMaster " + master_user_add)
def insertUserRhost(user_add):
directory = "/home/" + user + "/.rhosts"
slave_in_file = False
for line in open(directory):
if "Slave " + user_add in line:
slave_in_file = True
with open(directory, "a") as rhosts:
if slave_in_file == False:
rhosts.write("\nSlave " + user_add)
def insertUserHost(host_ip_add):
directory = "/etc/hosts"
slave_ip_in_file = False
for line in open(directory):
if host_ip_add + " Slave" in line:
slave_ip_in_file = True
with open(directory, "a") as hosts:
if slave_ip_in_file == False:
hosts.write("\n" + host_ip_add + " Slave")
def insertHostAllow(host_ip_allow):
directory = "/etc/hosts.allow"
host_already_allowed = False
for line in open(directory):
if host_ip_allow in line:
host_already_allowed = True
with open(directory, "a") as allowed:
if host_already_allowed == False:
allowed.write("\n" + host_ip_allow)
def insertMasterHost(master_ip_add):
directory = "/etc/hosts"
master_ip_in_file = False
for line in open(directory):
if master_ip_add + " Master" in line:
master_ip_in_file = True
with open(directory, "a") as hosts:
if master_ip_in_file == False:
hosts.write("\n" + master_ip_add + " Master")
def insertSectretty():
directory = "/etc/securetty"
securetty_root_string = "rsh, rlogin, rexec, pts/0, pts/1"
securetty_in_file = False
for line in open(directory):
if securetty_root_string in line:
securetty_in_file = True
with open(directory, "a") as securetty:
if securetty_in_file == False:
securetty.write("\n" + securetty_root_string)
def getIP():
getting_ip = True
adap_count = 0
wlan_test = False
while getting_ip:
if wlan_test == False:
adaptor = "eth" + str(adap_count)
else:
adaptor = "wlan" + str(adap_count)
print "Trying connection on " + adaptor + "..."
try:
ret_ip = this_ip(adaptor)
print "Connection found on " + adaptor
getting_ip = False
except IOError:
print "Error: Failed on eth" + adap_count
if adap_count == 5:
adap_count = 0
if wlan_test == False:
wlan_test = True
else:
new_adap = True
new_adap_name = raw_input("Error: Cannot find connection. Specify adaptor name:")
while new_adap:
try:
ret_ip = this_ip(new_adap_name)
new_adap = False
getting_ip = False
print "Connection found on " + new_adap_name
except IOError:
new_adap_name = raw_input("Error: Cannot find specified adaptor. Specify another or type \"c\" to exit:")
if new_adap_name == "c":
sys.exit()
return ret_ip
def insertRshContent():
auth1_text = "auth sufficient /lib/security/pam_nologin.so"
auth2_text = "auth optional /lib/security/pam_securetty.so"
auth3_text = "auth sufficient /lib/security/pam_env.so"
auth4_text = "auth sufficient /lib/security/pam_rhosts_auth.so"
account_text = "account sufficient /lib/security/pam_stack.so service=system-auth"
session_text = "session sufficient /lib/security/pam_stack.so service=system-auth"
directory = "/etc/pam.d/rsh"
auth1_text_bool = False
auth2_text_bool = False
auth3_text_bool = False
auth4_text_bool = False
account_text_bool = False
session_text_bool = False
for line in open(directory):
if auth1_text in line:
auth1_text_bool = True
if auth2_text in line:
auth2_text_bool = True
if auth3_text in line:
auth3_text_bool = True
if auth4_text in line:
auth4_text_bool = True
if account_text in line:
account_text_bool = True
if session_text in line:
session_text_bool = True
with open(directory, "a") as rsh:
if auth1_text_bool == False:
rsh.write("\n" + auth1_text)
if auth2_text_bool == False:
rsh.write("\n" + auth2_text)
if auth3_text_bool == False:
rsh.write("\n" + auth3_text)
if auth4_text_bool == False:
rsh.write("\n" + auth4_text)
if account_text_bool == False:
rsh.write("\n" + account_text)
if session_text_bool == False:
rsh.write("\n" + session_text)
clear = Popen(["clear"])
waitclear = clear.wait()
user = getpass.getuser()
if user != "root":
print "Error: Please run the script as root. Type \"sudo !!\" to run the last command as root."
sys.exit()
print "==============MPICH2 v1.4.1 Python Installation Script v0.1 for RPi=============="
print "Please ensure that your IPs are statically allocated to your nodes on the bramble"
print "Dynamic allocation will cause IPs in config files to become redundant. Files will"
print "not be overwritten if they already exist, so don't worry about loosing any data. "
print "=================================================================================\n"
user = raw_input("Please enter your RPi (non root) username: ")
#Assign Popen commands to variable for future error analysing if needed
print "Creating /home/" + user + "/.rhosts file..."
touch = Popen(["touch", "/home/" + user + "/.rhosts"])
c1 = touch.wait()
print "Successfully created /home/" + user + "/.rhosts file"
print "Creating /root/.rhosts file..."
root_touch = Popen(["sudo", "touch", "/root/.rhosts"])
c2 = root_touch.wait()
print "Successfully created /root/.rhosts file"
print "Creating /etc/pam.d/rsh file..."
rshFile = Popen (["touch", "/etc/pam.d/rsh"])
createRsh = rshFile.wait()
print "Successfully created /etc/pam.d/rsh"
print "Creating /etc/hosts file..."
hostsFile = Popen(["touch", "/etc/hosts"])
createHostsFile = hostsFile.wait()
print "Successfully created /etc/hosts"
print "Creating /etc/hosts.allow file..."
allowedHostsFile = Popen(["touch", "/etc/hosts.allow"])
createallowedHosts = allowedHostsFile.wait()
print "Successfully created /etc/hosts.allow"
print "Creating /etc/securetty file..."
securettyFile = Popen(["touch", "/etc/securetty"])
createScuretty = securettyFile.wait()
print "Successfully created /etc/securetty\n"
insertRshContent()
insertSectretty()
master_slave = raw_input("Is this the Master or a Slave node? [M/S]: ")
while master_slave not in ["M", "S"]:
master_slave = raw_input("Error: \"" + master_slave + "\" not a selection. Is this the Master or a Slave node? [M/S]: ")
if master_slave in "M":
insertMasterRhost(user)
insertRootRhost()
master_ip = getIP()
insertMasterHost(master_ip)
print "IP address is: " + master_ip
print ""
done = False
Error = False
while True:
try:
if Error == False:
loop_count = int(raw_input("Enter number of Slave nodes: "))
else:
loop_count = int(raw_input("Error: Not a number. Enter number of Slave nodes: "))
break
except (SyntaxError, ValueError, NameError):
Error = True
print ""
count = 0
while count < loop_count:
if count == 0:
current_usr = raw_input("Enter username for first Slave node: ")
else:
current_usr = raw_input("Enter username for next Slave node: ")
ip_valid = False
bad_ip = False
while ip_valid == False:
if bad_ip == True:
current_ip = raw_input("Error: Invalid IPv4 address. Enter IP for Slave node " + current_usr + ": ")
else:
current_ip = raw_input("Enter IP for Slave node " + current_usr + ": ")
try:
socket.inet_aton(current_ip)
if len(current_ip.split(".")) == 4:
ip_valid = True
else:
bad_ip = True
except socket.error:
bad_ip = True
insertUserHost(current_ip)
insertUserRhost(current_usr)
insertHostAllow(current_ip)
print ""
count += 1
elif master_slave in "S":
insertRootRhost()
this_slave_ip = getIP()
print "IP address is: " + this_slave_ip
print ""
master_user = raw_input("Master node username: ")
master_ip = raw_input("Master node IP address: ")
insertMasterRhost(master_user)
insertMasterHost(master_ip)
insertUserHost(this_slave_ip)
insertHostAllow(master_ip)
done = False
Error = False
not_answer = False
while True:
if not not_answer:
other_nodes = raw_input("\nIs this the only Slave node? [Y/N]: ")
else:
other_nodes = raw_input("Error: " + other_nodes + " not an selection. Is this the only Slave node? [Y/N]: ")
if other_nodes == "N":
while True:
try:
if Error == False:
loop_count = int(raw_input("Enter number of other Slave nodes (not including this node): "))
else:
loop_count = int(raw_input("Error: Not a number. Enter number of Slave nodes (not including this node): "))
break
except (SyntaxError, ValueError, NameError):
Error = True
break
elif other_nodes == "Y":
loop_count = 0
break
else:
not_answer = True
print ""
count = 0
while count < loop_count:
if count == 0:
current_usr = raw_input("Enter username for first Slave node (not including this node): ")
else:
current_usr = raw_input("Enter username for next Slave node (not including this node): ")
ip_valid = False
bad_ip = False
while ip_valid == False:
if bad_ip == True:
current_ip = raw_input("Error: Invalid IPv4 address. Enter IP for Slave node " + current_usr + ": ")
else:
current_ip = raw_input("Enter IP for Slave node " + current_usr + ": ")
try:
socket.inet_aton(current_ip)
if len(current_ip.split(".")) == 4:
ip_valid = True
else:
bad_ip = True
except socket.error:
bad_ip = True
insertUserHost(current_ip)
insertUserRhost(current_usr)
insertHostAllow(current_ip)
print ""
count += 1
if not os.path.isfile("/home/" + user + "/mpich2_1.4.1p1-1_armel.deb"):
sys.stdout.write("Downloading MPICH2 .deb package [0%]")
sys.stdout.flush()
message = "Downloading MPICH2 .deb package ["
rem_file = "https://github.com/downloads/philleonard/MPICH2-Armel-Raspberry-Pi/mpich2_1.4.1p1-1_armel.deb"
loc_file = "/home/" + user + "/mpich2_1.4.1p1-1_armel.deb"
urllib.urlretrieve(rem_file, loc_file, reporthook=dlProgress)
print ""
print "Successfully downloaded package\n"
else:
print "Skipping download. mpich2_1.4.1p1-1_armel.deb already exists.\n"
print "Depackaging and installing .deb..."
dpkg = Popen(["sudo", "dpkg", "-i", "mpich2_1.4.1p1-1_armel.deb"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
c4 = dpkg.wait()
print "Successfully installed package\n"
if not os.path.isfile("/home/" + user + "/cpi_test.tar.gz"):
sys.stdout.write("Downloading C test files tarball: [0%]")
sys.stdout.flush()
message = "Downloading C test files tarball: ["
rem_file = "https://github.com/downloads/philleonard/MPICH2-Armel-Raspberry-Pi/cpi_test.tar.gz"
loc_file = "/home/" + user + "/cpi_test.tar.gz"
urllib.urlretrieve(rem_file, loc_file, reporthook=dlProgress)
print ""
print "Successfully downloaded cpi_test.tar.gz\n"
else:
print "Skipping download. cpi_test.tar.gz already exists.\n"
print "Untaring cpi_test.tar.gz..."
untar = Popen(["tar", "-zxvf", "/home/" + user + "/cpi_test.tar.gz"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
untarWait = untar.wait()
print "Successfully extracted test files."
print "\nInstallation on this node complete!"