apiotics 0.2.8 → 0.2.9

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: 41dcd2f44d625cc322694b01aaa300b5b836a4f0
4
- data.tar.gz: 3eed758660cd07bc6075f678e87428ebd9e6c459
3
+ metadata.gz: c8c1c641a4fd78cbf146dce87fd547de4eccd727
4
+ data.tar.gz: 1d71b5ea8c9ee2d4dc6f68aaa58b8691a8267e67
5
5
  SHA512:
6
- metadata.gz: 4d7da40f950e9960145b8eefac79e35154a9da724c363c9535b3e1a6c4755a56a0ec0a57fef043bd323f26cc8a2077e5ca60b47865b3f05c61bdbca34243fb35
7
- data.tar.gz: 161a54125eaf1b04b8014b672f826b634a1b26e2e2aec15ee4c867418604ecdc429b3a2afb8a416d9657b0da0809aaf6632fda8370d87a96a968cbd4a0e936bf
6
+ metadata.gz: e44139a7721d61e90c44f75facf5dd165554f6a9e5bc45c58ab72bff87e09835741f22036f89bd87a5c2a2af7c2447b91aa28691a99cabd4a0d66387e8ebedf6
7
+ data.tar.gz: c7e1d205d7dfbfc416cd4cce47cea1c87f8d15c84c4d9fd7c9976772d05cd5e0550188b64cc6f695fbe958fb0ca887a9eeeffe4ce0fa14e35e0b09f0ea1f2414
@@ -320,7 +320,9 @@ module Apiotics
320
320
  end
321
321
  if downloaded == false
322
322
  scripts = Apiotics::Portal.sd_scripts(system)
323
- File.write("#{download_directory}/sd_scripts.tgz")
323
+ file = File.open("#{download_directory}/sd_scripts.tgz", 'wb')
324
+ file.write(scripts)
325
+ file.close
324
326
  `tar xvzf #{download_directory}/sd_scripts.tgz -C #{download_directory}`
325
327
  `rm #{download_directory}/sd_scripts.tgz`
326
328
  end
@@ -350,7 +352,7 @@ module Apiotics
350
352
  end
351
353
 
352
354
  def self.sd_config_file(worker_name, name, download_directory)
353
- worker_directory = download_directory + "/#{worker_name.downcase}"
355
+ worker_directory = download_directory.to_s + "/#{worker_name.downcase}"
354
356
  Dir.mkdir worker_directory unless Dir.exist?(worker_directory)
355
357
  config_file_path = "#{worker_directory}/#{worker_name.downcase}.json"
356
358
  if File.exist?(config_file_path)
@@ -380,14 +382,19 @@ module Apiotics
380
382
 
381
383
  def self.brand_sd_image(download_directory, image_path, wifi_settings, config_file_path)
382
384
  status = false
383
- branding_script_path == nil
385
+ branding_script_path = nil
384
386
  if Hardware.mac == true
385
387
  branding_script_path = "#{download_directory}/brand_image.mac.sh"
386
388
  elsif Hardware.linux == true
387
389
  branding_script_path = "#{download_directory}/brand_image.sh"
388
390
  end
389
391
  if branding_script_path != nil
390
- `#{branding_script_path} #{image_path} #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{config_file_path} dhcp`
392
+ #puts "Please wait..."
393
+ IO.popen("#{branding_script_path} #{image_path} #{wifi_settings["ssid"]} #{wifi_settings["password"]} #{config_file_path} dhcp") do |io|
394
+ while (line = io.gets) do
395
+ puts line
396
+ end
397
+ end
391
398
  status = true
392
399
  else
393
400
  puts "Unrecognized system architecture, exiting."
@@ -423,23 +430,30 @@ module Apiotics
423
430
  end
424
431
 
425
432
  def self.burn_sd_image(download_directory, image_path, disk)
433
+ img_path = image_path.chomp(".img.gz") + "_branded.img.gz"
426
434
  puts "Burning #{image_path} to #{disk}..."
427
435
  if Hardware.mac == true
428
- execute_path = download_directory + "/burn_image_to_disk.mac.sh"
436
+ execute_path = download_directory.to_s + "/burn_image_to_disk.mac.sh"
429
437
  elsif Hardware.linux == true
430
- execute_path = download_directory + "/burn_image_to_disk.sh"
438
+ execute_path = download_directory.to_s + "/burn_image_to_disk.sh"
431
439
  else
432
440
  execute_path = nil
433
441
  end
434
442
  if execute_path == nil
435
443
  puts "This computer is not running a recognized OS. Exiting."
436
444
  else
437
- `#{execute_path} #{image_path} #{disk}`
445
+ puts "Running sudo #{execute_path} #{image_path} #{disk}"
446
+ #pwd = STDIN.getpass("Password:")
447
+ IO.popen("sudo -S #{execute_path} #{img_path} #{disk}") do |io|
448
+ while (line = io.gets) do
449
+ puts line
450
+ end
451
+ end
438
452
  end
439
453
  end
440
454
 
441
455
  def self.sd_card(worker_name, name, config)
442
- download_directory = self.check_sd_card_scripts
456
+ download_directory = Hardware.check_sd_card_scripts
443
457
  if download_directory != nil
444
458
  image_path = Hardware.get_sd_image(download_directory, worker_name)
445
459
  wifi_settings = Hardware.fetch_wifi
@@ -520,6 +534,7 @@ module Apiotics
520
534
  encrypted_settings = File.read(path)
521
535
  return_hash = encrypted_settings.apiotics_decrypt(pwd)
522
536
  end
537
+ return_hash = JSON.parse(return_hash)
523
538
  end
524
539
  return_hash
525
540
  end
@@ -266,16 +266,34 @@ module Apiotics
266
266
  }
267
267
  end
268
268
 
269
+ ##
270
+
269
271
  def self.get_sd_image(download_directory, worker_name)
270
272
  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 "."
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
+ response = JSON.parse(response)
275
+ url = response["url"]
276
+ size = response["size"].to_i
277
+ #puts url
278
+ total_downloaded = 0
279
+ chunk = size / 50
280
+ back = "\b" * 52
281
+ todo = " " * 50
282
+ File.open(filename, "wb") do |file|
283
+ puts "Downloading image..\n"
284
+ print "[#{todo}]"
285
+ HTTParty.get(url, stream_body: true) do |fragment|
286
+ total_downloaded = total_downloaded + fragment.length
287
+ done = "#" * (total_downloaded / chunk)
288
+ todo = " " * (50 - total_downloaded / chunk)
289
+ print "#{back}"
290
+ print "[#{done}#{todo}]"
275
291
  file.write(fragment)
276
292
  end
277
293
  end
278
- File.unlink(filename)
294
+ fin = "#" * 50
295
+ print "#{back}"
296
+ print "[#{fin}]\n"
279
297
  end
280
298
 
281
299
  def self.register_client
@@ -1,3 +1,3 @@
1
1
  module Apiotics
2
- VERSION = '0.2.8'
2
+ VERSION = '0.2.9'
3
3
  end
@@ -8,6 +8,8 @@ namespace :firmware do
8
8
  else
9
9
  Apiotics::Hardware.wifi(args[:ssid], args[:password], args[:security_mode])
10
10
  end
11
+ else
12
+ Apiotics::Hardware.wifi(args[:ssid], args[:password], nil)
11
13
  end
12
14
  end
13
15
  end
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.8
4
+ version: 0.2.9
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-21 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  version: '0'
268
268
  requirements: []
269
269
  rubyforge_project:
270
- rubygems_version: 2.6.10
270
+ rubygems_version: 2.2.2
271
271
  signing_key:
272
272
  specification_version: 4
273
273
  summary: IoT For Everybody.