apiotics 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiotics/hardware.rb +189 -4
- data/lib/apiotics/portal.rb +16 -0
- data/lib/apiotics/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: 1e25c98184861bff100688037a23340b6be5385e
|
4
|
+
data.tar.gz: f97ad7382054e1e67090a64f83aff5f12b7ac340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 568dfad8b2116d196a085861cd3dfea958c57945482c6bb84b8f68024e3bc692df39d71fc7ba45166bd8aeebe2156fc17ce104ac48e3c10d0fb8e3adbc8f8a65
|
7
|
+
data.tar.gz: bce6b5fd058002e67bda0273c035b0794af6e712c9ddbb7a7a3d90418fc3627969045ab51456cf9e195be7a7f0b02c460f6594c930d0f78fae8c215cd8b25768
|
data/lib/apiotics/hardware.rb
CHANGED
@@ -294,6 +294,174 @@ module Apiotics
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
+
def self.check_sd_card_scripts
|
298
|
+
status = nil
|
299
|
+
download_directory = Rails.root.join('lib', 'sd_card')
|
300
|
+
Dir.mkdir download_directory unless Dir.exist?(download_directory)
|
301
|
+
download_directory = Rails.root.join('lib', 'sd_card', 'downloads')
|
302
|
+
Dir.mkdir download_directory unless Dir.exist?(download_directory)
|
303
|
+
Dir.chdir download_directory
|
304
|
+
system = nil
|
305
|
+
if Hardware.mac == true
|
306
|
+
system = "mac"
|
307
|
+
elsif Hardware.linux == true
|
308
|
+
system = "linux"
|
309
|
+
end
|
310
|
+
downloaded = false
|
311
|
+
unless system == nil
|
312
|
+
if system == "mac"
|
313
|
+
if File.exist?("#{download_directory}/brand_image.mac.sh")
|
314
|
+
downloaded = true
|
315
|
+
end
|
316
|
+
elsif system == "linux"
|
317
|
+
if File.exist?("#{download_directory}/brand_image.sh")
|
318
|
+
downloaded = true
|
319
|
+
end
|
320
|
+
end
|
321
|
+
if downloaded == false
|
322
|
+
scripts = Apiotics::Portal.sd_scripts(system)
|
323
|
+
File.write("#{download_directory}/sd_scripts.tgz")
|
324
|
+
`tar xvzf #{download_directory}/sd_scripts.tgz -C #{download_directory}`
|
325
|
+
`rm #{download_directory}/sd_scripts.tgz`
|
326
|
+
end
|
327
|
+
if system == "mac"
|
328
|
+
if File.exist?("#{download_directory}/brand_image.mac.sh")
|
329
|
+
status = download_directory
|
330
|
+
end
|
331
|
+
elsif system == "linux"
|
332
|
+
if File.exist?("#{download_directory}/brand_image.sh")
|
333
|
+
status = download_directory
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
return status
|
338
|
+
end
|
339
|
+
|
340
|
+
def self.get_sd_image(download_directory, worker_name)
|
341
|
+
Dir.chdir download_directory
|
342
|
+
image_path = "#{download_directory}/#{worker_name}.img.gz"
|
343
|
+
unless File.exist?(image_path)
|
344
|
+
Apiotics::Portal.get_sd_image(download_directory, worker_name)
|
345
|
+
#zip_path = "#{download_directory}/#{worker_name}.img.gz"
|
346
|
+
#`gunzip -c #{zip_path} > #{image_path}`
|
347
|
+
#`rm #{zip_path}`
|
348
|
+
end
|
349
|
+
return image_path
|
350
|
+
end
|
351
|
+
|
352
|
+
def self.sd_config_file(worker_name, name, download_directory)
|
353
|
+
worker_directory = download_directory + "/#{worker_name.downcase}"
|
354
|
+
Dir.mkdir worker_directory unless Dir.exist?(worker_directory)
|
355
|
+
config_file_path = "#{worker_directory}/#{worker_name.downcase}.json"
|
356
|
+
if File.exist?(config_file_path)
|
357
|
+
config = File.read(config_file_path)
|
358
|
+
config = JSON.parse(config)
|
359
|
+
else
|
360
|
+
config = {}
|
361
|
+
end
|
362
|
+
config["port"] = "8883"
|
363
|
+
config["download"] = true
|
364
|
+
config["public_key"] = Apiotics.configuration.public_key
|
365
|
+
config["private_key"] = Apiotics.configuration.private_key
|
366
|
+
if name == nil || name == ""
|
367
|
+
config["name"] = ""
|
368
|
+
else
|
369
|
+
config["name"] = name.to_s
|
370
|
+
end
|
371
|
+
config["portal"] = Apiotics.configuration.portal
|
372
|
+
config["message_validation"] = false
|
373
|
+
config["local_server"] = "localhost"
|
374
|
+
config["local_port"] = "8001"
|
375
|
+
config["containers"] = false
|
376
|
+
config["driver_logging"] = true
|
377
|
+
File.write(config_file_path, config.to_json)
|
378
|
+
config_file_path
|
379
|
+
end
|
380
|
+
|
381
|
+
def self.brand_sd_image(download_directory, image_path, wifi_settings, config_file_path)
|
382
|
+
status = false
|
383
|
+
branding_script_path == nil
|
384
|
+
if Hardware.mac == true
|
385
|
+
branding_script_path = "#{download_directory}/brand_image.mac.sh"
|
386
|
+
elsif Hardware.linux == true
|
387
|
+
branding_script_path = "#{download_directory}/brand_image.sh"
|
388
|
+
end
|
389
|
+
if branding_script_path != nil
|
390
|
+
`#{branding_script_path} #{image_path} #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{config_file_path} dhcp`
|
391
|
+
status = true
|
392
|
+
else
|
393
|
+
puts "Unrecognized system architecture, exiting."
|
394
|
+
end
|
395
|
+
status
|
396
|
+
end
|
397
|
+
|
398
|
+
def self.find_smallest_disk
|
399
|
+
small_disk_size = 99999999999999999999
|
400
|
+
small_disk = "no_disk"
|
401
|
+
disks = {}
|
402
|
+
output = `df -k`
|
403
|
+
lines = output.split("\n")
|
404
|
+
i = 0
|
405
|
+
lines.each do |line|
|
406
|
+
lines[i] = line.split(" ")
|
407
|
+
i += 1
|
408
|
+
end
|
409
|
+
gigabyte_scaling = 1024 * 1024
|
410
|
+
lines.each do |line|
|
411
|
+
length = line.count
|
412
|
+
unless line[length - 1] == "/"
|
413
|
+
disks[line[0]] = line[1].to_i / gigabyte_scaling
|
414
|
+
end
|
415
|
+
end
|
416
|
+
disks.each do |disk, size|
|
417
|
+
if size < small_disk_size && size > 4 && disk[0..3] == "/dev"
|
418
|
+
small_disk_size = size
|
419
|
+
small_disk = disk
|
420
|
+
end
|
421
|
+
end
|
422
|
+
return small_disk
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
def self.burn_sd_image(download_directory, image_path, disk)
|
427
|
+
puts "Burning #{image_path} to #{disk}..."
|
428
|
+
if Hardware.mac == true
|
429
|
+
execute_path = download_directory + "/burn_image_to_disk.mac.sh"
|
430
|
+
elsif Hardware.linux == true
|
431
|
+
execute_path = download_directory + "/burn_image_to_disk.sh"
|
432
|
+
else
|
433
|
+
execute_path = nil
|
434
|
+
end
|
435
|
+
if execute_path == nil
|
436
|
+
puts "This computer is not running a recognized OS. Exiting."
|
437
|
+
else
|
438
|
+
`#{execute_path} #{image_path} #{disk}`
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
def self.sd_card(worker_name, name, config)
|
443
|
+
download_directory = self.check_sd_card_scripts
|
444
|
+
if download_directory != nil
|
445
|
+
image_path = Hardware.get_sd_image(download_directory, worker_name)
|
446
|
+
wifi_settings = Hardware.fetch_wifi
|
447
|
+
if wifi_settings != nil
|
448
|
+
config_file_path = Hardware.sd_config_file(worker_name, name, download_directory)
|
449
|
+
if Hardware.brand_sd_image(download_directory, image_path, wifi_settings, config_file_path)
|
450
|
+
disk = Hardware.find_smallest_disk
|
451
|
+
if disk != "no_disk"
|
452
|
+
Hardware.burn_sd_image(download_directory, image_path, disk)
|
453
|
+
else
|
454
|
+
puts "No plausible SD card disk found. Please insert an SD card into your computer. Exiting."
|
455
|
+
end
|
456
|
+
end
|
457
|
+
else
|
458
|
+
puts "No WiFi settings found. Please run rake firmware:wifi[ssid,password,security_mode] to set your default wifi settings"
|
459
|
+
end
|
460
|
+
else
|
461
|
+
puts "SD card installation scripts not available. Exiting."
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
297
465
|
def self.install(worker_name, name)
|
298
466
|
config = Apiotics::Portal.openocd_worker_config(worker_name)
|
299
467
|
config = JSON.parse(config)
|
@@ -301,6 +469,8 @@ module Apiotics
|
|
301
469
|
Hardware.openocd(worker_name, name, config)
|
302
470
|
elsif config["installer"] == "Uniflash 4.3.0"
|
303
471
|
Hardware.uniflash(worker_name, name, config)
|
472
|
+
elsif config["installer"] == "SD Card"
|
473
|
+
Hardware.sd_card(worker_name, name, config)
|
304
474
|
else
|
305
475
|
puts "Unknown installer for #{worker_name}. Please check the installer settings for the #{worker_name} device on the Apiotics portal.\n"
|
306
476
|
end
|
@@ -331,14 +501,29 @@ module Apiotics
|
|
331
501
|
|
332
502
|
encrypted_wifi_config = args.to_json.apiotics_encrypt(pwd)
|
333
503
|
|
334
|
-
download_directory = Rails.root.join('lib', '
|
335
|
-
Dir.mkdir download_directory unless Dir.exist?(download_directory)
|
336
|
-
download_directory = Rails.root.join('lib', 'uniflash', 'downloads')
|
504
|
+
download_directory = Rails.root.join('lib', 'wifi')
|
337
505
|
Dir.mkdir download_directory unless Dir.exist?(download_directory)
|
338
506
|
Dir.chdir download_directory
|
339
|
-
path = Rails.root.join('lib', '
|
507
|
+
path = Rails.root.join('lib', 'wifi', 'wifi_settings')
|
340
508
|
File.write(path, encrypted_wifi_config)
|
341
509
|
end
|
342
510
|
|
511
|
+
def self.fetch_wifi
|
512
|
+
return_hash = nil
|
513
|
+
download_directory = Rails.root.join('lib', 'wifi')
|
514
|
+
Dir.mkdir download_directory unless Dir.exist?(download_directory)
|
515
|
+
Dir.chdir download_directory
|
516
|
+
path = Rails.root.join('lib', 'wifi', 'wifi_settings')
|
517
|
+
if File.exist?(path)
|
518
|
+
pwd = ApioticsSetting.find_by(key: "wifi_key")
|
519
|
+
if pwd != nil
|
520
|
+
pwd = pwd.value
|
521
|
+
encrypted_settings = File.read(path)
|
522
|
+
return_hash = encrypted_settings.apiotics_decrypt(pwd)
|
523
|
+
end
|
524
|
+
end
|
525
|
+
return_hash
|
526
|
+
end
|
527
|
+
|
343
528
|
end
|
344
529
|
end
|
data/lib/apiotics/portal.rb
CHANGED
@@ -250,6 +250,10 @@ module Apiotics
|
|
250
250
|
response = HTTParty.post("#{Apiotics.configuration.portal}api/openocd", :query => {:public_key => Apiotics.configuration.public_key, :private_key => Apiotics.configuration.private_key, :system => system}).body
|
251
251
|
end
|
252
252
|
|
253
|
+
def self.sd_scripts(system)
|
254
|
+
response = HTTParty.post("#{Apiotics.configuration.portal}api/sd_scripts", :query => {:public_key => Apiotics.configuration.public_key, :private_key => Apiotics.configuration.private_key, :system => system}).body
|
255
|
+
end
|
256
|
+
|
253
257
|
def self.openocd_worker_config(worker_name)
|
254
258
|
response = HTTParty.post("#{Apiotics.configuration.portal}api/openocd_details", :query => {:public_key => Apiotics.configuration.public_key, :private_key => Apiotics.configuration.private_key, :worker => worker_name}).body
|
255
259
|
end
|
@@ -262,6 +266,18 @@ module Apiotics
|
|
262
266
|
}
|
263
267
|
end
|
264
268
|
|
269
|
+
def self.get_sd_image(download_directory, worker_name)
|
270
|
+
filename = "#{download_directory}/#{worker_name}.img.gz"
|
271
|
+
File.open(filename, "w") do |file|
|
272
|
+
puts "Downloading image.."
|
273
|
+
response = HTTParty.post("#{Apiotics.configuration.portal}api/download", :query => {:public_key => Apiotics.configuration.public_key, :private_key => Apiotics.configuration.private_key, :worker => worker_name}, stream_body: true) do |fragment|
|
274
|
+
print "."
|
275
|
+
file.write(fragment)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
File.unlink(filename)
|
279
|
+
end
|
280
|
+
|
265
281
|
def self.register_client
|
266
282
|
response = HTTParty.post("#{Apiotics.configuration.portal}api/register_client", :query => {:public_key => Apiotics.configuration.public_key, :private_key => Apiotics.configuration.private_key}).body
|
267
283
|
hash = JSON.parse(response)
|
data/lib/apiotics/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiotics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MicroArx Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|