isaac_toolbelt 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isaac_toolbelt.rb +96 -27
- data/lib/isaac_toolbelt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c67637613745d7fd01f327f5fe5f802e3bc4226c
|
4
|
+
data.tar.gz: 0c498e908136f756af59d50da74caeefad4c4c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f962fddab766f16c3313a1a567b402c3b0cefd3d2fc6a0b0d74a71bdb36c471a3052579d4b348c54634e48d831057d96bada1d18adc2c6539cc62ea1c7b1c38
|
7
|
+
data.tar.gz: 02ce1492a9ade4a54271feae9ca6c5b65c6b9374f4fb3b8dcfa67e0df0089bc93c48f171f14ae94d3d163191223b1e841f557e0600cf1c9c2b57a7040cebb7d6
|
data/lib/isaac_toolbelt.rb
CHANGED
@@ -9,6 +9,7 @@ require 'curb'
|
|
9
9
|
require 'ruby-progressbar'
|
10
10
|
require 'archive'
|
11
11
|
require 'mkmf'
|
12
|
+
include SSHKit::DSL
|
12
13
|
|
13
14
|
REQUIREMENTS_TXT = <<"EOF"
|
14
15
|
cffi==1.4.2
|
@@ -81,6 +82,7 @@ module IsaacToolbelt
|
|
81
82
|
TEMP_ROOT = '/var/isaac/tmp'
|
82
83
|
ISAAC_CONF_PATH = '/etc/isaac.conf'
|
83
84
|
ISAAC_EDISON_IMAGE_URL='https://s3-ap-northeast-1.amazonaws.com/isaac-os-images/edison/toFlash.tar.bz2'
|
85
|
+
ISAAC_EDISON_TEMPLATE_URL='https://codeload.github.com/xshellinc/isaac_template_python/zip/master'
|
84
86
|
|
85
87
|
|
86
88
|
module Helper
|
@@ -166,6 +168,18 @@ module IsaacToolbelt
|
|
166
168
|
end
|
167
169
|
Process.waitall
|
168
170
|
end
|
171
|
+
|
172
|
+
def current_mode
|
173
|
+
msg = ""
|
174
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
175
|
+
msg = capture(:systemctl, "is-active isaacd", raise_on_non_zero_exit: false)
|
176
|
+
end
|
177
|
+
if msg == "active" || msg == "activating"
|
178
|
+
return :production
|
179
|
+
else
|
180
|
+
return :development
|
181
|
+
end
|
182
|
+
end
|
169
183
|
end
|
170
184
|
|
171
185
|
class Local < Thor
|
@@ -315,13 +329,24 @@ module IsaacToolbelt
|
|
315
329
|
uname = get_uname()
|
316
330
|
conf = get_conf()
|
317
331
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
332
|
+
puts "OS: #{uname}"
|
333
|
+
puts "Access Key: #{conf['access_key']}"
|
334
|
+
|
335
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
336
|
+
%w(usb0 wlan0).each do |interface|
|
337
|
+
ifconfig = capture(:ifconfig, "#{interface}")
|
338
|
+
lines = ifconfig.lines
|
339
|
+
puts "#{interface}"
|
340
|
+
lines[1..-1].each do |l|
|
341
|
+
puts " IPv4: #{l.split[1].split(":").last}" if l.include? "inet addr:"
|
342
|
+
if l.include? "inet6 addr:"
|
343
|
+
words = l.split
|
344
|
+
puts " IPv6: #{words[2]} #{words[3]}"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
puts " HW Addr: #{lines[0].split.last}" if lines[0].include? "HWaddr"
|
348
|
+
end
|
349
|
+
end
|
325
350
|
end
|
326
351
|
|
327
352
|
desc 'config:access_key ACCESS_KEY', 'Set ISAAC Access Token'
|
@@ -352,27 +377,16 @@ module IsaacToolbelt
|
|
352
377
|
end
|
353
378
|
|
354
379
|
desc 'mode', 'Set modes whether production mode or development mode.'
|
355
|
-
def mode(
|
380
|
+
def mode(m)
|
356
381
|
waitfor
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
execute :systemctl, *%w(enable isaac-local)
|
364
|
-
execute :systemctl, *%w(start isaac-local)
|
365
|
-
elsif state == "production" then
|
366
|
-
# stop isaac-local
|
367
|
-
execute :systemctl, *%w(stop isaac-local)
|
368
|
-
execute :systemctl, *%w(disable isaac-local)
|
369
|
-
# start isaacd
|
370
|
-
execute :systemctl, *%w(enable isaacd)
|
371
|
-
execute :systemctl, *%w(start isaacd)
|
372
|
-
else
|
373
|
-
puts DEVICE_MODE
|
374
|
-
end
|
382
|
+
if m == "development" || m == "dev" then
|
383
|
+
change_mode :development
|
384
|
+
elsif m == "production" then
|
385
|
+
change_mode :production
|
386
|
+
else
|
387
|
+
puts DEVICE_MODE
|
375
388
|
end
|
389
|
+
puts "Current mode is #{current_mode}."
|
376
390
|
end
|
377
391
|
|
378
392
|
desc 'reboot', 'Reboot ISAAC OS'
|
@@ -382,7 +396,6 @@ module IsaacToolbelt
|
|
382
396
|
end
|
383
397
|
map 'reboot' => '_reboot'
|
384
398
|
|
385
|
-
|
386
399
|
private
|
387
400
|
def prepare_os_image
|
388
401
|
easy = Curl::Easy.new
|
@@ -571,11 +584,67 @@ module IsaacToolbelt
|
|
571
584
|
end
|
572
585
|
return uname
|
573
586
|
end
|
587
|
+
|
588
|
+
def change_mode(m)
|
589
|
+
if m == :development
|
590
|
+
if current_mode == :production
|
591
|
+
print "The device is in production mode. Do you wish to change to development mode [yN]: "
|
592
|
+
confirm = STDIN.gets.chomp.downcase
|
593
|
+
if confirm == "yes" || confirm == "y"
|
594
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
595
|
+
# stop isaacd
|
596
|
+
execute :systemctl, *%w(stop isaacd)
|
597
|
+
execute :systemctl, *%w(disable isaacd)
|
598
|
+
# start isaac-local
|
599
|
+
execute :systemctl, *%w(enable isaac-local)
|
600
|
+
execute :systemctl, *%w(start isaac-local)
|
601
|
+
end
|
602
|
+
else
|
603
|
+
puts "Device mode was not changed."
|
604
|
+
end
|
605
|
+
end
|
606
|
+
elsif m == :production
|
607
|
+
on "#{SSH_USERNAME}@#{DEVICE_IP_ADDRESS}" do
|
608
|
+
# stop isaac-local
|
609
|
+
execute :systemctl, *%w(stop isaac-local)
|
610
|
+
execute :systemctl, *%w(disable isaac-local)
|
611
|
+
# start isaacd
|
612
|
+
execute :systemctl, *%w(enable isaacd)
|
613
|
+
execute :systemctl, *%w(start isaacd)
|
614
|
+
end
|
615
|
+
end
|
616
|
+
return current_mode
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
class App < Thor
|
621
|
+
desc 'new <name>', 'Create a new Isaac <name> app'
|
622
|
+
def new(app_name)
|
623
|
+
# Create app directory
|
624
|
+
if Dir.exist? app_name
|
625
|
+
puts "ERROR: #{app_name} directory already exists."
|
626
|
+
exit(-1)
|
627
|
+
end
|
628
|
+
FileUtils.mkdir app_name
|
629
|
+
# Get a template
|
630
|
+
url = ISAAC_EDISON_TEMPLATE_URL
|
631
|
+
template_d = File.join(ISAAC_DIR, 'templates/edison')
|
632
|
+
FileUtils.mkdir_p template_d unless Dir.exist? template_d
|
633
|
+
template_fname = url.split(/\?/).first.split(/\//).last
|
634
|
+
template_f = File.join(template_d, template_fname)
|
635
|
+
Curl::Easy.download(url, template_f)
|
636
|
+
# Extract template archive
|
637
|
+
extract_d = File.join(template_d, "isaac_template_python-master")
|
638
|
+
Archive.extract(template_f, template_d)
|
639
|
+
# Copy to app directory
|
640
|
+
FileUtils.cp_r extract_d + "/.", app_name
|
641
|
+
end
|
574
642
|
end
|
575
643
|
|
576
644
|
class CLI < Thor
|
577
645
|
register Local, 'local', 'local <COMMAND>', 'Run the app on local SBC'
|
578
646
|
register Device, 'device', 'device <COMMAND>', 'Configure SBC connected via USB'
|
647
|
+
register App, 'app', 'app <COMMAND>', 'Isaac app'
|
579
648
|
|
580
649
|
map %w(-v --version) => :version
|
581
650
|
desc "version", "Show Isaac's version information"
|
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.5
|
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-04-
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|