forked from MAKOMO/RaspiWiFi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitial_setup.py
118 lines (101 loc) · 4.42 KB
/
initial_setup.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
import subprocess
import fileinput
import os
import sys
def install_prereqs():
project_path = os.path.dirname(os.path.abspath(__file__))
print("Updating Apt...")
os.system('apt update')
print("Installing prerequisites via Apt...")
os.system('apt install python3 bundler libsqlite3-dev dnsmasq nodejs rpi.gpio hostapd libxml2-dev libxslt-dev -y')
print("Installing necessary Ruby Gems. This can take a few minutes...")
os.system('gem install nokogiri --no-document -v 1.6.6.2 -- --use-system-libraries')
os.system('bundle install --gemfile=' + project_path + '/Configuration_App/Gemfile')
def update_config_paths():
project_path = os.path.dirname(os.path.abspath(__file__))
os.system('sudo cp -a Reset_Device/static_files/rc.local.aphost.template Reset_Device/static_files/rc.local.aphost')
os.system('sudo cp -a Reset_Device/static_files/rc.local.apclient.template Reset_Device/static_files/rc.local.apclient')
os.system('sudo cp -a Reset_Device/reset.py.template Reset_Device/reset.py')
with fileinput.FileInput("Reset_Device/static_files/rc.local.aphost", inplace=True) as file:
for line in file:
print(line.replace("[[project_dir]]", project_path), end='')
file.close
with fileinput.FileInput("Reset_Device/static_files/rc.local.apclient", inplace=True) as file:
for line in file:
print(line.replace("[[project_dir]]", project_path), end='')
file.close
with fileinput.FileInput("Reset_Device/reset.py", inplace=True) as file:
for line in file:
print(line.replace("[[project_dir]]", project_path), end='')
file.close
#################################################################
#################################################################
print()
print("###################################")
print("##### RaspiWiFi Intial Setup #####")
print("###################################")
print()
print()
install_prereqs_ans = input("Would you like to install prerequisite files (This can take up to 5 minutes)? (y/n): ")
if(install_prereqs_ans == 'y'):
print()
print("Updating system...")
install_prereqs()
else:
print()
print()
print("===================================================")
print("---------------------------------------------------")
print()
print("No Prerequisites installed. Continuing to configuration file installation...")
print()
print("---------------------------------------------------")
print("===================================================")
print()
print()
print()
print()
print()
print()
run_setup_ans = input("Would you like to run the initial setup for RaspiWiFi? (y/n): ")
if(run_setup_ans == 'y'):
print("Updating config files and copying them...")
update_config_paths()
os.system('sudo rm -f /etc/wpa_supplicant/wpa_supplicant.conf.OLD')
os.system('sudo mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.OLD')
os.system('sudo rm -f ./tmp/*')
os.system('sudo cp ./Reset_Device/static_files/dhcpcd.conf.aphost /etc/dhcpcd.conf')
os.system('sudo cp ./Reset_Device/static_files/dnsmasq.conf /etc/dnsmasq.conf')
os.system('sudo cp ./Reset_Device/static_files/hostapd.conf /etc/hostapd/hostapd.conf')
os.system('sudo cp ./Reset_Device/static_files/default_hostapd /etc/default/hostapd')
os.system('sudo cp ./Reset_Device/static_files/rc.local.aphost /etc/rc.local')
os.system('sudo chown root.netdev /etc/dhcpcd.conf')
os.system('sudo chmod 664 /etc/dhcpcd.conf')
os.system('sudo chown root.root /etc/hostapd/hostapd.conf')
os.system('sudo chmod 644 /etc/hostapd/hostapd.conf')
os.system('sudo chown root.root /etc/dnsmasq.conf')
os.system('sudo chmod 644 /etc/dnsmasq.conf')
os.system('sudo chown root.root /etc/default/hostapd')
os.system('sudo chmod 644 /etc/default/hostapd')
os.system('sudo chown root.root /etc/rc.local')
os.system('sudo chmod 755 /etc/rc.local')
else:
print()
print()
print("===================================================")
print("---------------------------------------------------")
print()
print("RaspiWiFi initial setup cancelled. No changes made.")
print()
print("---------------------------------------------------")
print("===================================================")
print()
print()
sys.exit(0)
print()
print()
reboot_ans = input("Initial setup is complete. A reboot is required, would you like to do that now? (y/n): ")
if(run_setup_ans == 'y' and reboot_ans == 'y'):
os.system('sudo systemctl enable dnsmasq')
os.system('sudo systemctl enable hostapd')
os.system('sudo reboot')