isaac_toolbelt 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +66 -1
- data/bin/isaac +120 -1
- data/lib/app.rb +41 -0
- data/lib/isaac_toolbelt.rb +128 -141
- data/lib/isaac_toolbelt/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73bf2d5f4c3c7ab0835722a3cd3af19bc137f7bb
|
4
|
+
data.tar.gz: fc0e46c3b3d77fc4c212d813cf5d3e6a56448bb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6692437735bc96db5e7202235bd52e0de65c79733b1c3ec944baadeaa0ba79c5d3d7f8142401735f40c7934e5e5c897da73ab2d1b80913b8502ea47810fe670e
|
7
|
+
data.tar.gz: b6086ab841c7bf7965dd53efd4c8bd84a1473d272bd0c792d997298a5c19c9600ff258fe05b640dbefe6fe27c51fdafb14143124218bcbdfb98e079c18b986e5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -11,10 +11,75 @@ It is inspired by [heroku toolbelt](https://toolbelt.heroku.com/).
|
|
11
11
|
$ gem install specific_install
|
12
12
|
$ gem specific_install git@github.com:xshellinc/isaac_toolbelt.git
|
13
13
|
|
14
|
+
### Ubuntu
|
15
|
+
|
16
|
+
If your release doesn't have a ruby2.2-dev package, we recommend using [rbenv](https://github.com/rbenv/rbenv) to set up your Ruby environment.
|
17
|
+
|
18
|
+
$ sudo apt-get install ruby2.2-dev
|
19
|
+
|
20
|
+
Install dependencies for the toolbelt.
|
21
|
+
|
22
|
+
$ sudo apt-get install dfu-util libcurl4-openssl-dev libarchive-dev
|
23
|
+
|
24
|
+
Install the toolbelt by either ways below.
|
25
|
+
|
26
|
+
1. Install from [rubygems.org](https://rubygems.org/gems/isaac_toolbelt)
|
27
|
+
|
28
|
+
$ sudo gem install isaac_toolbelt
|
29
|
+
|
30
|
+
2. Install from [GitHub](https://github.com/xshellinc/isaac_toolbelt)
|
31
|
+
|
32
|
+
$ git clone https://github.com/xshellinc/isaac_toolbelt.git
|
33
|
+
$ cd isaac_toolbelt
|
34
|
+
$ bundle install
|
35
|
+
$ gem install isaac_toolbelt
|
14
36
|
|
15
37
|
## Usage
|
16
38
|
|
17
|
-
|
39
|
+
### Quickstart Guide
|
40
|
+
|
41
|
+
1. Obtain a git repository url and an access key for a device
|
42
|
+
from [Isaac dashboard](https://dashboard.isaacapp.io/)
|
43
|
+
1. Create an app
|
44
|
+
2. Create a device for the app
|
45
|
+
2. Setup an app devloping environment
|
46
|
+
1. Create a new app with a template
|
47
|
+
|
48
|
+
```sh
|
49
|
+
$ isaac app new <app name> --language=python
|
50
|
+
```
|
51
|
+
|
52
|
+
2. Setup Git remote server
|
53
|
+
|
54
|
+
```sh
|
55
|
+
$ cd <app name>
|
56
|
+
$ git remote add origin <app git server url>
|
57
|
+
```
|
58
|
+
|
59
|
+
3. Add and commit all template files
|
60
|
+
|
61
|
+
```sh
|
62
|
+
$ git add .
|
63
|
+
$ git commit -m "add files from the template"
|
64
|
+
```
|
65
|
+
|
66
|
+
4. Push changes to the Git server
|
67
|
+
|
68
|
+
```sh
|
69
|
+
$ git push --set-upstream origin master
|
70
|
+
```
|
71
|
+
|
72
|
+
3. Prepare a device
|
73
|
+
1. Connect your device by a USB cable
|
74
|
+
2. Flash the device
|
75
|
+
|
76
|
+
```sh
|
77
|
+
$ isaac device init --ssid=<wifi ap name> --wpa=<wifi password> \
|
78
|
+
--access_key=<access key>
|
79
|
+
```
|
80
|
+
|
81
|
+
The device will start blinking because of the template code at this point.
|
82
|
+
Your device listens for changes in the git repository from now on.
|
18
83
|
|
19
84
|
### Show all commands
|
20
85
|
|
data/bin/isaac
CHANGED
@@ -2,5 +2,124 @@
|
|
2
2
|
|
3
3
|
require "isaac_toolbelt"
|
4
4
|
|
5
|
-
|
5
|
+
LOCK_FILE = File.open("/var/tmp/isaac.lock",
|
6
|
+
File::CREAT|File::TRUNC|File::WRONLY, 0644)
|
7
|
+
LOCK_FILE.write(Process.pid)
|
6
8
|
|
9
|
+
module CLI
|
10
|
+
class Local < Thor
|
11
|
+
# XXX: Take the run method away from Thor so that we can redefine it.
|
12
|
+
# from https://github.com/ddollar/foreman/blob/59d87c91a2004e05f6b12d4b150dcb4c911eb31c/lib/foreman/cli.rb#L28
|
13
|
+
class << self
|
14
|
+
def is_thor_reserved_word?(word, type)
|
15
|
+
return false if word == "run"
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'start', 'Run the project on the debug mode device that connected via RNDIS'
|
21
|
+
def start
|
22
|
+
IsaacToolbelt::Local.start
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'stop', 'Stop the sketch'
|
26
|
+
def stop
|
27
|
+
IsaacToolbelt::Local.stop
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'run', 'Run a command with .env on the debug mode device that connected via RNDIS'
|
31
|
+
def run(*args)
|
32
|
+
IsaacToolbelt::Local.run(args)
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'debug_node', 'Run node.js app on the device that connected via RNDIS'
|
36
|
+
def debug_node
|
37
|
+
IsaacToolbelt::Local.debug_node
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Device < Thor
|
42
|
+
desc 'init', 'Initialize SBC for use with isaac'
|
43
|
+
option :ssid, :aliases => '-s', :required => true, :type => :string, :desc => 'Specify WiFi SSID'
|
44
|
+
option :wpa, :aliases => '-w', :required => true, :type => :string, :desc => 'Specify WPA Key for the SSID'
|
45
|
+
option :access_key, :aliases => '-a', :required => false, :type => :string, :desc => 'Specify ISAAC access key for the device'
|
46
|
+
def init
|
47
|
+
IsaacToolbelt::Device.init(options[:ssid], options[:wpa], options[:access_key])
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'info', 'Show device status'
|
51
|
+
def info
|
52
|
+
IsaacToolbelt::Device.info
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'config:access_key ACCESS_KEY', 'Set ISAAC Access Token'
|
56
|
+
def config_access_key(access_key)
|
57
|
+
IsaacToolbelt::Device.config_access_key(access_key)
|
58
|
+
end
|
59
|
+
map 'config:access_key' => 'config_access_key'
|
60
|
+
|
61
|
+
desc 'config:wifi', 'Configure WiFi'
|
62
|
+
option :ssid, :aliases => '-s', :required => true, :type => :string, :desc => 'Specify WiFi SSID'
|
63
|
+
option :wpa, :aliases => '-w', :required => true, :type => :string, :desc => 'Specify WPA Key for the SSID'
|
64
|
+
def config_wifi
|
65
|
+
IsaacToolbelt::Device.config_wifi(options[:ssid], options[:wpa])
|
66
|
+
end
|
67
|
+
map 'config:wifi' => 'config_wifi'
|
68
|
+
|
69
|
+
desc 'console', 'Shell on the debug mode device that connected via RNDIS'
|
70
|
+
def console
|
71
|
+
IsaacToolbelt::Device.console
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'logs', 'show logs on the device that connected via RNDIS'
|
75
|
+
def logs
|
76
|
+
IsaacToolbelt::Device.logs
|
77
|
+
end
|
78
|
+
|
79
|
+
desc 'mode', 'Set modes whether production mode or development mode.'
|
80
|
+
def mode(m)
|
81
|
+
IsaacToolbelt::Device.mode(m)
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'reboot', 'Reboot ISAAC OS'
|
85
|
+
def _reboot
|
86
|
+
IsaacToolbelt::Device._reboot
|
87
|
+
end
|
88
|
+
map 'reboot' => '_reboot'
|
89
|
+
end
|
90
|
+
|
91
|
+
class App < Thor
|
92
|
+
desc 'new <name>', 'Create a new Isaac <name> app'
|
93
|
+
option :language, :required => false, :type => :string, :desc => 'app language [python javascript]'
|
94
|
+
def new(app_name)
|
95
|
+
IsaacToolbelt::App.new(app_name, options[:language])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Main < Thor
|
100
|
+
desc "local SUBCOMMAND ...", "Run the app on local SBC"
|
101
|
+
subcommand "local", Local
|
102
|
+
desc "device SUBCOMMAND ...", "Configure SBC connected via USB"
|
103
|
+
subcommand "device", Device
|
104
|
+
desc "app SUBCOMMAND ...", "Isaac app"
|
105
|
+
subcommand "app", App
|
106
|
+
|
107
|
+
map %w(-v --version) => :version
|
108
|
+
desc "version", "Show Isaac's version information"
|
109
|
+
def version
|
110
|
+
puts "Isaac toolbelt version #{IsaacToolbelt::VERSION}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# `isaac device mode` without args shows current mode
|
116
|
+
if ARGV.length == 2 && ARGV[0] == "device" && ARGV[1] == "mode"
|
117
|
+
puts IsaacToolbelt::Device.current_mode
|
118
|
+
else
|
119
|
+
CLI::Main.start(ARGV)
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
at_exit do
|
124
|
+
LOCK_FILE.close
|
125
|
+
end
|
data/lib/app.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'curb'
|
2
|
+
|
3
|
+
module IsaacToolbelt::App
|
4
|
+
def self.new(app_name, language)
|
5
|
+
# Create app directory
|
6
|
+
if Dir.exist? app_name
|
7
|
+
puts "ERROR: #{app_name} directory already exists."
|
8
|
+
exit(-1)
|
9
|
+
end
|
10
|
+
# Select a template source
|
11
|
+
url = nil
|
12
|
+
extract_dname = nil
|
13
|
+
language = language.downcase.to_sym unless language.nil?
|
14
|
+
language ||= :python
|
15
|
+
case language
|
16
|
+
when :python
|
17
|
+
url = IsaacToolbelt::ISAAC_EDISON_TEMPLATE_URL
|
18
|
+
extract_dname = "isaac_template_python-master"
|
19
|
+
when :javascript, :js
|
20
|
+
url = "https://codeload.github.com/xshellinc/isaac_template_nodejs/zip/master"
|
21
|
+
extract_dname = "isaac_template_nodejs-master"
|
22
|
+
else
|
23
|
+
puts "ERROR: Unsupported or invalid language was selected"
|
24
|
+
puts "Supported languages are python, javascript"
|
25
|
+
exit -1
|
26
|
+
end
|
27
|
+
unless url.nil?
|
28
|
+
# Get a template
|
29
|
+
template_d = File.join(IsaacToolbelt::ISAAC_DIR, 'templates/edison')
|
30
|
+
FileUtils.mkdir_p template_d unless Dir.exist? template_d
|
31
|
+
template_fname = url.split(/\?/).first.split(/\//).last
|
32
|
+
template_f = File.join(template_d, template_fname)
|
33
|
+
Curl::Easy.download(url, template_f)
|
34
|
+
# Extract template archive
|
35
|
+
extract_d = File.join(template_d, extract_dname)
|
36
|
+
Archive.extract(template_f, template_d)
|
37
|
+
# Copy to app directory
|
38
|
+
FileUtils.cp_r extract_d + "/.", app_name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/isaac_toolbelt.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "isaac_toolbelt/version"
|
2
|
+
require "app"
|
2
3
|
|
3
4
|
require 'digest/sha1'
|
4
5
|
require 'sshkit'
|
@@ -84,7 +85,6 @@ module IsaacToolbelt
|
|
84
85
|
ISAAC_EDISON_IMAGE_URL='https://s3-ap-northeast-1.amazonaws.com/isaac-os-images/edison/toFlash.tar.bz2'
|
85
86
|
ISAAC_EDISON_TEMPLATE_URL='https://codeload.github.com/xshellinc/isaac_template_python/zip/master'
|
86
87
|
|
87
|
-
|
88
88
|
module Helper
|
89
89
|
def check_file(filename)
|
90
90
|
unless File.exist?(File.join(Dir.pwd, filename))
|
@@ -135,7 +135,7 @@ module IsaacToolbelt
|
|
135
135
|
|
136
136
|
# wait until board is booted
|
137
137
|
def waitfor(message=nil)
|
138
|
-
until system(
|
138
|
+
until system("ping -W 10 -c 1 #{DEVICE_IP_ADDRESS} > /dev/null 2>&1") do
|
139
139
|
puts message || 'waiting board...'
|
140
140
|
sleep 1
|
141
141
|
end
|
@@ -182,62 +182,50 @@ module IsaacToolbelt
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
-
class Local
|
185
|
+
class Local
|
186
186
|
extend Helper
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
desc 'start', 'Run the project on the debug mode device that connected via RNDIS'
|
198
|
-
def start
|
199
|
-
temp_path = self.class.temp_path
|
200
|
-
self.class.transfer_files(temp_path)
|
201
|
-
SSHKit::Coordinator.new(self.class.host).each do
|
187
|
+
def self.start
|
188
|
+
unless Device.mode(:development) == :development
|
189
|
+
puts "Please switch mode to development to develop locally"
|
190
|
+
return
|
191
|
+
end
|
192
|
+
temp_d = temp_path
|
193
|
+
transfer_files(temp_d)
|
194
|
+
SSHKit::Coordinator.new(self.host).each do
|
202
195
|
# start isaac-local
|
203
196
|
execute :systemctl, *%w(stop isaac-local)
|
204
197
|
#execute :systemctl, *%w(start isaac-local)
|
205
|
-
execute :ln, '-nfs',
|
198
|
+
execute :ln, '-nfs', temp_d, '/var/isaac/development'
|
206
199
|
end
|
207
200
|
#self.class.ssh_run_command('journalctl -n 5 -f -u isaac-local')
|
208
201
|
#self.class.ssh_run_command('tail -f /var/log/isaac-local.log')
|
209
|
-
#self.class.ssh_run_command("cd #{
|
210
|
-
|
202
|
+
#self.class.ssh_run_command("cd #{temp_d}; " + 'honcho start')
|
203
|
+
ssh_run_command("cd /var/isaac/development; " + 'shoreman')
|
211
204
|
end
|
212
205
|
|
213
|
-
|
214
|
-
|
206
|
+
def self.stop
|
207
|
+
hello
|
215
208
|
end
|
216
209
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
self.class.ssh_run_command("cd #{temp_path}; " + 'honcho run ' + args.shelljoin)
|
210
|
+
def self.run(args)
|
211
|
+
temp_d = temp_path
|
212
|
+
transfer_files(temp_d)
|
213
|
+
ssh_run_command("cd #{temp_d}; " + 'honcho run ' + args.shelljoin)
|
222
214
|
end
|
223
215
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
result = self.class.transfer_files(temp_path)
|
216
|
+
def self.debug_node
|
217
|
+
temp_d = make_temp_dir(TEMP_ROOT)
|
218
|
+
result = transfer_files(temp_d)
|
228
219
|
if result
|
229
|
-
|
220
|
+
ssh_run_command('cd %s; npm install; node app.js' % [temp_d])
|
230
221
|
else
|
231
222
|
puts 'Transfer failed'
|
232
223
|
end
|
233
224
|
end
|
234
|
-
|
235
|
-
#map 'shell' => 'console'
|
236
|
-
#map 'shell' => 'shell_'
|
237
225
|
end
|
238
226
|
|
239
|
-
class Device
|
240
|
-
|
227
|
+
class Device
|
228
|
+
extend Helper
|
241
229
|
|
242
230
|
def self.curl(url, save_dir)
|
243
231
|
filename = url.split('/').last
|
@@ -264,11 +252,11 @@ module IsaacToolbelt
|
|
264
252
|
return filename
|
265
253
|
end
|
266
254
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
255
|
+
def self.init(ssid, wpa, access_key)
|
256
|
+
unless LOCK_FILE.flock(File::LOCK_EX|File::LOCK_NB)
|
257
|
+
puts "Only one 'isaac device init' can run at a time."
|
258
|
+
exit
|
259
|
+
end
|
272
260
|
unless !!find_executable('dfu-util')
|
273
261
|
STDERR.puts 'dfu-util is not installed!'
|
274
262
|
STDERR.puts 'try: brew install dfu-util'
|
@@ -285,18 +273,14 @@ module IsaacToolbelt
|
|
285
273
|
waitfor
|
286
274
|
|
287
275
|
# configure WiFi
|
288
|
-
configure_wifi(
|
276
|
+
configure_wifi(ssid, wpa)
|
289
277
|
waitfor_network
|
290
278
|
|
291
|
-
#
|
292
|
-
|
293
|
-
execute :
|
294
|
-
|
295
|
-
execute :
|
296
|
-
requirements = StringIO.new(REQUIREMENTS_TXT)
|
297
|
-
dst = '/tmp/requirements.txt'
|
298
|
-
upload! requirements, dst
|
299
|
-
execute :pip, *%w(install -r), dst
|
279
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
280
|
+
puts "Updating package database..."
|
281
|
+
execute :opkg, %w(update)
|
282
|
+
puts "Installing NodeJS..."
|
283
|
+
execute :opkg, %w(install nodejs nodejs-npm)
|
300
284
|
end
|
301
285
|
|
302
286
|
## install opkg dependencies for isaacd : hacky
|
@@ -309,11 +293,9 @@ module IsaacToolbelt
|
|
309
293
|
#end
|
310
294
|
|
311
295
|
# init isaacd
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
execute :systemctl, *%w(enable isaacd)
|
316
|
-
end
|
296
|
+
set_conf({'access_key' => access_key})
|
297
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
298
|
+
execute :systemctl, *%w(enable isaacd)
|
317
299
|
end
|
318
300
|
|
319
301
|
# wait until rebooted
|
@@ -322,8 +304,7 @@ module IsaacToolbelt
|
|
322
304
|
puts 'Your device is ready to develop!'
|
323
305
|
end
|
324
306
|
|
325
|
-
|
326
|
-
def info
|
307
|
+
def self.info
|
327
308
|
waitfor('Please connect the board and wait for a while...')
|
328
309
|
|
329
310
|
uname = get_uname()
|
@@ -346,58 +327,50 @@ module IsaacToolbelt
|
|
346
327
|
end
|
347
328
|
puts " HW Addr: #{lines[0].split.last}" if lines[0].include? "HWaddr"
|
348
329
|
end
|
330
|
+
ssid = capture(:iwgetid, "-r")
|
331
|
+
puts "WiFi SSID: #{ssid}"
|
349
332
|
end
|
350
333
|
end
|
351
334
|
|
352
|
-
|
353
|
-
def config_access_key(access_key)
|
335
|
+
def self.config_access_key(access_key)
|
354
336
|
waitfor
|
355
337
|
configure_access_key(access_key)
|
356
338
|
end
|
357
|
-
map 'config:access_key' => 'config_access_key'
|
358
339
|
|
359
|
-
|
360
|
-
|
361
|
-
option :wpa, :aliases => '-w', :required => true, :type => :string, :desc => 'Specify WPA Key for the SSID'
|
362
|
-
def config_wifi
|
363
|
-
configure_wifi(options[:ssid], options[:wpa])
|
340
|
+
def self.config_wifi(ssid, wpa)
|
341
|
+
configure_wifi(ssid, wpa)
|
364
342
|
end
|
365
|
-
map 'config:wifi' => 'config_wifi'
|
366
343
|
|
367
|
-
|
368
|
-
def console
|
344
|
+
def self.console
|
369
345
|
waitfor('Please connect the board and wait for a while...')
|
370
346
|
ssh_run_command('')
|
371
347
|
end
|
372
348
|
|
373
|
-
|
374
|
-
def logs
|
349
|
+
def self.logs
|
375
350
|
waitfor('Please connect the board and wait for a while...')
|
376
351
|
ssh_run_command('journalctl -f')
|
377
352
|
end
|
378
353
|
|
379
|
-
|
380
|
-
def mode(m)
|
354
|
+
def self.mode(m)
|
381
355
|
waitfor
|
382
|
-
|
383
|
-
|
384
|
-
elsif m == "production" then
|
385
|
-
change_mode :production
|
386
|
-
else
|
356
|
+
m = m.to_sym if m.is_a? String
|
357
|
+
if m != :development && m != :dev && m != :production
|
387
358
|
puts DEVICE_MODE
|
359
|
+
elsif m != current_mode
|
360
|
+
change_mode :development if m == :development || m == :dev
|
361
|
+
change_mode :production if m == :production
|
388
362
|
end
|
389
363
|
puts "Current mode is #{current_mode}."
|
364
|
+
return current_mode
|
390
365
|
end
|
391
366
|
|
392
|
-
|
393
|
-
def _reboot
|
367
|
+
def self._reboot
|
394
368
|
waitfor
|
395
369
|
reboot
|
396
370
|
end
|
397
|
-
map 'reboot' => '_reboot'
|
398
371
|
|
399
372
|
private
|
400
|
-
def prepare_os_image
|
373
|
+
def self.prepare_os_image
|
401
374
|
easy = Curl::Easy.new
|
402
375
|
easy.follow_location = true
|
403
376
|
easy.url = ISAAC_EDISON_IMAGE_URL
|
@@ -432,7 +405,7 @@ module IsaacToolbelt
|
|
432
405
|
return extract_path
|
433
406
|
end
|
434
407
|
|
435
|
-
def flash_os_image(extract_path)
|
408
|
+
def self.flash_os_image(extract_path)
|
436
409
|
base_dir = extract_path
|
437
410
|
usb_vid = '8087'
|
438
411
|
usb_pid = '0a99'
|
@@ -471,13 +444,13 @@ module IsaacToolbelt
|
|
471
444
|
dfu_download(usb_vid, usb_pid, "rootfs", rootfs_file_path, true)
|
472
445
|
end
|
473
446
|
|
474
|
-
def dfu_ifwi_download(usb_vid, usb_pid, alt_name, file_path)
|
447
|
+
def self.dfu_ifwi_download(usb_vid, usb_pid, alt_name, file_path)
|
475
448
|
if dfu_alt_name_exists?(usb_vid, usb_pid, alt_name)
|
476
449
|
dfu_download(usb_vid, usb_pid, alt_name, file_path)
|
477
450
|
end
|
478
451
|
end
|
479
452
|
|
480
|
-
def dfu_download(usb_vid, usb_pid, alt_name, file_path, do_reboot=false)
|
453
|
+
def self.dfu_download(usb_vid, usb_pid, alt_name, file_path, do_reboot=false)
|
481
454
|
retry_count = 0
|
482
455
|
loop do
|
483
456
|
params = %W(dfu-util -v -d #{usb_vid}:#{usb_pid} --alt #{alt_name} -D #{file_path})
|
@@ -500,13 +473,13 @@ module IsaacToolbelt
|
|
500
473
|
end
|
501
474
|
end
|
502
475
|
|
503
|
-
def dfu_alt_name_exists?(usb_vid, usb_pid, alt_name)
|
476
|
+
def self.dfu_alt_name_exists?(usb_vid, usb_pid, alt_name)
|
504
477
|
dfu_list(usb_vid, usb_pid).select {|e|
|
505
478
|
e[:name] == alt_name
|
506
479
|
}.count > 0
|
507
480
|
end
|
508
481
|
|
509
|
-
def dfu_wait(message=nil)
|
482
|
+
def self.dfu_wait(message=nil)
|
510
483
|
usb_vid = '8087'
|
511
484
|
usb_pid = '0a99'
|
512
485
|
until dfu_device_counts(usb_vid, usb_pid) > 0
|
@@ -515,7 +488,7 @@ module IsaacToolbelt
|
|
515
488
|
end
|
516
489
|
end
|
517
490
|
|
518
|
-
def dfu_device_counts(usb_vid, usb_pid)
|
491
|
+
def self.dfu_device_counts(usb_vid, usb_pid)
|
519
492
|
`dfu-util -l -d #{usb_vid}:#{usb_pid}`.split("\n").select{|l0|
|
520
493
|
l0 =~ /Found/
|
521
494
|
}.select{|l1|
|
@@ -523,7 +496,7 @@ module IsaacToolbelt
|
|
523
496
|
}.count
|
524
497
|
end
|
525
498
|
|
526
|
-
def dfu_list(usb_vid, usb_pid)
|
499
|
+
def self.dfu_list(usb_vid, usb_pid)
|
527
500
|
`dfu-util -l -d #{usb_vid}:#{usb_pid}`.split("\n").select{|l0|
|
528
501
|
l0 =~ /Found/
|
529
502
|
}.map {|str|
|
@@ -546,7 +519,7 @@ module IsaacToolbelt
|
|
546
519
|
}
|
547
520
|
end
|
548
521
|
|
549
|
-
def configure_wifi(ssid, wpa_key)
|
522
|
+
def self.configure_wifi(ssid, wpa_key)
|
550
523
|
SSHKit::Coordinator.new(host).each do
|
551
524
|
execute :wpa_passphrase, ssid, wpa_key, '>>', '/etc/wpa_supplicant/wpa_supplicant.conf'
|
552
525
|
execute :systemctl, *%w(restart wpa_supplicant.service)
|
@@ -554,30 +527,28 @@ module IsaacToolbelt
|
|
554
527
|
end
|
555
528
|
end
|
556
529
|
|
557
|
-
def configure_access_key(access_key)
|
530
|
+
def self.configure_access_key(access_key)
|
558
531
|
conf = get_conf
|
559
532
|
conf["access_key"] = access_key
|
560
533
|
set_conf(conf)
|
561
534
|
end
|
562
535
|
|
563
|
-
def get_conf
|
536
|
+
def self.get_conf
|
564
537
|
conf = nil
|
565
|
-
|
566
|
-
conf = YAML.load(capture(:cat, ISAAC_CONF_PATH))
|
538
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
539
|
+
conf = YAML.load(capture(:cat, ISAAC_CONF_PATH)) if test("[ -f #{ISAAC_CONF_PATH} ]")
|
567
540
|
end
|
568
|
-
return conf
|
541
|
+
return {} if conf.nil?
|
542
|
+
conf
|
569
543
|
end
|
570
544
|
|
571
|
-
def set_conf(conf)
|
572
|
-
|
573
|
-
|
574
|
-
SSHKit::Coordinator.new(host).each do
|
575
|
-
upload! upload_io, ISAAC_CONF_PATH
|
545
|
+
def self.set_conf(conf)
|
546
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
547
|
+
upload! StringIO.new(YAML.dump(conf)), ISAAC_CONF_PATH
|
576
548
|
end
|
577
|
-
return nil
|
578
549
|
end
|
579
550
|
|
580
|
-
def get_uname
|
551
|
+
def self.get_uname
|
581
552
|
uname = nil
|
582
553
|
SSHKit::Coordinator.new(host).each do
|
583
554
|
uname = capture(:uname, '-a')
|
@@ -585,7 +556,7 @@ module IsaacToolbelt
|
|
585
556
|
return uname
|
586
557
|
end
|
587
558
|
|
588
|
-
def change_mode(m)
|
559
|
+
def self.change_mode(m)
|
589
560
|
if m == :development
|
590
561
|
if current_mode == :production
|
591
562
|
print "The device is in production mode. Do you wish to change to development mode [yN]: "
|
@@ -616,42 +587,58 @@ module IsaacToolbelt
|
|
616
587
|
return current_mode
|
617
588
|
end
|
618
589
|
end
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
590
|
+
#<<<<<<< HEAD
|
591
|
+
#
|
592
|
+
# class App < Thor
|
593
|
+
# desc 'new <name>', 'Create a new Isaac <name> app'
|
594
|
+
# option :language, :required => false, :type => :string, :desc => 'app language [python javascript]'
|
595
|
+
# def new(app_name)
|
596
|
+
# # Create app directory
|
597
|
+
# if Dir.exist? app_name
|
598
|
+
# puts "ERROR: #{app_name} directory already exists."
|
599
|
+
# exit(-1)
|
600
|
+
# end
|
601
|
+
# FileUtils.mkdir app_name
|
602
|
+
# # Select a template source
|
603
|
+
# url = nil
|
604
|
+
# extract_dname = nil
|
605
|
+
# case options[:language].to_sym
|
606
|
+
# when :python
|
607
|
+
# url = ISAAC_EDISON_TEMPLATE_URL
|
608
|
+
# extract_dname = "isaac_template_python-master"
|
609
|
+
# when :javascript, :js
|
610
|
+
# url = "https://codeload.github.com/xshellinc/isaac_template_nodejs/zip/master"
|
611
|
+
# extract_dname = "isaac_template_nodejs-master"
|
612
|
+
# end
|
613
|
+
# unless url.nil?
|
614
|
+
# # Get a template
|
615
|
+
# template_d = File.join(ISAAC_DIR, 'templates/edison')
|
616
|
+
# FileUtils.mkdir_p template_d unless Dir.exist? template_d
|
617
|
+
# template_fname = url.split(/\?/).first.split(/\//).last
|
618
|
+
# template_f = File.join(template_d, template_fname)
|
619
|
+
# Curl::Easy.download(url, template_f)
|
620
|
+
# # Extract template archive
|
621
|
+
# extract_d = File.join(template_d, extract_dname)
|
622
|
+
# Archive.extract(template_f, template_d)
|
623
|
+
# # Copy to app directory
|
624
|
+
# FileUtils.cp_r extract_d + "/.", app_name
|
625
|
+
# end
|
626
|
+
# end
|
627
|
+
# end
|
628
|
+
#
|
629
|
+
# class CLI < Thor
|
630
|
+
# register Local, 'local', 'local <COMMAND>', 'Run the app on local SBC'
|
631
|
+
# register Device, 'device', 'device <COMMAND>', 'Configure SBC connected via USB'
|
632
|
+
# register App, 'app', 'app <COMMAND>', 'Isaac app'
|
633
|
+
#
|
634
|
+
# map %w(-v --version) => :version
|
635
|
+
# desc "version", "Show Isaac's version information"
|
636
|
+
# def version
|
637
|
+
# puts "Isaac toolbelt version #{VERSION}"
|
638
|
+
# end
|
639
|
+
# end
|
640
|
+
#=======
|
641
|
+
#>>>>>>> master
|
655
642
|
end
|
656
643
|
|
657
644
|
Signal.trap(:INT) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isaac_toolbelt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xshell inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- bin/isaac
|
154
154
|
- bin/setup
|
155
155
|
- isaac_toolbelt.gemspec
|
156
|
+
- lib/app.rb
|
156
157
|
- lib/isaac_toolbelt.rb
|
157
158
|
- lib/isaac_toolbelt/version.rb
|
158
159
|
homepage: https://isaacapp.io/
|