apiotics 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db6cd04319d0626204bec257c2996307ea450b80
4
- data.tar.gz: 5b7aab3cfba5c14cb824f04b2f3d78c4947a9373
3
+ metadata.gz: cf59743178c67ba8fc5651aae6497cd2142dc4f2
4
+ data.tar.gz: 51ea2c76b6b5c304680703b300b4121b029a2298
5
5
  SHA512:
6
- metadata.gz: 7b33c0097709e5bfd1551e8fc1c838d4c23383c92a7f5fe07b3be35a1735960796f0792e68e9a26c21ba3ad81ab751fa7057087718d48b15158addce4d4e035f
7
- data.tar.gz: 8b30fde35f8a3b9b0e2c0c9082711414c66a147d89642d66b1f49f659fd655bbb62e2e12b4d66698a9044d63223d539cacc53ea437fcea1ffdfe6732fd294b2e
6
+ metadata.gz: 75f585a1105d7d12f2761f9b52c2fa7a4cfd6720c55664dab61372d34bbec1c57cc53cf089a103e83c359e2548708f92410708adc74216937c77b94cc97a4380
7
+ data.tar.gz: 81306f49643f01775a86e47390b98e76f9f9a48c5d4d12d011ed35a8f8006b7e2607149ac8e07acf88f17918f2caa1df080f37164d48bd8b07680b03245d094d
@@ -310,11 +310,11 @@ module Apiotics
310
310
  downloaded = false
311
311
  unless system == nil
312
312
  if system == "mac"
313
- if File.exist?("#{download_directory}/brand_image.mac.sh")
313
+ if File.exist?("#{download_directory}/brand_and_burn.mac.sh")
314
314
  downloaded = true
315
315
  end
316
316
  elsif system == "linux"
317
- if File.exist?("#{download_directory}/brand_image.sh")
317
+ if File.exist?("#{download_directory}/brand_and_burn.sh")
318
318
  downloaded = true
319
319
  end
320
320
  end
@@ -327,11 +327,11 @@ module Apiotics
327
327
  `rm #{download_directory}/sd_scripts.tgz`
328
328
  end
329
329
  if system == "mac"
330
- if File.exist?("#{download_directory}/brand_image.mac.sh")
330
+ if File.exist?("#{download_directory}/brand_and_burn.mac.sh")
331
331
  status = download_directory
332
332
  end
333
333
  elsif system == "linux"
334
- if File.exist?("#{download_directory}/brand_image.sh")
334
+ if File.exist?("#{download_directory}/brand_and_burn.sh")
335
335
  status = download_directory
336
336
  end
337
337
  end
@@ -339,11 +339,16 @@ module Apiotics
339
339
  return status
340
340
  end
341
341
 
342
- def self.get_sd_image(download_directory, worker_name)
342
+ def self.get_sd_image(download_directory, worker_name, config)
343
343
  Dir.chdir download_directory
344
- image_path = "#{download_directory}/#{worker_name}.img.gz"
344
+ worker_directory = download_directory.to_s + "/#{worker_name.downcase}"
345
+ Dir.mkdir worker_directory unless Dir.exist?(worker_directory)
346
+ image_name = "#{worker_name.downcase}-#{config['device_name'].underscore}-#{config['device_version']}"
347
+ image_name = image_name.gsub(" ", "_")
348
+ image_path = "#{worker_directory}/#{image_name}.img.gz"
345
349
  unless File.exist?(image_path)
346
- Apiotics::Portal.get_sd_image(download_directory, worker_name)
350
+ `rm #{worker_directory}/*`
351
+ Apiotics::Portal.get_sd_image(worker_directory, worker_name, image_name)
347
352
  #zip_path = "#{download_directory}/#{worker_name}.img.gz"
348
353
  #`gunzip -c #{zip_path} > #{image_path}`
349
354
  #`rm #{zip_path}`
@@ -380,96 +385,63 @@ module Apiotics
380
385
  config_file_path
381
386
  end
382
387
 
383
- def self.brand_sd_image(download_directory, image_path, wifi_settings, config_file_path)
388
+ def self.brand_and_burn_sd_image(download_directory, image_path, wifi_settings, config_file_path)
384
389
  status = false
385
390
  Dir.chdir download_directory
386
- branding_script_path = nil
391
+ script_path = nil
387
392
  if Hardware.mac == true
388
- branding_script_path = "#{download_directory}/brand_image.mac.sh"
393
+ script_path = "#{download_directory}/brand_and_burn.mac.sh"
389
394
  elsif Hardware.linux == true
390
- branding_script_path = "#{download_directory}/brand_image.sh"
395
+ script_path = "#{download_directory}/brand_and_burn.sh"
391
396
  end
392
- if branding_script_path != nil
397
+ if script_path != nil
393
398
  #puts "Please wait..."
394
- puts "Running #{branding_script_path} #{image_path} #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{config_file_path} dhcp"
395
- IO.popen("#{branding_script_path} #{image_path} #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{config_file_path} dhcp") do |io|
399
+ puts "Running sudo -S #{script_path} brand_and_burn #{image_path} no_disk #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{wifi_settings["security_mode"]} #{config_file_path} 0 dhcp"
400
+ IO.popen("sudo -S #{script_path} brand_and_burn #{image_path} no_disk #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{wifi_settings["security_mode"]} #{config_file_path} 0 dhcp") do |io|
396
401
  while (line = io.gets) do
397
402
  puts line
398
403
  end
399
404
  end
400
405
  status = true
401
406
  else
402
- puts "Unrecognized system architecture, exiting."
407
+ puts "Unrecognized operating system, exiting."
403
408
  end
404
409
  status
405
410
  end
406
411
 
407
- def self.find_smallest_disk
408
- small_disk_size = 99999999999999999999
409
- small_disk = "no_disk"
410
- disks = {}
411
- output = `df -k`
412
- lines = output.split("\n")
413
- i = 0
414
- lines.each do |line|
415
- lines[i] = line.split(" ")
416
- i += 1
417
- end
418
- gigabyte_scaling = 1024 * 1024
419
- lines.each do |line|
420
- length = line.count
421
- unless line[length - 1] == "/"
422
- disks[line[0]] = line[1].to_i / gigabyte_scaling
423
- end
424
- end
425
- disks.each do |disk, size|
426
- if size < small_disk_size && size > 4 && disk[0..3] == "/dev"
427
- small_disk_size = size
428
- small_disk = disk
429
- end
430
- end
431
- return small_disk
432
- end
433
-
434
- def self.burn_sd_image(download_directory, image_path, disk)
435
- Dir.chdir download_directory
436
- img_path = image_path.chomp(".img.gz") + "_branded.img.gz"
437
- puts "Burning #{image_path}..."
438
- if Hardware.mac == true
439
- execute_path = download_directory.to_s + "/burn_image_to_disk.mac.sh"
440
- elsif Hardware.linux == true
441
- execute_path = download_directory.to_s + "/burn_image_to_disk.sh"
442
- else
443
- execute_path = nil
444
- end
445
- if execute_path == nil
446
- puts "This computer is not running a recognized OS. Exiting."
447
- else
448
- puts "Running sudo #{execute_path} #{image_path}"
449
- #pwd = STDIN.getpass("Password:")
450
- IO.popen("sudo -S #{execute_path} #{img_path}") do |io|
451
- while (line = io.gets) do
452
- puts line
453
- end
454
- end
455
- end
456
- end
412
+ #def self.burn_sd_image(download_directory, image_path)
413
+ # Dir.chdir download_directory
414
+ # img_path = image_path.chomp(".img.gz") + "_branded.img.gz"
415
+ # puts "Burning #{image_path}..."
416
+ # if Hardware.mac == true
417
+ # execute_path = download_directory.to_s + "/burn_image_to_disk.mac.sh"
418
+ # elsif Hardware.linux == true
419
+ # execute_path = download_directory.to_s + "/burn_image_to_disk.sh"
420
+ # else
421
+ # execute_path = nil
422
+ # end
423
+ # if execute_path == nil
424
+ # puts "This computer is not running a recognized OS. Exiting."
425
+ # else
426
+ # puts "Running sudo #{execute_path} #{image_path}"
427
+ # #pwd = STDIN.getpass("Password:")
428
+ # IO.popen("sudo -S #{execute_path} #{img_path}") do |io|
429
+ # while (line = io.gets) do
430
+ # puts line
431
+ # end
432
+ # end
433
+ # end
434
+ #end
457
435
 
458
436
  def self.sd_card(worker_name, name, config)
437
+ #puts "Grab a coffee, this may take a few minutes..."
459
438
  download_directory = Apiotics::Hardware.check_sd_card_scripts
460
439
  if download_directory != nil
461
- image_path = Apiotics::Hardware.get_sd_image(download_directory, worker_name)
440
+ image_path = Apiotics::Hardware.get_sd_image(download_directory, worker_name, config)
462
441
  wifi_settings = Apiotics::Hardware.fetch_wifi
463
442
  if wifi_settings != nil
464
443
  config_file_path = Apiotics::Hardware.sd_config_file(worker_name, name, download_directory)
465
- if Apiotics::Hardware.brand_sd_image(download_directory, image_path, wifi_settings, config_file_path)
466
- disk = Apiotics::Hardware.find_smallest_disk
467
- if disk != "no_disk"
468
- Apiotics::Hardware.burn_sd_image(download_directory, image_path, disk)
469
- else
470
- puts "No plausible SD card disk found. Please insert an SD card into your computer. Exiting."
471
- end
472
- end
444
+ Apiotics::Hardware.brand_and_burn_sd_image(download_directory, image_path, wifi_settings, config_file_path)
473
445
  else
474
446
  puts "No WiFi settings found. Please run rake firmware:wifi[ssid,password,security_mode] to set your default wifi settings"
475
447
  end
@@ -500,7 +472,7 @@ module Apiotics
500
472
  }
501
473
  args.keys.each do |key|
502
474
  if args[key] == nil
503
- args[key] = ""
475
+ args[key] = "NONE"
504
476
  end
505
477
  end
506
478
 
@@ -268,8 +268,8 @@ module Apiotics
268
268
 
269
269
  ##
270
270
 
271
- def self.get_sd_image(download_directory, worker_name)
272
- filename = "#{download_directory}/#{worker_name}.img.gz"
271
+ def self.get_sd_image(download_directory, worker_name, image_name)
272
+ filename = "#{download_directory}/#{image_name}.img.gz"
273
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}).body
274
274
  response = JSON.parse(response)
275
275
  url = response["url"]
@@ -1,3 +1,3 @@
1
1
  module Apiotics
2
- VERSION = '0.2.11'
2
+ VERSION = '0.2.12'
3
3
  end
@@ -1,15 +1,18 @@
1
1
  namespace :firmware do
2
2
  desc "Set Wifi details for a device (if applicable). Use rake firmware:wifi[ssid, password, security_mode] to set the wifi details for a device."
3
3
  task :wifi, [:ssid, :password, :security_mode] => [:environment] do |task, args|
4
- security_modes = ["WEP", "WPA", "WPA2"]
4
+ security_modes = ["WEP", "WPA", "WPA2", "NONE"]
5
+ password = args[:password] || 'NONE'
5
6
  if args[:security_mode] != nil
6
7
  unless security_modes.include?(args[:security_mode])
7
8
  puts "#{args[:security_mode]} is not a supported WiFi security mode. The supported security modes are: #{security_modes.to_s}"
8
9
  else
9
- Apiotics::Hardware.wifi(args[:ssid], args[:password], args[:security_mode])
10
+ Apiotics::Hardware.wifi(args[:ssid], password, args[:security_mode])
10
11
  end
11
12
  else
12
- Apiotics::Hardware.wifi(args[:ssid], args[:password], nil)
13
+ Apiotics::Hardware.wifi(args[:ssid], password, "NONE")
13
14
  end
14
15
  end
15
- end
16
+ end
17
+
18
+ #
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.11
4
+ version: 0.2.12
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-22 00:00:00.000000000 Z
11
+ date: 2018-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails