This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
262 lines (216 loc) · 6.28 KB
/
fabfile.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
"""
Fabric commands to setup beaglebone
"""
from fabric.api import cd, env, lcd, put, prompt, local, sudo, prefix
from fabric.decorators import runs_once
from fabric.contrib.files import exists, sed
from fabric.contrib.console import confirm
from fabtools import require
import fabtools
try:
from fabhosts import bone
except ImportError:
pass
gage_folder = '/gage'
time_till_startup = '14'
time_till_watchdog = ''
startup_reasons = '0x09'
# startup_reasons:
# 0x01 START_BUTTON
# 0x02 START_EXTERNAL
# 0x04 START_PWRGOOD
# 0x08 START_TIMEOUT
# 0x0F START_ALL
# Most likely we want to use 0x09 so it will start with a button press or after
# a timeout
# set root password
# apt-get update
# apt-get upgrade
# install python packages
# git clone https://github.com/abkfenris/gage-beaglebone.git
# add config
# setup powercape
# create gage service
# systemctl enable gage-logger.service
# add gagerun to /boot/uboot
# create Sample and Config tables
def apt_upgrade():
"""
Update and upgrade apt
"""
require.deb.uptodate_index(max_age={'day': 1})
sudo('apt-get upgrade')
def mk_gage_folder():
"""
Folder for gage to run from
"""
require.directory(gage_folder, use_sudo=True)
def git_gage():
"""
Clone or update the gage-beaglebone repo
"""
sudo('systemctl stop gage-logger.service')
require.git.working_copy(
'https://github.com/abkfenris/gage-beaglebone.git',
path=gage_folder+'/gage-beaglebone',
branch='master',
update=True,
use_sudo=True)
with cd(gage_folder+'/gage-beaglebone'):
# initialize and update the submodule
sudo('git submodule init')
sudo('git submodule update')
def python_requirements():
"""
Install required packages for python
"""
require.deb.packages(['python-smbus', 'python-numpy', 'minicom'])
require.python.requirements(
gage_folder+'/gage-beaglebone/gage-requirements.txt')
def powercape_requirements():
"""
Install requirements for powercape
"""
require.deb.packages(['gcc-avr', 'avr-libc', 'avrdude', 'unzip'])
def git_powercape():
"""
Clone or update the powercape git repo
"""
require.git.working_copy(
'https://github.com/AndiceLabs/PowerCape.git',
path=gage_folder+'/powercape',
branch='master',
update=True,
use_sudo=True
)
with cd(gage_folder+'/powercape/utils'):
sudo('make powercape')
def powercape_update_bootloader():
"""
Update the powercape bootloader
http://andicelabs.com/2014/05/updating-power-cape-firmware/
"""
with cd('/gage'):
sudo('wget http://andicelabs.com/wp-content/uploads/2014/08/powercape.zip')
sudo('unzip powercape.zip')
with cd(gage_folder+'/powercape/utils'):
sudo('./power -b')
with cd(gage_folder+'/powercape/avr/twiboot/linux'):
# sudo('make')
sudo('./twiboot -a 0x20 -w flash:/gage/powercape.hex')
with cd('/gage'):
sudo('rm powercape.hex')
sudo('rm powercape.zip')
def powercape_rtc_set():
"""
Set the time on the powercape rtc
"""
sudo('date')
sudo('ntpdate -b -s -u pool.ntp.org')
sudo('date')
with cd(gage_folder+'/powercape/utils'):
sudo('./powercape -w')
def powercape_rtc_use():
"""
Use powercape rtc for system time
"""
pass
def powercape_startup_set():
"""
Set powercape startup reasons
"""
sudo('i2cset -y 1 0x21 7 {time}'.format(time=time_till_startup))
sudo('i2cset -y 1 0x21 4 {reason}'.format(reason=startup_reasons))
def powercape_watchdog():
pass
def clean_shutdown():
"""
http://andicelabs.com/2014/07/automatic-root-filesystem-repair-boot/
"""
sed('/lib/init/vars.sh', 'FSCKFIX=no', 'FSCKFIX=yes', use_sudo=True)
def shutdown():
"""
Shut the beaglebone down
"""
sudo('shutdown -h now')
@runs_once
def _settings():
"""
Get settings
"""
settings = {}
settings['name'] = prompt('Gage name?')
settings['id_num'] = prompt('Gage id number?')
settings['secret_key'] = prompt('Secret gage password?')
settings['depth_ain'] = prompt('Depth AIN?')
settings['depth_gpio'] = prompt('Depth GPIO?')
settings['depth_uart'] = prompt('Depth UART?')
settings['serial_dev'] = prompt('Serial Device?')
settings['url'] = prompt('API post URL?')
return settings
def make_config():
"""
Make config file and place on gage
"""
settings = _settings()
fabtools.files.upload_template(
'templates/config.py',
'/gage/gage-beaglebone/config.py',
context=settings,
use_sudo=True,
use_jinja=True
)
def service_add():
"""
Add the systemd service
"""
with cd('/lib/systemd/system'):
require.file('gage-logger.service',
source='gage-logger.service',
use_sudo=True)
sudo('systemctl enable gage-logger.service')
def service_start():
"""
Start the service
"""
sudo('systemctl start gage-logger.service')
def gagerun():
"""
Add gagerun to uboot so that it will go do it's thing
"""
sudo('touch /boot/uboot/gagerun')
def cell_sprint_sierra_250u():
"""
Place configuration files for a Sprint Sierra 250 U modem
"""
with lcd('cell/sprint/sierra250u/config-files'):
with cd('/etc'):
require.file('open.resolv.conf',
source='open.resolv.conf',
use_sudo=True)
with cd('ppp'):
sudo('cp options options.origional')
require.file('options',
source='options',
use_sudo=True)
require.file('ip-up',
source='options',
use_sudo=True)
with cd('peers'):
require.file('gprs-connect-chat',
source='gprs-connect-chat',
use_sudo=True)
def bootstrap():
"""
Setup all the things to make gage-beaglebone work
"""
apt_upgrade()
clean_shutdown()
mk_gage_folder()
git_gage()
python_requirements()
git_powercape()
powercape_requirements()
powercape_startup_set()
service_add()
gagerun()