startor 0.6.3 → 0.6.4

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc53f3a56d1a16ab625bc40c3ac78f227a70ae2e211ccff7e362d0c93b9e5184
4
- data.tar.gz: b3e9b991bad3c524fa8ab4bdec2cf4669f4df0f5773a9253f9fc6e4c6c1f6faf
3
+ metadata.gz: 75a30a450379b0c64fbb337d72447828e9f7b7c7c7dd66c040794682ce488480
4
+ data.tar.gz: 5965c6e542207e6af325d3c305eeda9e4f30beea1068f77df39543a114a7cf07
5
5
  SHA512:
6
- metadata.gz: 14ae6ecc7567c1c35f3f64c6eb1e02154d33d809ffe0bf7c9f093349f8beca6ba1c7b6f833585b4f05f9f65fb80ad81d3febc44ff2aecfb188eb42b937290ed1
7
- data.tar.gz: d48241ae5e093866046f7319f0d161b96ada6a3e5bb82eedbbf62346a645bdfd77ac0322bca9172952fc061aac2a3f74dd9e0c81306faaac154f7cdfc8a83168
6
+ metadata.gz: 4d3d3901d349fa82d2cb8efea423814f40d8617e56d9288fb7ee1807a53c170e975c368ed08513f9ba909134f4cae2b37290d9ae493c8c66116391482137af56
7
+ data.tar.gz: 16efcce7c462dcfc34a066ddb6ee799f0b7d1b79c0bf0c22c944ee5ea924d1a73f715f5eedb302f3c62acaa82eae0374e3ed1c4085c118069f57eafde8e6a5d3
@@ -2,7 +2,7 @@
2
2
  # startor
3
3
 
4
4
  # 20190802
5
- # 0.6.3
5
+ # 0.6.4
6
6
 
7
7
  # History: Derived from https://kremalicious.com/simple-tor-setup-on-mac-os-x/...
8
8
 
@@ -52,11 +52,13 @@
52
52
  # 11. ~ install_homebrew() to make use of homebrew_installed?().
53
53
  # 12. ~ install_tor() to make use of tor_installed?(), though this is a bit redundant, since setup() should control whether install_tor() is run anyway.
54
54
  # 13. ~ setup(), so that it doesn't needlessly install brew, because tor is already installed.
55
+ # 3/4
56
+ # 14. /lib\/OSX/lib\/MacOS/
55
57
 
56
58
  require 'FileUtils/which'
57
59
  require 'Kernel/run'
58
- require 'OSX/HardwarePort'
59
- require 'OSX/IfConfig'
60
+ require 'MacOS/HardwarePort'
61
+ require 'MacOS/IfConfig'
60
62
 
61
63
  def install_homebrew
62
64
  if homebrew_installed?
@@ -102,12 +104,12 @@ def enter_admin_password
102
104
  end
103
105
 
104
106
  def active_network_interfaces
105
- OSX::IfConfig.new.active_interfaces
107
+ MacOS::IfConfig.active_interfaces
106
108
  end
107
109
 
108
110
  def active_network_ports
109
111
  active_network_interfaces.collect do |active_network_interface|
110
- if hardware_port = OSX::HardwarePort.find_by_device(active_network_interface)
112
+ if hardware_port = MacOS::HardwarePort.find_by_device(active_network_interface)
111
113
  hardware_port.name
112
114
  end
113
115
  end.compact
@@ -0,0 +1,109 @@
1
+ # MacOS/HardwarePort.rb
2
+ # MacOS::HardwarePort
3
+
4
+ # 20190829
5
+ # 0.3.1
6
+
7
+ # Changes since 0.2:
8
+ # 1. /Hardware/HardwarePort at the top of the file.
9
+ # 2. /new()/initialize()/ (Really!? I did that!? Twice!)
10
+ # 3. ~ MacOS::HardwarePort.parse, so that it only puts in one entry per hardware port.
11
+ # 4. - all()
12
+ # 5. + alias_method :all, :parse
13
+ # 6. + alias_method :hardware_ports, :parse
14
+ # 7. + alias_method :ports, :parse
15
+ # 8. + MacOS::HardwarePort.find_by_name
16
+ # 9. + MacOS::HardwarePort.find_by_ethernet_address
17
+ # 10. + MacOS::HardwarePort#mac_address
18
+ # 0/1
19
+ # 11. /MacOS::HardwarePort.find_by_device/MacOS::HardwarePort.find_by_interface/
20
+ # 11. + alias_method :find_by_device, :find_by_interface
21
+ # 12. + MacOS::HardwarePort#interface
22
+ # 13. + alias_method :find_by_hardware_port, :find_by_name
23
+
24
+ require 'Thoran/String/Captures/captures'
25
+
26
+ module MacOS
27
+ class HardwarePort
28
+
29
+ class << self
30
+
31
+ def parse(output = nil)
32
+ output ||= self.output
33
+ hardware_ports = []
34
+ hardware_port = nil
35
+ output.each_line do |line|
36
+ # p line
37
+ if line == "\n" || line == ""
38
+ hardware_ports << hardware_port if hardware_port
39
+ hardware_port = new
40
+ else
41
+ label, value = line.captures(/^(.+): (.+)/)
42
+ case label
43
+ when 'Hardware Port'; hardware_port.hardware_port = value
44
+ when 'Device'; hardware_port.device = value
45
+ when 'Ethernet Address'; hardware_port.ethernet_address = value
46
+ end
47
+ end
48
+ end
49
+ hardware_ports
50
+ end
51
+ alias_method :all, :parse
52
+ alias_method :hardware_ports, :parse
53
+ alias_method :ports, :parse
54
+
55
+ def find_by_interface(interface)
56
+ all.detect{|hardware_port| hardware_port.interface == interface}
57
+ end
58
+ alias_method :find_by_device, :find_by_interface
59
+
60
+ def find_by_name(name)
61
+ all.detect{|hardware_port| hardware_port.name == name}
62
+ end
63
+ alias_method :find_by_hardware_port, :find_by_name
64
+
65
+ def find_by_mac_address(mac_address)
66
+ all.detect{|hardware_port| hardware_port.ethernet_address == mac_address}
67
+ end
68
+ alias_method :find_by_ethernet_address, :find_by_mac_address
69
+
70
+ private
71
+
72
+ def output
73
+ `networksetup -listallhardwareports`
74
+ end
75
+
76
+ end # class << self
77
+
78
+ attr_accessor :hardware_port
79
+ attr_accessor :device
80
+ attr_accessor :ethernet_address
81
+
82
+ def initialize(hardware_port: nil, device: nil, ethernet_address: nil)
83
+ @hardware_port = hardware_port
84
+ @device = device
85
+ @ethernet_address = ethernet_address
86
+ end
87
+
88
+ def name
89
+ @hardware_port
90
+ end
91
+
92
+ def mac_address
93
+ @ethernet_address
94
+ end
95
+
96
+ def interface
97
+ @device
98
+ end
99
+
100
+ end
101
+ end
102
+
103
+ if __FILE__ == $0
104
+ require 'pp'
105
+ pp MacOS::HardwarePort.all
106
+ p MacOS::HardwarePort.find_by_device('en4')
107
+ p MacOS::HardwarePort.find_by_name('Wi-Fi')
108
+ p MacOS::HardwarePort.find_by_interface('en4')
109
+ end
@@ -0,0 +1,161 @@
1
+ # MacOS/IfConfig.rb
2
+ # MacOS::IfConfig
3
+
4
+ # 20200429
5
+ # 0.6.0
6
+
7
+ # Changes since 0.5:
8
+ # 1. + MacOS::Ifconfig.find_by_interface
9
+ # 2. + MacOS::Ifconfig.find_by_mac_address
10
+ # 3. + MacOS::Ifconfig.find_by_ipv4_address
11
+
12
+ require 'Thoran/String/Capture/capture'
13
+ require 'Thoran/String/Captures/captures'
14
+
15
+ module MacOS
16
+ class IfConfig
17
+
18
+ class << self
19
+
20
+ def parse(output = nil)
21
+ output ||= self.output
22
+ @ifconfigs = []
23
+ interface = nil
24
+ output.each_line do |line|
25
+ if line =~ /^\t/
26
+ case line
27
+ when /ether/
28
+ @ifconfig.mac_address = line.capture(/ *ether (.+) $/)
29
+ when /inet /
30
+ if line.match(/broadcast/)
31
+ @ifconfig.ipv4_address, @ifconfig.netmask, @ifconfig.broadcast_address = line.captures(/ *inet (\d+(?:\.\d+){3}) netmask (.+) broadcast (.+)$/)
32
+ elsif line.match(/-->/)
33
+ ipv4_addresses, @ifconfig.netmask = line.captures(/ *inet (.+) netmask (.+) $/)
34
+ @ifconfig.ipv4_address = ipv4_addresses.split(' --> ').first
35
+ else
36
+ @ifconfig.ipv4_address, @ifconfig.netmask = line.captures(/ *inet (\d+(?:\.\d+){3}) netmask (.+) $/)
37
+ end
38
+ when /status\:/
39
+ @ifconfig.status = line.capture(/ *status: (.+)$/)
40
+ end
41
+ else
42
+ @ifconfigs << @ifconfig if @ifconfig
43
+ @ifconfig = new
44
+ @ifconfig.interface, _rest_of_line = line.captures(/^(.+?): (.+)$/)
45
+ end
46
+ end
47
+ @ifconfigs << @ifconfig
48
+ end
49
+ alias_method :all, :parse
50
+ alias_method :interfaces, :parse
51
+
52
+ def interface_names
53
+ all.collect(&:interface_name)
54
+ end
55
+
56
+ def active_interfaces
57
+ all.select(&:active?)
58
+ end
59
+ alias_method :active, :active_interfaces
60
+
61
+ def active_interfaces_names
62
+ all.select(&:active?).collect(&:interface_name)
63
+ end
64
+
65
+ def inactive_interfaces
66
+ all.select(&:inactive?)
67
+ end
68
+ alias_method :inactive, :inactive_interfaces
69
+
70
+ def inactive_interfaces_names
71
+ all.select(&:inactive?).collect(&:interface_name)
72
+ end
73
+
74
+ def up_interfaces
75
+ all.select(&:up?)
76
+ end
77
+ alias_method :up, :up_interfaces
78
+
79
+ def up_interfaces_names
80
+ all.select(&:up?).collect(&:interface_name)
81
+ end
82
+
83
+ def mac_addresses
84
+ all.collect(&:mac_address).compact
85
+ end
86
+ alias_method :ethernet_addresses, :mac_addresses
87
+
88
+ def ipv4_addresses
89
+ all.collect(&:ipv4_address).compact
90
+ end
91
+
92
+ def find_by_interface(interface)
93
+ all.find{|ifconfig| ifconfig.interface == interface}
94
+ end
95
+
96
+ def find_by_mac_address(mac_address)
97
+ all.find{|ifconfig| ifconfig.mac_address == mac_address}
98
+ end
99
+
100
+ def find_by_ipv4_address(ipv4_address)
101
+ all.find{|ifconfig| ifconfig.ipv4_address == ipv4_address}
102
+ end
103
+
104
+ private
105
+
106
+ def output
107
+ `ifconfig -a`
108
+ end
109
+
110
+ end # class << self
111
+
112
+ attr_accessor :interface
113
+ attr_accessor :mac_address
114
+ attr_accessor :ipv4_address, :netmask, :broadcast_address
115
+ attr_accessor :status
116
+
117
+ def initialize(interface: nil, mac_address: nil, ipv4_address: nil, netmask: nil, broadcast_address:nil, status: nil)
118
+ @interface = interface
119
+ @mac_address = mac_address
120
+ @ipv4_address, @netmask, @broadcast_address = ipv4_address, netmask, broadcast_address
121
+ @status = status
122
+ end
123
+
124
+ def interface_name
125
+ @interface
126
+ end
127
+ alias_method :name, :interface_name
128
+
129
+ def ethernet_address
130
+ @mac_address
131
+ end
132
+
133
+ def active?
134
+ @status == 'active'
135
+ end
136
+
137
+ def inactive?
138
+ @status == 'inactive'
139
+ end
140
+
141
+ def up?
142
+ active? || @ipv4_address
143
+ end
144
+
145
+ end
146
+ end
147
+
148
+ if __FILE__ == $0
149
+ require 'pp'
150
+ pp MacOS::IfConfig.interfaces
151
+ p MacOS::IfConfig.interface_names
152
+ p MacOS::IfConfig.active_interfaces
153
+ p MacOS::IfConfig.active_interfaces_names
154
+ p MacOS::IfConfig.inactive_interfaces
155
+ p MacOS::IfConfig.inactive_interfaces_names
156
+ p MacOS::IfConfig.up_interfaces
157
+ p MacOS::IfConfig.up_interfaces_names
158
+ p MacOS::IfConfig.mac_addresses
159
+ p MacOS::IfConfig.ipv4_addresses
160
+ p MacOS::IfConfig.find_by_interface('en0')
161
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: startor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-02 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily install, start, and stop tor.
14
14
  email: code@thoran.com
@@ -28,9 +28,9 @@ files:
28
28
  - lib/FileUtils/which.rb
29
29
  - lib/Files.rb
30
30
  - lib/Kernel/run.rb
31
+ - lib/MacOS/HardwarePort.rb
32
+ - lib/MacOS/IfConfig.rb
31
33
  - lib/Module/alias_methods.rb
32
- - lib/OSX/HardwarePort.rb
33
- - lib/OSX/IfConfig.rb
34
34
  - lib/Ordinal.rb
35
35
  - lib/Ordinal/Array.rb
36
36
  - lib/Platform/OS.rb
@@ -57,7 +57,7 @@ licenses:
57
57
  metadata:
58
58
  tor_website: https://www.torproject.org
59
59
  tor_check_page: https://check.torproject.org
60
- post_install_message:
60
+ post_install_message:
61
61
  rdoc_options: []
62
62
  require_paths:
63
63
  - lib
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.0.3
76
- signing_key:
75
+ rubygems_version: 3.2.0.rc.1
76
+ signing_key:
77
77
  specification_version: 4
78
78
  summary: tor management made easy.
79
79
  test_files: []
@@ -1,69 +0,0 @@
1
- # OSX/Hardware.rb
2
- # OSX::Hardware
3
-
4
- # 20180209
5
- # 0.1.1
6
-
7
- require 'Thoran/String/Captures/captures'
8
-
9
- module OSX
10
- class HardwarePort
11
-
12
- class << self
13
-
14
- def parse(output)
15
- hardware_ports = []
16
- hardware_port = nil
17
- output.each_line do |line|
18
- if line == "\n" || line == ""
19
- hardware_port = new
20
- else
21
- label, value = line.captures(/^(.+): (.+)/)
22
- case label
23
- when 'Hardware Port'; hardware_port.hardware_port = value
24
- when 'Device'; hardware_port.device = value
25
- when 'Ethernet Address'; hardware_port.ethernet_address = value
26
- end
27
- end
28
- hardware_ports << hardware_port
29
- end
30
- hardware_ports
31
- end
32
-
33
- def all
34
- parse(output)
35
- end
36
-
37
- def find_by_device(device)
38
- all.detect{|hardware_port| hardware_port.device == device}
39
- end
40
-
41
- private
42
-
43
- def output
44
- `networksetup -listallhardwareports`
45
- end
46
-
47
- end # class << self
48
-
49
- attr_accessor :hardware_port
50
- attr_accessor :device
51
- attr_accessor :ethernet_address
52
-
53
- def new(hardware_port:, device:, ethernet_address:)
54
- @hardware_port = hardware_port
55
- @device = device
56
- @ethernet_address = ethernet_address
57
- end
58
-
59
- def name
60
- @hardware_port
61
- end
62
-
63
- end
64
- end
65
-
66
- if __FILE__ == $0
67
- p hardware_ports = OSX::HardwarePort.all
68
- p en4 = OSX::HardwarePort.find_by_device('en4')
69
- end
@@ -1,57 +0,0 @@
1
- # OSX/IfConfig.rb
2
- # OSX::IfConfig
3
-
4
- # 20180209
5
- # 0.2.0
6
-
7
- # Changes since 0.1:
8
- # 1. + OSX namespace, under the assumption that the output of ifconfig on OSX is different from other operating systems.
9
- require 'Thoran/String/Captures/captures'
10
-
11
- module OSX
12
- class IfConfig
13
-
14
- def new(output = nil)
15
- @output = output
16
- end
17
-
18
- def interfaces
19
- parse.keys
20
- end
21
-
22
- def active_interfaces
23
- parse.select do |interface, details|
24
- details.any?{|detail| detail =~ /status: active/}
25
- end.keys
26
- end
27
-
28
- private
29
-
30
- def output
31
- @output || `ifconfig -a`
32
- end
33
-
34
- def parse
35
- interfaces = {}
36
- interface = nil
37
- output.each_line do |line|
38
- if line =~ /^\t/
39
- interfaces[interface] << line.sub(/^\t/, '')
40
- else
41
- interface, rest_of_line = line.captures(/^(.+?): (.+)$/)
42
- interfaces[interface] = [rest_of_line]
43
- end
44
- end
45
- interfaces
46
- end
47
-
48
- end
49
- end
50
-
51
- if __FILE__ == $0
52
- require 'pp'
53
- ic = OSX::IfConfig.new
54
- pp ic.send(:parse)
55
- ic.interfaces
56
- ic.active_interfaces
57
- end