-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·80 lines (63 loc) · 1.75 KB
/
install.py
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
#!/usr/bin/env python
import binascii
import enc
import sys
from subprocess import call
import datetime
import os
import hashlib
import ConfigParser
import getpass
import qrcode
import csv
from os.path import join
import shutil
KEY_NUM = 256
KEY_SIZE = 16
def gen_keyfile(in_file,password):
with open("ckeys", 'wb') as keyfile:
keys = enc.encrypt(in_file,keyfile,password)
keyfile.close()
def get_hash(password):
with open("ckeys", 'rb') as keyfile:
keys = enc.decrypt(keyfile,password)
hash = hashlib.sha1(keys).hexdigest()
keyfile.close()
return hash
def open_keyfile(password,hash):
with open("ckeys", 'rb') as keyfile:
keys = enc.decrypt(keyfile, password)
ok = (hashlib.sha1(keys).hexdigest() == hash)
keyfile.close()
return ok
###########################################################################################
print("SPHERE Deployment Manager - Installation Script")
if (os.path.isfile('ckeys')):
print("Key file 'ckeys' already exists. Manually delete it to reinstall.")
sys.exit(1)
print("Set password for key file.")
password = getpass.getpass()
with open('tmp', 'wb') as f:
f.write(os.urandom(KEY_NUM*KEY_SIZE))
f.close()
with open('tmp', 'rb') as f:
gen_keyfile(f,password)
f.close()
os.remove('tmp')
with open('ckeys.hash', 'w') as f:
hash = get_hash(password)
f.write(hash)
f.close()
print("Type password again.")
password = getpass.getpass()
ok = open_keyfile(password,hash)
if(not ok):
print("Wrong password. Try again.")
os.remove('ckeys')
os.remove('ckeys.hash')
sys.exit(1)
with open("sphere_network_id.csv", 'w') as f:
f.write("Network ID (NID), House ID (HID), Allocated, Active\n")
for i in range(KEY_NUM):
f.write(str(i) + ",-1,,\n")
print("Installation Complete.")