modou 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -1
- data/Guardfile +17 -0
- data/bin/modou +129 -3
- data/lib/modou/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43dd15681602e57505a9fb26c41a55f306f34a74
|
4
|
+
data.tar.gz: 92b3f4df2630f03bc3d496dee71519017996b4a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e8f72c23fe9659607a00f60d31137cd6bbfd4736bf5533e65f8a95de8b5d4c7079999e34443693cc21bf42ae0fa393522ca10a880b3eb355ba6964e07162ec2
|
7
|
+
data.tar.gz: 5cdd9f7204b361e1d2ae92aad118922f56cc3f563535f655a812d7d03b809e2ad4913bf57d9158f26d7cec9c748e1aab0c101a9972f06021fb12ba1867dcb66c
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
5
|
+
# rspec may be run, below are examples of the most common uses.
|
6
|
+
# * bundler: 'bundle exec rspec'
|
7
|
+
# * bundler binstubs: 'bin/rspec'
|
8
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
9
|
+
# installed the spring binstubs per the docs)
|
10
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
11
|
+
# * 'just' rspec: 'rspec'
|
12
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
end
|
17
|
+
|
data/bin/modou
CHANGED
@@ -36,6 +36,8 @@ def save_config(config)
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def host
|
39
|
+
return ENV['MODOU_HOST'] if ENV['MODOU_HOST']
|
40
|
+
|
39
41
|
load_config[get_ssid]['host'] rescue '192.168.18.1'
|
40
42
|
end
|
41
43
|
|
@@ -88,9 +90,9 @@ def sign_in
|
|
88
90
|
require "json"
|
89
91
|
result = post('/api/auth/login', { body: JSON({ "password" => password }) })
|
90
92
|
|
91
|
-
cookie = result.headers['Set-Cookie']
|
93
|
+
$cookie = result.headers['Set-Cookie']
|
92
94
|
|
93
|
-
$auth = { headers: { 'Cookie' => cookie }, timeout: 999 }
|
95
|
+
$auth = { headers: { 'Cookie' => $cookie }, timeout: 999 }
|
94
96
|
end
|
95
97
|
|
96
98
|
def signin_required!
|
@@ -179,6 +181,20 @@ def print_help
|
|
179
181
|
puts 'modou devices whitelisted'
|
180
182
|
puts 'modou devices blacklisted'
|
181
183
|
puts 'modou devices graylisted'
|
184
|
+
|
185
|
+
puts
|
186
|
+
puts "========== applications =========="
|
187
|
+
puts "modou apps installed"
|
188
|
+
# puts "modou apps info APP_ID"
|
189
|
+
# puts "modou apps install APP_ID"
|
190
|
+
# puts "modou apps install_custom"
|
191
|
+
|
192
|
+
puts
|
193
|
+
puts "========== app store =========="
|
194
|
+
puts "modou store list_apps"
|
195
|
+
puts "modou store info APP_NAME"
|
196
|
+
puts "modou store download APP_NAME"
|
197
|
+
puts "modou store install APP_NAME"
|
182
198
|
end
|
183
199
|
|
184
200
|
def print_version_info
|
@@ -428,6 +444,112 @@ def devices_control(command)
|
|
428
444
|
end
|
429
445
|
end
|
430
446
|
|
447
|
+
def apps_control(command)
|
448
|
+
signin_required!
|
449
|
+
|
450
|
+
case command
|
451
|
+
when 'installed'
|
452
|
+
response = get('/api/plugin/installed_plugins')
|
453
|
+
|
454
|
+
if response['plugins'].empty?
|
455
|
+
puts 'no apps installed.'
|
456
|
+
else
|
457
|
+
response['plugins'].each do |app|
|
458
|
+
table = table_from_response(app)
|
459
|
+
puts table
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
###############################
|
466
|
+
# app store
|
467
|
+
###############################
|
468
|
+
|
469
|
+
def app_get(path)
|
470
|
+
store_endpoint = 'http://appstore.ly.md'
|
471
|
+
require "httparty"
|
472
|
+
|
473
|
+
@store_response = HTTParty.get(store_endpoint + path) unless @store_response
|
474
|
+
|
475
|
+
@store_response
|
476
|
+
end
|
477
|
+
|
478
|
+
def app_name
|
479
|
+
ARGV[2]
|
480
|
+
end
|
481
|
+
|
482
|
+
def app_info
|
483
|
+
app_get('/list').select { |app| app['name'] == app_name }.first if app_name
|
484
|
+
end
|
485
|
+
|
486
|
+
def app_filename
|
487
|
+
"#{app_name}-#{app_info['version']}.mpk" if app_info
|
488
|
+
end
|
489
|
+
|
490
|
+
def app_valid_file?(filename, size, md5_sum)
|
491
|
+
full_path = File.expand_path("../../tmp/#{filename}", __FILE__)
|
492
|
+
|
493
|
+
if File.size(full_path) != size.to_i
|
494
|
+
puts "file size mismatch"
|
495
|
+
false
|
496
|
+
elsif Digest::MD5.file(full_path).hexdigest != md5_sum
|
497
|
+
puts "incorrect md5 check sum"
|
498
|
+
false
|
499
|
+
else
|
500
|
+
true
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
def app_download_file!
|
505
|
+
`wget #{app_info['url']} -O tmp/#{app_filename}`
|
506
|
+
end
|
507
|
+
|
508
|
+
def store_control(command)
|
509
|
+
case command
|
510
|
+
when 'list_apps'
|
511
|
+
Hash.new.tap do |data|
|
512
|
+
app_get('/list').each { |app| data[app['name']] = app['description'] }
|
513
|
+
|
514
|
+
table = table_from_response(data)
|
515
|
+
|
516
|
+
puts table
|
517
|
+
end
|
518
|
+
when 'info'
|
519
|
+
if app_info
|
520
|
+
table = table_from_response(app_info)
|
521
|
+
|
522
|
+
puts table
|
523
|
+
else
|
524
|
+
puts "there is no app named '#{app_name}'"
|
525
|
+
end
|
526
|
+
when 'download'
|
527
|
+
if app_info
|
528
|
+
app_download_file!
|
529
|
+
else
|
530
|
+
puts "there is no app named '#{app_name}'"
|
531
|
+
end
|
532
|
+
when 'install'
|
533
|
+
signin_required!
|
534
|
+
|
535
|
+
if app_info
|
536
|
+
if app_valid_file?(app_filename, app_info['size'], app_info['md5_sum'])
|
537
|
+
puts "file already downloaded..."
|
538
|
+
else
|
539
|
+
app_download_file!
|
540
|
+
end
|
541
|
+
|
542
|
+
cli_command = %{curl -b "#{$cookie}" -F name=#{app_info['name']} -F size=#{app_info['size']} -F file=@./tmp/#{app_filename} http://#{host}/api/plugin/install_custom}
|
543
|
+
|
544
|
+
`#{cli_command}`
|
545
|
+
else
|
546
|
+
puts "there is no app named '#{app_name}'"
|
547
|
+
end
|
548
|
+
else
|
549
|
+
puts "unknown command"
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
431
553
|
###############################
|
432
554
|
# firmware upgrade
|
433
555
|
###############################
|
@@ -555,7 +677,7 @@ end
|
|
555
677
|
if ARGV.count == 0
|
556
678
|
print_help
|
557
679
|
else
|
558
|
-
if
|
680
|
+
if host.nil?
|
559
681
|
prompt_for_config
|
560
682
|
end
|
561
683
|
|
@@ -602,6 +724,10 @@ else
|
|
602
724
|
security_control(ARGV[1])
|
603
725
|
when 'firmware'
|
604
726
|
firmware_control(ARGV[1])
|
727
|
+
when 'apps'
|
728
|
+
apps_control(ARGV[1])
|
729
|
+
when 'store'
|
730
|
+
store_control(ARGV[1])
|
605
731
|
else
|
606
732
|
puts "unrecognized command"
|
607
733
|
puts
|
data/lib/modou/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modou
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Forrest Ye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -132,6 +132,7 @@ extra_rdoc_files: []
|
|
132
132
|
files:
|
133
133
|
- .gitignore
|
134
134
|
- Gemfile
|
135
|
+
- Guardfile
|
135
136
|
- LICENSE.txt
|
136
137
|
- README.md
|
137
138
|
- Rakefile
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- spec/fixtures/wan/is_internet_available.json
|
159
160
|
- spec/fixtures/wifi/get_config.json
|
160
161
|
- spec/spec_helper.rb
|
162
|
+
- tmp/.gitkeep
|
161
163
|
homepage: ''
|
162
164
|
licenses:
|
163
165
|
- MIT
|