forked from ryanmccartney/Autonomous_Electric_Wheelchair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
56 lines (45 loc) · 1.69 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
#NAME: install.py
#DATE: Monday 5th August 2019
#AUTH: Ryan McCartney
#DESC: A python script for installing wheelchair API utility
#COPY: Copyright 2019, All Rights Reserved, Ryan McCartney
import os
import json
settingFilePath = "api/settings.json"
def getDependencies():
#Install Dependencies
os.system("sudo pip3 install --upgrade pip")
os.system("sudo pip3 install CherryPy")
os.system("sudo pip3 install pyserial")
os.system("sudo pip3 install pygame")
def setupPythonStartup():
cwd = os.getcwd()
startupFile = "/etc/rc.local"
startupFileContents = None
cdCommand ="cd "+str(cwd)
startCommand="sudo python3 "+str(cwd)+"/api/startup.py"
with open(startupFile, 'r') as file:
startupFileContents = file.readlines()
lineNumber = len(startupFileContents)-1
startupFileContents.insert(lineNumber,cdCommand + "\n")
lineNumber = len(startupFileContents)-1
startupFileContents.insert(lineNumber,startCommand + "\n")
with open(startupFile,'w') as file:
file.writelines(startupFileContents)
def changeHostname():
#Change Hostname
hostname = settings["hostname"]
os.system("sudo hostname "+hostname)
if __name__ == '__main__':
#Load Settings File
settingsFile = open(settingFilePath,"r")
settings = json.load(settingsFile)
settingsFile.close()
print("INFO: Installing "+settings["serverName"])
print("INFO: Getting dependencies for operation")
getDependencies()
print("INFO: Setting up Raspberry Pi to run pyapi on startup")
setupPythonStartup()
print("INFO: Changing hostname")
changeHostname()
print("INFO: Installation complete. Please reboot.")