mac-wifi 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/RELEASE_NOTES.md +12 -0
- data/bin/mac-wifi +54 -16
- data/mac-wifi.gemspec +3 -2
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a58d1685f69fd21d35c2e06e323a7d932e5c82f
|
4
|
+
data.tar.gz: 9b129f36832db299389950a7fb9d8561dedb1a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a34b48bf98052309743cd068ebe3b32612ace5577fd6b00449e0c55a0bf9f5037c6a8c16483a667887b89692160e021a22cdaa5f2ef229b1a84faeee2d51204
|
7
|
+
data.tar.gz: 82ad9b39c6c17632bcea897b4b9f7592dbe0e063ef5c0294ba4b043122ea1c788609248de690495e1ffc914ce7940e3ce33439eb8135049d70338e904e4393a3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# mac-wifi
|
2
2
|
|
3
|
-
The script installed by this gem (or otherwise copied) enables the query and management of wifi configuration and environment on a Mac.
|
3
|
+
The `mac-wifi` script installed by this gem (or otherwise copied) enables the query and management of wifi configuration and environment on a Mac.
|
4
4
|
The code encapsulates the Mac OS specific logic in a minimal class to more easily add support for other operating systems,
|
5
5
|
but as of now, only Mac OS is supported. (Feel free to add an OS!)
|
6
6
|
|
data/RELEASE_NOTES.md
ADDED
data/bin/mac-wifi
CHANGED
@@ -26,7 +26,7 @@ require 'tempfile'
|
|
26
26
|
module MacWifi
|
27
27
|
|
28
28
|
# This version must be kept in sync with the version in the gemspec file.
|
29
|
-
VERSION = '1.
|
29
|
+
VERSION = '1.1.0'
|
30
30
|
|
31
31
|
|
32
32
|
class BaseModel
|
@@ -127,6 +127,10 @@ class BaseModel
|
|
127
127
|
# Turns wifi on first, in case it was turned off.
|
128
128
|
# Relies on subclass implementation of simple_connect().
|
129
129
|
def connect(network_name, password = nil)
|
130
|
+
# Allow symbols and anything responding to to_s for user convenience
|
131
|
+
network_name = network_name.to_s if network_name
|
132
|
+
password = password.to_s if password
|
133
|
+
|
130
134
|
if network_name.nil? || network_name.empty?
|
131
135
|
raise "A network name is required but was not provided."
|
132
136
|
end
|
@@ -163,6 +167,7 @@ class BaseModel
|
|
163
167
|
|
164
168
|
|
165
169
|
def preferred_network_password(preferred_network_name)
|
170
|
+
preferred_network_name = preferred_network_name.to_s
|
166
171
|
if preferred_networks.include?(preferred_network_name)
|
167
172
|
simple_preferred_network_password(preferred_network_name)
|
168
173
|
else
|
@@ -179,17 +184,17 @@ class BaseModel
|
|
179
184
|
|
180
185
|
wait_interval_in_secs ||= 0.5
|
181
186
|
|
182
|
-
|
183
|
-
|
184
|
-
-> { connected_to_internet? }
|
185
|
-
|
186
|
-
-> { !
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
187
|
+
actions = {
|
188
|
+
conn: -> { connected_to_internet? },
|
189
|
+
disc: -> { ! connected_to_internet? },
|
190
|
+
on: -> { wifi_on? },
|
191
|
+
off: -> { ! wifi_on? }
|
192
|
+
}
|
193
|
+
|
194
|
+
exit_when = actions[status]
|
195
|
+
|
196
|
+
if exit_when.nil?
|
197
|
+
raise ArgumentError.new("Option must be one of [#{actions.keys.map(&:inspect).join(', ')}]. Was: #{status.inspect}")
|
193
198
|
end
|
194
199
|
|
195
200
|
loop do
|
@@ -197,7 +202,6 @@ class BaseModel
|
|
197
202
|
sleep(wait_interval_in_secs)
|
198
203
|
end
|
199
204
|
end
|
200
|
-
|
201
205
|
end
|
202
206
|
|
203
207
|
|
@@ -243,14 +247,30 @@ class MacOsModel < BaseModel
|
|
243
247
|
|
244
248
|
# Returns data pertaining to available wireless networks.
|
245
249
|
# For some reason, this often returns no results, so I've put the operation in a loop.
|
250
|
+
# I was unable to detect a sort strategy in the airport utility's output, so I sort
|
251
|
+
# the lines alphabetically, to show duplicates and for easier lookup.
|
246
252
|
def available_network_info
|
247
253
|
return nil unless wifi_on? # no need to try
|
248
254
|
command = "#{AIRPORT_CMD} -s"
|
249
255
|
max_attempts = 50
|
256
|
+
|
257
|
+
reformat_line = ->(line) do
|
258
|
+
ssid = line[0..31].strip
|
259
|
+
"%-32.32s%s" % [ssid, line[32..-1]]
|
260
|
+
end
|
261
|
+
|
250
262
|
max_attempts.times do
|
251
263
|
output = run_os_command(command)
|
252
264
|
if output.size > 0
|
253
|
-
|
265
|
+
lines = output.split("\n")
|
266
|
+
header_line = lines[0]
|
267
|
+
data_lines = lines[1..-1]
|
268
|
+
data_lines.map! do |line|
|
269
|
+
# Reformat the line so that the name is left instead of right justified
|
270
|
+
reformat_line.(line)
|
271
|
+
end
|
272
|
+
data_lines.sort!
|
273
|
+
return [reformat_line.(header_line)] + data_lines
|
254
274
|
end
|
255
275
|
end
|
256
276
|
raise "Unable to get available network information after #{max_attempts} attempts."
|
@@ -345,6 +365,7 @@ class MacOsModel < BaseModel
|
|
345
365
|
|
346
366
|
|
347
367
|
def remove_preferred_network(network_name)
|
368
|
+
network_name = network_name.to_s
|
348
369
|
run_os_command("sudo networksetup -removepreferredwirelessnetwork " +
|
349
370
|
"#{wifi_hardware_port} #{Shellwords.shellescape(network_name)}")
|
350
371
|
end
|
@@ -767,13 +788,30 @@ end
|
|
767
788
|
#
|
768
789
|
# 1) by loading this file directly, or
|
769
790
|
# 2) by running as a gem executable's binstub, in (relatively) '../../../bin'
|
791
|
+
#
|
792
|
+
# For example, I get this when running this file as a gem:
|
793
|
+
# __FILE__ = /Users/kbennett/.rvm/gems/ruby-2.4.0/gems/mac-wifi-1.0.0/bin/mac-wifi
|
794
|
+
# $0 = /Users/kbennett/.rvm/gems/ruby-2.4.0/bin/mac-wifi
|
795
|
+
# GEM_PATH = /Users/kbennett/.rvm/gems/ruby-2.4.0:/Users/kbennett/.rvm/gems/ruby-2.4.0@global
|
770
796
|
|
771
797
|
def running_as_script?
|
798
|
+
|
799
|
+
# Please enable this code and report its output if you report any issues with this method:
|
800
|
+
# puts "__FILE__ = #{__FILE__}"
|
801
|
+
# puts "$0 = #{$0}"
|
802
|
+
# puts "GEM_PATH = #{ENV['GEM_PATH']}"
|
803
|
+
|
772
804
|
return true if __FILE__ == $0
|
773
805
|
return false if File.basename(__FILE__) != File.basename($0)
|
774
806
|
|
775
|
-
|
776
|
-
|
807
|
+
# If here, then filespecs are different but have the same basename.
|
808
|
+
gem_paths = ENV['GEM_PATH'].split(File::PATH_SEPARATOR)
|
809
|
+
basename = File.basename($0)
|
810
|
+
gem_paths.any? do |path|
|
811
|
+
path_plus_bin_basename = File.join(path, 'bin', basename)
|
812
|
+
__file__up_4 = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
|
813
|
+
($0 == path_plus_bin_basename) && (path == __file__up_4)
|
814
|
+
end
|
777
815
|
end
|
778
816
|
|
779
817
|
|
data/mac-wifi.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
# This version must be kept in sync with the version in the mac-wifi file.
|
3
|
+
VERSION = '1.1.0'
|
3
4
|
|
4
5
|
Gem::Specification.new do |spec|
|
5
6
|
spec.name = "mac-wifi"
|
@@ -11,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
11
12
|
spec.homepage = "https://github.com/keithrbennett/mac-wifi"
|
12
13
|
spec.license = "MIT"
|
13
14
|
|
14
|
-
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.files = `git ls-files`.split($/)
|
15
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
18
|
spec.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mac-wifi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Bennett
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A command line interface for managing wifi on a Mac.
|
14
14
|
email:
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- Gemfile
|
23
23
|
- LICENSE.txt
|
24
24
|
- README.md
|
25
|
+
- RELEASE_NOTES.md
|
25
26
|
- bin/mac-wifi
|
26
27
|
- mac-wifi.gemspec
|
27
28
|
- spec/mac-wifi_spec.rb
|
@@ -29,7 +30,7 @@ homepage: https://github.com/keithrbennett/mac-wifi
|
|
29
30
|
licenses:
|
30
31
|
- MIT
|
31
32
|
metadata: {}
|
32
|
-
post_install_message:
|
33
|
+
post_install_message:
|
33
34
|
rdoc_options: []
|
34
35
|
require_paths:
|
35
36
|
- lib
|
@@ -44,9 +45,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
47
|
requirements: []
|
47
|
-
rubyforge_project:
|
48
|
+
rubyforge_project:
|
48
49
|
rubygems_version: 2.6.13
|
49
|
-
signing_key:
|
50
|
+
signing_key:
|
50
51
|
specification_version: 4
|
51
52
|
summary: Mac wifi utility
|
52
53
|
test_files:
|