-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_hueBerry.py
147 lines (130 loc) · 5.27 KB
/
install_hueBerry.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
147
"""
Python installer for hueberry. Probably now, the best thing in the world!
"""
import sys
import os
#import shutil
#import imp
import subprocess
from contextlib import contextmanager
@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
try:
yield
finally:
os.chdir(prevdir)
def myrun(cmd):
"""from http://blog.kagesenshi.org/2008/02/teeing-python-subprocesspopen-output.html
"""
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout = []
while True:
line = p.stdout.readline()
stdout.append(line)
print line,
if line == '' and p.poll() != None:
break
return ''.join(stdout)
#Installer shold be self contained so don't import this. Just create it here
class bcolors:
PRPL = '\033[95m'
BLU = '\033[94m'
GRN = '\033[92m'
YLO = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
temp = os.popen("cat /etc/os-release | grep raspbian").read()
#print temp
result_array = temp.split('\n')
num_groups = len(result_array) - 1
#print num_groups
if(num_groups != 4):
print(bcolors.RED+"This OS is not Raspbian. It does not meet the directory structure requirements of this installer. Exiting"+bcolors.ENDC)
sys.exit()
else:
print(bcolors.GRN+"Looks like you're running Rasbian! Good start!"+bcolors.ENDC)
#shutil.copy(pythondaemon.py,/home/pi/pythondaemon.py)
print(bcolors.BOLD+"Checking required modules. Please wait..."+bcolors.ENDC)
req_modules = ['pigpio','authenticate','Adafruit_SSD1306','RPi','rotary_encoder','PIL']
n2install = []
for x in req_modules:
try:
#imp.find_module(x)
#import Adafruit_SSD1306
new_module = __import__(x)
found = True
except ImportError:
print(" " + bcolors.YLO + str(x) + bcolors.ENDC + bcolors.RED + " module not found. Please install this before continuing!"+bcolors.ENDC)
n2install.append(x)
print("\r")
#p = subprocess.Popen('htop')
#p.wait()
if len(n2install) > 0:
#something wrong with this function... can't initiate apt-get update for some reason
print("Looks like we have some requirements! Updating system repo!\n")
#p = subprocess.Popen("sudo apt-get update")
#p.wait()
#cout = os.popen("apt-get update").read()
#print cout
myrun("apt-get -q update")
#myrun("apt-get -y -V -q dist-upgrade")
print("Finished updating system repository\n\n")
#print "test finished"
#sys.exit()
baremetal = 0
for x in n2install:
if x == 'pigpio':
print("Installing " +str(x))
myrun("rm master.zip; sudo rm -rf pigpio-master; wget https://github.com/joan2937/pigpio/archive/master.zip && unzip master.zip ")
with cd("pigpio-master/"):
myrun("sudo make -j4 && sudo make install && sudo pigpiod ")
print("Done installing " +str(x)+"\n\n")
if x == 'authenticate':
print(bcolors.YLO + "The " +str(x)+" module should be in the same directory. Since it's not I guess you want a bare metal install?" + bcolors.ENDC + "\n\n")
baremetal = baremetal + 1
if x == 'Adafruit_SSD1306':
print("Installing " +str(x)+"\n\n")
myrun("sudo apt-get -y install build-essential python-dev python-pip && sudo pip install RPi.GPIO && sudo apt-get -y install python-imaging python-smbus && sudo apt-get install -y git && git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git ")
with cd("Adafruit_Python_SSD1306/"):
myrun("sudo python setup.py install")
print("Done installing " +str(x)+"\n\n")
if x =='RPi':
print(bcolors.RED + " wtf, the " +str(x)+" module should be part of the most recent Raspberry Pi distribution.\nAre you even running this on a Pi?" + bcolors.ENDC + "\n\n")
print(" installing anyway. lel")
myrun("sudo pip install RPi.GPIO")
if x == 'rotary_encoder':
print(bcolors.YLO + "The " +str(x)+" module should be in the same directory. Since it's not I guess you want a bare metal install?" + bcolors.ENDC + "\n\n")
if x == 'PIL':
try:
import PIL
except ImportError:
myrun("sudo -H pip install --upgrade pillow")
#myrun("echo ididathing && echo doing another thing && echo doing a third thing").read()
baremetal = baremetal + 1
#print baremetal
if baremetal > 0:
print("" + bcolors.BOLD + "Downloading dev branch of hueBerry" + bcolors.ENDC)
myrun("runuser -l pi -c 'git clone -b dev https://github.com/fiveseven808/HueBerry_SmartSwitch.git'")
print("Cloned Repo ")
print("Gonna enable I2c and OC the bus")
with open("/boot/config.txt", "a") as myfile:
myfile.write("\ndtparam=i2c_baudrate=400000")
print("Enabled I2c OC parameter")
finalreadme = """
\rHow to run:
[REQUIRED] Ensure that I2c is enabled and that the display and rotary encoder are wired up properly
[Optional] Disable X and decrease GPU mem to minimum
[Optional] Overclock SD card
Then run the following commands:
cd HueBerry_SmartSwitch
sudo pigpiod (if not PiGPIOd is not running already)
sudo python hueberry.py [&]
& Sets the program to run in the background
(You can see more debug messages if you omit this)
Enjoy!
"""
print(finalreadme)