-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfmka.py
executable file
·121 lines (108 loc) · 3.38 KB
/
fmka.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
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
#!/usr/bin/env python
# Tool's name is Firmware Modify Kit for Avalon(FMKA)
#
# October 2017 Zhenxing Xu <[email protected]>
import os
import time
def network_cmd(net):
cmd = "./config_image.sh --network %s" %(net)
os.system(cmd)
def ntp_cmd(ntp):
cmd = "./config_image.sh --ntp %s" %(ntp)
os.system(cmd)
def pool_cmd(pool):
cmd = "./config_image.sh --pools %s" %(pool)
os.system(cmd)
# Download img gz file
def download_img():
conf = open("default.conf")
for dl in conf.readlines():
if (dl.find('avalon_type') != -1):
if (dl[0] == '#'):
continue
dl = dl[len("avalon_type"):]
break
conf.close()
conf = open("default.conf")
for ctl in conf.readlines():
if (ctl.find('controller_type') != -1):
if (ctl[0] == '#'):
continue
ctl = ctl[len("controller_type"):]
break
conf.close()
img_type = dl.strip() + " " + ctl.strip()
cmd = "./download.sh %s" %(img_type)
os.system(cmd)
time.sleep(3)
# Mount img file
def mount_img():
conf = open("default.conf")
for mt in conf.readlines():
if (mt.find('controller_type') != -1):
if (mt[0] == '#'):
continue
cmd = "./config_image.sh --mount %s" %(mt.strip())
os.system(cmd)
break
conf.close()
# Network
def network():
conf = open("default.conf")
for net in conf.readlines():
if (net.find('ipaddr') != -1) or (net.find('gateway') != -1) or \
(net.find('dns') != -1) or (net.find('broadcast') != -1):
if (net[0] == '#'):
continue
network_cmd(net.strip())
elif (net.find('dhcp') != -1):
if (net[0] == '#'):
continue
network_cmd(net.strip())
break
conf.close()
# Timezone
def timezone():
conf = open("default.conf")
for time in conf.readlines():
if (time.find('zonename') != -1):
if (time[0] == '#'):
continue
cmd = "./config_image.sh --timezone %s" %(time.strip())
os.system(cmd)
break
conf.close()
# Ntp server
def ntp_server():
conf = open("default.conf")
for ntp in conf.readlines():
if (ntp.find('ntp_server') != -1) or (ntp.find('candidates1') != -1) or \
(ntp.find('candidates1') != -1) or (ntp.find('candidates2') != -1) or \
(ntp.find('candidates3') != -1) or (ntp.find('candidates4') != -1):
if (ntp[0] == '#'):
continue
ntp_cmd(ntp.strip())
conf.close()
# Pools Workers
def pools():
conf = open("default.conf")
for pool in conf.readlines():
if (pool.find('pool1url') != -1) or (pool.find('pool1user') != -1) or (pool.find('pool1pw') != -1) or \
(pool.find('pool2url') != -1) or (pool.find('pool2user') != -1) or (pool.find('pool2pw') != -1) or \
(pool.find('pool3url') != -1) or (pool.find('pool3user') != -1) or (pool.find('pool3pw') != -1):
if (pool[0] == '#'):
continue
pool_cmd(pool.strip())
conf.close()
# Umount img file
def umount_img():
os.system("./config_image.sh --umount")
if __name__ == "__main__":
download_img()
mount_img()
network()
timezone()
ntp_server()
pools()
umount_img()
print("firmwae config success.")