lifx_dash 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjBlMWRjMmRmOWZlZDY1NjJiODA1NDNmZTIyZWVlZDYxNTkyOWFhMw==
4
+ M2Q0MTdjYWZlZmM1MzQ0ZGE5MWY3YTJmMjM3NmVhNzdmNzZiZmZlMg==
5
5
  data.tar.gz: !binary |-
6
- MTQyZDA5Yjc1ZDM4NGFjODU2ZWM3NmQzODQ5YTM2MWI3MzUxZWZkMw==
6
+ OWVhMDk4N2JhNGIwYmNmODg0YTlhYzU2NjczNWYzZmYzOWMxMzVlMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzIzY2FjNmYyYzRkODc1YjRmZjIzMDc0MGZjN2ZiOWJhYjQxOGJjNWRkNWYy
10
- MTEwMmNjY2QzN2QwYzIzODUyNzQ2NTg4OTE1Y2E5MGVkMzdhOGM0ODBjNWY1
11
- MjhjMmQ1MmFiYzhlZjUyMjJmNzQ2OGE5NDg4Y2RlMWM1NmY0MTQ=
9
+ ZDc3ZjhlYzhjNmExYmU5ZGEyNGM4OTE4MGZkMTMzYTBhMTZmMzEwMTE4ZjNj
10
+ MmY5MTFkNzBjN2Y3YjE4NzcyODEyMjdiMjUxY2I5ZDcxMzdmNjljNDA2Mjk4
11
+ MzY5ZDlkNTFkZDRjZDMxOGVhYTgyMDJkMDJlZDE3MGNhYjdlYjY=
12
12
  data.tar.gz: !binary |-
13
- NWZmYjlmZDMzOTlhNGUwNGZiYjlkYzBkYzAxNjU4OGM3NzA0YTE1ZDdkZDhk
14
- YWMwZTdkZDc0ZGZiODU2NDcyNGFmMmM0ZjNkYzJkMGEzZjNkMDQwMWNkN2Q4
15
- YjE0ODRlMWMxZDQzNzZjZmFmNjM1MGEyNTFjN2ZiZDcwMzQ3NmQ=
13
+ ZmZlZmQ5MDAwYjgwN2Q1MGU0MWFmODY5YTdiNTIxYmE1ODFjNTlhODlmMzM1
14
+ Y2Y2OGFiZWQ3MDEzNmE2YzBlYjQ4ZTE2ZDFlZGJiM2E1ZWM4YWM5ZDBhMjIw
15
+ MDdmMDhkYzU0ZDZjNTcxNDk3MjAyNzljZTBjZWYxYzc4ZmI2ZDc=
data/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ project adheres to [Semantic Versioning][Semver].
7
7
 
8
8
  * Validation of all command line flag values, iface/mac/token etc.
9
9
 
10
+ ## [0.1.3][] (2 Jul 2016)
11
+ * Mentioning libpcap dependency
12
+ * Refactoring Configuration - added CONFIG const and fixed sudo home dir issue
13
+
14
+ ## [0.1.2][] (2 Jul 2016)
15
+ * YANKED!
16
+
10
17
  ## [0.1.1][] (30 Jun 2016)
11
18
  * Testing auto-releasing gem from Travis CI
12
19
 
@@ -15,7 +22,8 @@ project adheres to [Semantic Versioning][Semver].
15
22
  * Includes dameonizing option for monitor command (writing to a log file)
16
23
  * Built with gli command-suite gem
17
24
 
18
- [Unreleased]: https://github.com/matthutchinson/lifx_dash/compare/v0.1.1...HEAD
25
+ [Unreleased]: https://github.com/matthutchinson/lifx_dash/compare/v0.1.3...HEAD
26
+ [0.1.3]: https://github.com/matthutchinson/lifx_dash/compare/v0.1.1...v0.1.3
19
27
  [0.1.1]: https://github.com/matthutchinson/lifx_dash/compare/v0.1.0...v0.1.1
20
28
  [0.1.0]: https://github.com/matthutchinson/lifx_dash/releases/tag/v0.1.0
21
29
  [Semver]: http://semver.org
data/README.md CHANGED
@@ -29,6 +29,15 @@ A `config` command also exists, allowing you to set default options for
29
29
  will also need a wifi network and root access to sniff packets on your network
30
30
  adaptor.
31
31
 
32
+ This gem uses [packet_fu](https://rubygems.org/gems/packetfu) which in turn
33
+ requires the [libpcap](http://www.tcpdump.org) library. This is probably already
34
+ available on your machine, if not download the [latest
35
+ release](http://www.tcpdump.org/#latest-release) or install with your package
36
+ manager e.g.:
37
+
38
+ sudo apt-get install libpcap0.8-dev # UNIX
39
+ brew install libpcap # homebrew on OSX
40
+
32
41
  `lifx_dash` is distributed via [RubyGems](https://rubygems.org) and requires
33
42
  [Ruby](https://www.ruby-lang.org) >= 2.0.0.
34
43
 
data/bin/lifx_dash CHANGED
@@ -6,7 +6,7 @@ require "lifx_dash"
6
6
  include GLI::App
7
7
 
8
8
  LOGGER = Logger.new(STDOUT)
9
- config_options = LifxDash::Configuration.load
9
+ CONFIG = LifxDash::Configuration.new
10
10
 
11
11
  program_desc "Toggle LIFX lights with an Amazon Dash button"
12
12
 
@@ -25,7 +25,11 @@ command :config do |c|
25
25
  c.switch [:s, :show]
26
26
 
27
27
  c.action do |_global_options, options, _args|
28
- LifxDash::Configuration.new.run(show_config: options["show"])
28
+ if options["show"]
29
+ CONFIG.show
30
+ else
31
+ CONFIG.configure
32
+ end
29
33
  end
30
34
  end
31
35
 
@@ -38,7 +42,7 @@ packets of their own when you press. Take care to choose the MAC address from
38
42
  the ARP packet that occurs only once from a single MAC address."
39
43
  command :snoop do |c|
40
44
  c.desc "Network Interface"
41
- c.default_value config_options["iface"] || "en0"
45
+ c.default_value CONFIG["iface"] || "en0"
42
46
  c.flag [:i, :iface]
43
47
 
44
48
  c.action do |_global_options, options, _args|
@@ -61,30 +65,30 @@ overrride this location."
61
65
  command :monitor do |c|
62
66
 
63
67
  c.desc "Dash button MAC address"
64
- c.default_value config_options["mac-address"]
68
+ c.default_value CONFIG["mac-address"]
65
69
  c.flag [:m, :"mac-address"]
66
70
 
67
71
  c.desc "LIFX HTTP API Token"
68
- c.default_value config_options["token"]
72
+ c.default_value CONFIG["token"]
69
73
  c.flag [:t, :token]
70
74
 
71
75
  c.desc "LIFX Bulb Selector"
72
- c.default_value config_options["selector"] || "all"
76
+ c.default_value CONFIG["selector"] || "all"
73
77
  c.flag [:s, :selector]
74
78
 
75
79
  c.desc "Network Interface"
76
- c.default_value config_options["iface"] || "en0"
80
+ c.default_value CONFIG["iface"] || "en0"
77
81
  c.flag [:i, :iface]
78
82
 
79
83
  c.desc "Log file location (when running as a daemon)"
80
- c.default_value config_options["log-file"] || LifxDash::Daemonizer::LOG_FILE
84
+ c.default_value CONFIG["log-file"] || LifxDash::Daemonizer::LOG_FILE
81
85
  c.flag [:l, :"log-file"]
82
86
 
83
87
  c.desc "Dameonize the monitor process"
84
88
  c.switch [:d, :daemonize]
85
89
 
86
90
  c.action do |_global_options, options, _args|
87
- help_now!("a valid Dash button MAC address option (-m) is required: use `lifx_dash snoop #{options["iface"]}` to find it") unless options["mac-address"]
91
+ help_now!("a valid Dash button MAC address option (-m) is required: use `lifx_dash snoop -i #{options["iface"]}` to find it") unless options["mac-address"]
88
92
  help_now!("a valid LIFX API Token option (-t) is required: get one from https://cloud.lifx.com/settings") unless options["token"]
89
93
 
90
94
  if options["daemonize"]
@@ -3,8 +3,8 @@ require "yaml"
3
3
  module LifxDash
4
4
  class Configuration
5
5
 
6
- CONFIG_FILE = File.join(ENV["HOME"], ".lifx_dash.rc.yml")
7
- OPTION_PROMPTS = {
6
+ CONFIG_FILE_NAME = ".lifx_dash.rc.yml"
7
+ OPTION_PROMPTS = {
8
8
  "iface" => "Network interface identifier e.g. en0 (choose from ifconfig -l)",
9
9
  "token" => "LIFX API token (get a free personal token at cloud.lifx.com)",
10
10
  "mac-address" => "Dash button MAC address (use lifx_dash snoop to find it)",
@@ -12,26 +12,17 @@ module LifxDash
12
12
  "log-file" => "Log file location (when running as a daemon)"
13
13
  }
14
14
 
15
- def self.load
16
- if File.exist?(CONFIG_FILE)
17
- YAML.load_file(CONFIG_FILE)
18
- else
19
- {}
20
- end
21
- end
22
-
23
- def run(show_config: false)
24
- # decide to show config or start configuring
25
- show_config ? show : configure
15
+ def [](key)
16
+ config_options[key]
26
17
  end
27
18
 
28
19
  def show
29
- if File.exist?(CONFIG_FILE)
30
- puts "Configuration file at #{CONFIG_FILE} ...\n\n"
31
- puts File.read(CONFIG_FILE)
20
+ if File.exist?(config_file)
21
+ puts "Configuration file at #{config_file} ...\n\n"
22
+ puts File.read(config_file)
32
23
  puts "\nChange these options with `lifx_dash config`"
33
24
  else
34
- puts "No configuration file exists at #{CONFIG_FILE}"
25
+ puts "No configuration file exists at #{config_file}"
35
26
  end
36
27
  end
37
28
 
@@ -42,10 +33,37 @@ module LifxDash
42
33
  if user_options.values.all?(&:nil?)
43
34
  puts "\nNo options set, configuration is unchanged"
44
35
  else
45
- File.open(CONFIG_FILE, "w") do |file|
36
+ File.open(config_file, "w") do |file|
46
37
  YAML::dump(user_options, file)
47
38
  end
48
- puts "\nConfiguration saved to #{CONFIG_FILE}"
39
+ puts "\nConfiguration saved to #{config_file}"
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def config_file
46
+ @config_file ||= begin
47
+ home_dir = ENV["HOME"]
48
+
49
+ # when running as sudo on linux, use the sudo users' home dir
50
+ if platform == :linux &&
51
+ ENV["SUDO_USER"] &&
52
+ File.exist?("/home/#{ENV["SUDO_USER"]}")
53
+ home_dir = "/home/#{ENV["SUDO_USER"]}"
54
+ end
55
+
56
+ File.join(home_dir, CONFIG_FILE_NAME)
57
+ end
58
+ end
59
+
60
+ def config_options
61
+ @config_options ||= begin
62
+ if File.exist?(config_file)
63
+ YAML.load_file(config_file)
64
+ else
65
+ {}
66
+ end
49
67
  end
50
68
  end
51
69
 
@@ -56,6 +74,19 @@ module LifxDash
56
74
  end
57
75
  end
58
76
 
77
+ def platform
78
+ case RbConfig::CONFIG['host_os']
79
+ when /linux/
80
+ :linux
81
+ when /darwin/
82
+ :mac
83
+ when /(win|w)32/
84
+ :windows
85
+ else
86
+ :unknown
87
+ end
88
+ end
89
+
59
90
  def parse_user_input(str)
60
91
  # handle empty strings
61
92
  if str.empty?
@@ -1,3 +1,3 @@
1
1
  module LifxDash
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lifx_dash.gemspec CHANGED
@@ -43,6 +43,7 @@ Gem::Specification.new do |spec|
43
43
 
44
44
  # non-gem dependecies
45
45
  spec.required_ruby_version = ">= 2.0.0"
46
+ spec.requirements << 'libpcap'
46
47
  spec.requirements << 'an Amazon Dash button'
47
48
  spec.requirements << 'one or more LIFX bulbs'
48
49
  spec.requirements << 'root access'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifx_dash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Hutchinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -229,6 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements:
232
+ - libpcap
232
233
  - an Amazon Dash button
233
234
  - one or more LIFX bulbs
234
235
  - root access