pi_build_modifier 0.1.4.pre.alpha → 0.2.0.pre.alpha

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
  SHA1:
3
- metadata.gz: 7959456c61cee37a94e4ac44e5bc09ffc8920aa2
4
- data.tar.gz: f8d6630ddbbcf9009b07f1034558e1acaee3a52c
3
+ metadata.gz: 2166dffe358e62ffec35a50e83528f06ac2c543b
4
+ data.tar.gz: 737ac930c588b69ab8baf430837022370274db13
5
5
  SHA512:
6
- metadata.gz: 47be6299a1afafd6ecf032129bb161bdaf3b070b74a0137f40f83b92bff537da9bd2ba3a969262d4583f10cd1fb0e7cf17f2a1afb8565abacea6f23f4494e956
7
- data.tar.gz: '088072bcc25419d962fc76db7c54e3e305aa7bd544c228c12281d1b8513fda34fb2a734ae036ca20b7d24a3c61ca00a1e46b88c50f35a2a9792c87679de5b0c3'
6
+ metadata.gz: 055c01e36cdb9ae6473cd5598567470d034541115f1a8ed8be207fa7ef284cfaabcefbeff7e2fd639adccf1af5a640a6cc45c802a4d57cd68d32fbecc4b2527d
7
+ data.tar.gz: 4705763b3e1c33c7b0397a088316c59f99e48933628b99f4bc18b354b9d342522da96e75beea63cae959bfbde93a78063579691d56429f106bd3e0b3d80b6163
@@ -23,17 +23,23 @@ require 'pi_build_modifier/net-tweaks/wifi_network'
23
23
  require 'pi_build_modifier/modifier/erb_mapper'
24
24
  require 'pi_build_modifier/version'
25
25
  require 'pi_build_modifier/modifier_task'
26
+ require 'pi_build_modifier/config/logex'
26
27
 
27
28
  module PiBuildModifier
29
+
30
+ ##
31
+ # PiBuildModifier implements all cli commands of pi_build_modifier.
32
+
28
33
  class PiBuildModifier < Thor
29
34
 
30
- desc 'modify CONFIG WORKSPACE', 'Modify the pi image sources at the specified WORKSPACE with the specified configuration file.'
35
+ desc 'modify CONFIG WORKSPACE', 'Modify the pi image sources at the specified WORKSPACE with the specified configuration file CONFIG.'
31
36
  def modify(config, workspace)
37
+ $logger.debug "modify #{config} #{workspace}"
32
38
  task = Task::Modifier.new(config, workspace)
33
39
  task.execute
34
40
  end
35
41
 
36
- desc 'version', 'Show the version of the modifier.'
42
+ desc 'v, version', 'Show the version of the modifier.'
37
43
  def version
38
44
  puts VERSION
39
45
  end
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2017 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'erb'
22
+ require 'json'
23
+
24
+ module PiBuildModifier
25
+
26
+ ##
27
+ # The Locale class is used to customize the locales
28
+
29
+ class Boot
30
+
31
+ C_GROUPS = 'cgroups'
32
+
33
+ C_GROUP_MEMORY = 'memory'
34
+
35
+ attr_accessor :c_groups
36
+
37
+ attr_reader :template_path, :relative_output_path
38
+
39
+ def initialize(c_groups = [''])
40
+ @c_groups = c_groups
41
+ @template_path = File.join(File.dirname(__FILE__), '/templates/07-resize-init.diff.erb').to_s
42
+ @relative_output_path = 'stage2/01-sys-tweaks/00-patches/07-resize-init.diff'
43
+ end
44
+
45
+ def mapper(workspace)
46
+ ERBMapper.new(self,workspace)
47
+ end
48
+
49
+ def map(json_data)
50
+ unless json_data.nil? || !json_data.has_key?(C_GROUPS)
51
+ if json_data[C_GROUPS].has_key?(C_GROUP_MEMORY) && json_data[C_GROUPS][C_GROUP_MEMORY]
52
+ @c_groups << 'cgroup_memory=1'
53
+ end
54
+ end
55
+ end
56
+
57
+ def get_binding
58
+ binding
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,5 @@
1
+ --- a/rootfs/boot/cmdline.txt
2
+ +++ b/rootfs/boot/cmdline.txt
3
+ @@ -1 +1 @@
4
+ -dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
5
+ +dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 <%= @c_groups.join(' ') %> elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2017 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'logger'
22
+
23
+ module PiBuildModifier
24
+ $logger = Logger.new(STDOUT)
25
+ end
@@ -22,6 +22,10 @@ require 'erb'
22
22
  require 'json'
23
23
 
24
24
  module PiBuildModifier
25
+
26
+ ##
27
+ # The Locale class is used to customize the locales
28
+
25
29
  class Locale
26
30
 
27
31
  LOCALE = 'locale'
@@ -41,9 +45,13 @@ module PiBuildModifier
41
45
  @relative_output_path = 'stage0/01-locale/00-debconf'
42
46
  end
43
47
 
48
+ def mapper(workspace)
49
+ ERBMapper.new(self,workspace)
50
+ end
51
+
44
52
  def map(json_data)
45
53
  unless json_data.nil?
46
- @gen_locales = json_data[LOCALE][GEN].map {|rd| rd} if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(GEN)
54
+ @gen_locales = json_data[LOCALE][GEN].map {|gen| gen} if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(GEN)
47
55
  @sys_locale = json_data[LOCALE][SYS] if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(SYS)
48
56
  end
49
57
  end
@@ -37,7 +37,7 @@ module PiBuildModifier
37
37
  end
38
38
 
39
39
  def modify
40
- @data.map unless @data.nil?
40
+ @data.modify unless @data.nil?
41
41
  end
42
42
 
43
43
  end
@@ -45,8 +45,8 @@ module PiBuildModifier
45
45
 
46
46
  def modify
47
47
  load_config
48
- map
49
- modify_mapper
48
+ map_all
49
+ modify_all
50
50
  end
51
51
 
52
52
  private def load_config
@@ -59,13 +59,13 @@ module PiBuildModifier
59
59
  end
60
60
  end
61
61
 
62
- private def map
62
+ private def map_all
63
63
  @mappers.each do |c|
64
64
  c.map(@json_data)
65
65
  end
66
66
  end
67
67
 
68
- private def modify_mapper
68
+ private def modify_all
69
69
  @mappers.each do |c|
70
70
  c.modify
71
71
  end
@@ -24,6 +24,8 @@ require 'pi_build_modifier/net-tweaks/wifi_network'
24
24
  require 'pi_build_modifier/system/system_type'
25
25
  require 'pi_build_modifier/sys_tweaks/run_modifier'
26
26
  require 'pi_build_modifier/sys_tweaks/ssh'
27
+ require 'pi_build_modifier/locale/locale_debconf'
28
+ require 'pi_build_modifier/boot-files/boot'
27
29
 
28
30
  module PiBuildModifier
29
31
  module Task
@@ -32,13 +34,28 @@ module PiBuildModifier
32
34
  attr_reader :pi_modifier
33
35
 
34
36
  def initialize(config, workspace, pi_modifier = PiModifier.new)
37
+ @mappers = create_mappers
38
+ @mappers[:run_modifier].append(@mappers[:ssh]) #TODO: This connection has to be established somewhere else
35
39
  @pi_modifier = pi_modifier
36
- @pi_modifier.with_json_configuration(config)
40
+ configure_pi_modifier(config, workspace)
41
+ end
37
42
 
38
- @pi_modifier.with_mapper(ERBMapper.new(WPASupplicant.new, workspace))
39
- @pi_modifier.with_mapper(System.new.mapper(workspace))
40
- @pi_modifier.with_mapper(Ssh.new.mapper(workspace))
41
- @pi_modifier.with_mapper(RunModifier.new.mapper(workspace))
43
+ private def create_mappers
44
+ {
45
+ :wpa_supplicant => WPASupplicant.new,
46
+ :system => System.new,
47
+ :ssh => Ssh.new,
48
+ :run_modifier => RunModifier.new,
49
+ :locale => Locale.new,
50
+ :boot => Boot.new
51
+ }
52
+ end
53
+
54
+ private def configure_pi_modifier(config, workspace)
55
+ @pi_modifier.with_json_configuration(config)
56
+ @mappers.each do |*, mapper_data|
57
+ @pi_modifier.with_mapper(mapper_data.mapper(workspace))
58
+ end
42
59
  end
43
60
 
44
61
  def execute
@@ -20,15 +20,19 @@
20
20
 
21
21
  require 'erb'
22
22
  require 'json'
23
+ require 'openssl'
24
+ require 'pi_build_modifier/modifier/erb_mapper'
23
25
 
24
26
  module PiBuildModifier
25
- class WifiNetwork
26
27
 
27
- attr_accessor :ssid, :psk, :template
28
+ ##
29
+ # WifiNetwork represents a network in the wpa_supplicant configuration
30
+
31
+ class WifiNetwork
28
32
 
29
- attr_reader :file
33
+ attr_reader :ssid, :psk
30
34
 
31
- def initialize(ssid = 'no_ssid', psk = 'no_psk')
35
+ def initialize(ssid, psk)
32
36
  @ssid = ssid
33
37
  @psk = psk
34
38
  end
@@ -36,29 +40,65 @@ module PiBuildModifier
36
40
  def to_s
37
41
  sprintf('{
38
42
  ssid="%s"
39
- psk="%s"
43
+ psk=%s
40
44
  }', ssid, psk)
41
45
  end
42
46
  end
43
47
 
48
+ ##
49
+ # WPASupplicant represents the wpa_supplicant's configuration
50
+
44
51
  class WPASupplicant
45
52
 
53
+ PASSKEY = 'passphrase'
54
+
55
+ WPA_PASSKEY = 'wpa_passphrase'
56
+
57
+ SSID = 'ssid'
58
+
46
59
  attr_reader :template_path, :relative_output_path
47
60
 
48
- def initialize(networks = Array.new(0), wpa_country = 'DE')
49
- @networks = networks
50
- @wpa_country = wpa_country
61
+ def initialize
62
+ @networks = map_network(nil)
63
+ @wpa_country = 'DE'
51
64
  @template_path = File.join(File.dirname(__FILE__), '/templates/wpa_supplicant.conf.erb').to_s
52
65
  @relative_output_path = 'stage2/02-net-tweaks/files/wpa_supplicant.conf'
53
66
  end
54
67
 
68
+ def mapper(workspace)
69
+ ERBMapper.new(self, workspace)
70
+ end
71
+
55
72
  def map(json_data)
56
73
  unless json_data.nil?
57
- @networks = json_data['wifi']['networks'].map {|rd| WifiNetwork.new(rd['ssid'], rd['wpsk'])} if json_data.has_key?('wifi') && json_data['wifi'].has_key?('networks')
74
+ @networks = map_network(json_data['wifi']) if json_data.has_key?('wifi')
58
75
  @wpa_country = json_data['wifi']['wpa_country'] if json_data.has_key?('wifi') && json_data['wifi'].has_key?('wpa_country')
59
76
  end
60
77
  end
61
78
 
79
+ private def map_network(json_data)
80
+ if json_data.nil?
81
+ networks = Array.new(0)
82
+ else
83
+ networks = json_data['networks'].map do |rd|
84
+ ssid = if rd.has_key?(SSID)
85
+ rd[SSID]
86
+ else
87
+ 'no_ssid'
88
+ end
89
+ psk = if rd.has_key?(PASSKEY)
90
+ OpenSSL::PKCS5.pbkdf2_hmac_sha1(rd[PASSKEY], ssid, 4096, 32).unpack("H*").first
91
+ elsif rd.has_key?(WPA_PASSKEY)
92
+ rd[WPA_PASSKEY]
93
+ else
94
+ 'no_psk'
95
+ end
96
+ WifiNetwork.new(ssid, psk)
97
+ end
98
+ end
99
+ networks
100
+ end
101
+
62
102
  def get_binding
63
103
  binding
64
104
  end
@@ -46,9 +46,6 @@ module PiBuildModifier
46
46
  @appender << appender
47
47
  end
48
48
 
49
- def map(json_data)
50
- end
51
-
52
49
  def modify
53
50
  open("#{@workspace}/#{@relative_output_path}", 'a') do |f|
54
51
  f.puts ''
@@ -21,6 +21,7 @@
21
21
  require 'fileutils'
22
22
  require 'pi_build_modifier/modifier/mapper'
23
23
  require 'pi_build_modifier/sys_tweaks/run_modifier'
24
+ require 'pi_build_modifier/config/logex'
24
25
 
25
26
  module PiBuildModifier
26
27
 
@@ -48,7 +49,7 @@ module PiBuildModifier
48
49
  unless json_data.nil?
49
50
  @enable = 'disable' if json_data.has_key?('ssh') && json_data['ssh'].has_key?('enabled') && (not json_data['ssh']['enabled'])
50
51
  else
51
- # TODO: log error
52
+ $logger.error 'Invalid json data.'
52
53
  end
53
54
  end
54
55
 
@@ -19,5 +19,5 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  module PiBuildModifier
22
- VERSION = '0.1.4-alpha'
22
+ VERSION = '0.2.0-alpha'
23
23
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
19
  f.match(%r{^(test|spec|features)/})
20
20
  end
21
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f)}
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.15'
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'rdoc', '~> 5.1'
29
29
  spec.add_runtime_dependency 'thor', '~> 0.20'
30
30
  spec.add_runtime_dependency 'json', '~> 2.1'
31
+ spec.add_runtime_dependency 'openssl', '~> 2.0'
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pi_build_modifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.pre.alpha
4
+ version: 0.2.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beate Ottenwälder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-14 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: openssl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
111
125
  description: Modifies the build process of a Raspbian image.
112
126
  email: ottenwbe.public@gmail.com
113
127
  executables:
@@ -124,6 +138,9 @@ files:
124
138
  - Rakefile
125
139
  - bin/pi_build_modifier
126
140
  - lib/pi_build_modifier.rb
141
+ - lib/pi_build_modifier/boot-files/boot.rb
142
+ - lib/pi_build_modifier/boot-files/templates/07-resize-init.diff.erb
143
+ - lib/pi_build_modifier/config/logex.rb
127
144
  - lib/pi_build_modifier/locale/locale_debconf.rb
128
145
  - lib/pi_build_modifier/locale/templates/00-debconf.erb
129
146
  - lib/pi_build_modifier/modifier/erb_mapper.rb