forked from adeept/adeept_picarpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
146 lines (113 loc) · 3.9 KB
/
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
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
#!/usr/bin/python3
# File name : setup.py
# Author : Adeept
# Date : 2020/3/14
import os
import time
curpath = os.path.realpath(__file__)
thisPath = "/" + os.path.dirname(curpath)
def replace_num(file,initial,new_num):
newline=""
str_num=str(new_num)
with open(file,"r") as f:
for line in f.readlines():
if(line.find(initial) == 0):
line = (str_num+'\n')
newline += line
with open(file,"w") as f:
f.writelines(newline)
for x in range(1,4):
if os.system("sudo apt-get update") == 0:
break
os.system("sudo apt-get purge -y wolfram-engine")
os.system("sudo apt-get purge -y libreoffice*")
os.system("sudo apt-get -y clean")
os.system("sudo apt-get -y autoremove")
# for x in range(1,4):
# if os.system("sudo apt-get -y upgrade") == 0:
# break
for x in range(1,4):
if os.system("sudo pip3 install -U pip") == 0:
break
for x in range(1,4):
if os.system("sudo apt-get install -y python-dev python-pip libfreetype6-dev libjpeg-dev build-essential") == 0:
break
for x in range(1,4):
if os.system("sudo -H pip3 install --upgrade luma.oled") == 0:
break
for x in range(1,4):
if os.system("sudo apt-get install -y i2c-tools") == 0:
break
for x in range(1,4):
if os.system("sudo apt-get install -y python3-opencv") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install adafruit-pca9685") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install rpi_ws281x") == 0:
break
for x in range(1,4):
if os.system("sudo apt-get install -y python3-smbus") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install mpu6050-raspberrypi") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install flask") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install flask") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install flask_cors") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install websockets") == 0:
break
try:
replace_num("/boot/config.txt",'#dtparam=i2c_arm=on','dtparam=i2c_arm=on\nstart_x=1\n')
except:
print('try again')
for x in range(1,4):
if os.system("sudo pip3 install numpy") == 0:
break
for x in range(1,4):
if os.system("sudo apt-get -y install libqtgui4 libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev libqt4-test") == 0:
break
for x in range(1,4):
if os.system("sudo pip3 install imutils zmq pybase64 psutil") == 0: ####
break
for x in range(1,4):
if os.system("sudo git clone https://github.com/oblique/create_ap") == 0:
break
try:
os.system("cd " + thisPath + "/create_ap && sudo make install")
except:
pass
try:
os.system("cd //home/pi/create_ap && sudo make install")
except:
pass
for x in range(1,4):
if os.system("sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq") == 0:
break
try:
os.system('sudo touch //home/pi/startup.sh')
with open("//home/pi/startup.sh",'w') as file_to_write:
#you can choose how to control the robot
file_to_write.write("#!/bin/sh\nsudo python3 " + thisPath + "/server/webServer.py")
# file_to_write.write("#!/bin/sh\nsudo python3 " + thisPath + "/server/server.py")
except:
pass
os.system('sudo chmod 777 //home/pi/startup.sh')
replace_num('/etc/rc.local','fi','fi\n//home/pi/startup.sh start')
try: #fix conflict with onboard Raspberry Pi audio
os.system('sudo touch /etc/modprobe.d/snd-blacklist.conf')
with open("/etc/modprobe.d/snd-blacklist.conf",'w') as file_to_write:
file_to_write.write("blacklist snd_bcm2835")
except:
pass
print('The program in Raspberry Pi has been installed, disconnected and restarted. \nYou can now power off the Raspberry Pi to install the camera and driver board (Robot HAT). \nAfter turning on again, the Raspberry Pi will automatically run the program to set the servos port signal to turn the servos to the middle position, which is convenient for mechanical assembly.')
print('restarting...')
os.system("sudo reboot")