pi_customizer 0.4.0.pre.alpha → 0.5.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 +4 -4
- data/.gitignore +0 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +55 -20
- data/Rakefile +6 -5
- data/docs/concept.md +0 -18
- data/docs/incubation.md +3 -14
- data/pi_build_modifier/Gemfile.lock +50 -0
- data/pi_build_modifier/lib/pi_build_modifier.rb +4 -7
- data/pi_build_modifier/lib/pi_build_modifier/modify/configs.rb +335 -0
- data/pi_build_modifier/lib/pi_build_modifier/modify/modifiers.rb +281 -0
- data/pi_build_modifier/lib/pi_build_modifier/{locale → modify}/templates/00-debconf.erb +1 -1
- data/pi_build_modifier/lib/pi_build_modifier/{boot-files → modify}/templates/07-resize-init.diff.erb +1 -1
- data/pi_build_modifier/lib/pi_build_modifier/{net-tweaks → modify}/templates/wpa_supplicant.conf.erb +1 -1
- data/pi_build_modifier/lib/pi_build_modifier/{config → utils}/logex.rb +5 -1
- data/pi_build_modifier/lib/pi_build_modifier/version.rb +1 -1
- data/pi_build_modifier/spec/pi_build_modifier/modify/modify_spec.rb +306 -0
- data/pi_build_modifier/spec/pi_build_modifier_spec.rb +3 -3
- data/pi_build_modifier/spec/spec_helper.rb +1 -0
- data/pi_customizer/Gemfile.lock +47 -0
- data/pi_customizer/lib/pi_customizer.rb +15 -9
- data/pi_customizer/lib/pi_customizer/build/builder/build_executor.rb +12 -24
- data/pi_customizer/lib/pi_customizer/build/builder/builder.rb +17 -13
- data/pi_customizer/{spec/pi_customizer/environment/environment_builder_factory_spec.rb → lib/pi_customizer/build/config/build_config.rb} +27 -18
- data/pi_customizer/lib/pi_customizer/build/{workspace → config}/local_workspace.rb +8 -8
- data/pi_customizer/lib/pi_customizer/build/{workspace → config}/remote_workspace.rb +1 -1
- data/pi_customizer/lib/pi_customizer/build/environment/docker/docker.rb +1 -1
- data/pi_customizer/lib/pi_customizer/build/environment/environment.rb +1 -1
- data/pi_customizer/lib/pi_customizer/build/{builder/start_prepare_execute_builder.rb → environment/environment_factory.rb} +27 -16
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/templates/Vagrantfile.erb +2 -2
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant.rb +3 -8
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant_file.rb +3 -3
- data/pi_customizer/lib/pi_customizer/version.rb +1 -1
- data/pi_customizer/lib/pi_customizer/write/image_writer.rb +3 -2
- data/pi_customizer/spec/pi_customizer/build/builder/builder_spec.rb +122 -0
- data/pi_customizer/spec/pi_customizer/{environment/aws_spec.rb → build/config/build_config_spec.rb} +20 -25
- data/pi_customizer/spec/pi_customizer/{workspace/local_workspace_spec.rb → build/config/local_workspace_config_spec.rb} +10 -10
- data/pi_customizer/spec/pi_customizer/{workspace → build/config}/remote_workspace_spec.rb +2 -2
- data/pi_customizer/spec/pi_customizer/{environment/vagrant/vagrant_spec.rb → build/environment/environment_builder_factory_spec.rb} +17 -13
- data/pi_customizer/spec/pi_customizer/{environment → build/environment}/environment_spec.rb +1 -1
- data/pi_customizer/spec/pi_customizer/{environment → build/environment}/vagrant/vagrant_file_spec.rb +7 -7
- data/pi_customizer/spec/pi_customizer/build/environment/vagrant/vagrant_spec.rb +80 -0
- data/pi_customizer/spec/pi_customizer_spec.rb +19 -14
- data/pi_customizer/spec/spec_helper.rb +21 -0
- data/version.rb +1 -1
- metadata +23 -42
- data/Vagrantfile +0 -27
- data/pi_build_modifier/.gitignore +0 -12
- data/pi_build_modifier/lib/pi_build_modifier/boot-files/boot.rb +0 -64
- data/pi_build_modifier/lib/pi_build_modifier/locale/locale_debconf.rb +0 -66
- data/pi_build_modifier/lib/pi_build_modifier/modifier/erb_mapper.rb +0 -72
- data/pi_build_modifier/lib/pi_build_modifier/modifier/mapper.rb +0 -49
- data/pi_build_modifier/lib/pi_build_modifier/modifier/pi_modifier.rb +0 -81
- data/pi_build_modifier/lib/pi_build_modifier/modifier_task.rb +0 -79
- data/pi_build_modifier/lib/pi_build_modifier/net-tweaks/wifi_network.rb +0 -124
- data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/run_modifier.rb +0 -63
- data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/ssh.rb +0 -61
- data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/templates/ssh.sh.erb +0 -8
- data/pi_build_modifier/lib/pi_build_modifier/system/system_type.rb +0 -84
- data/pi_build_modifier/spec/pi_build_modifier/boot/boot_spec.rb +0 -103
- data/pi_build_modifier/spec/pi_build_modifier/locale/locale_spec.rb +0 -87
- data/pi_build_modifier/spec/pi_build_modifier/modifier/mapper_spec.rb +0 -105
- data/pi_build_modifier/spec/pi_build_modifier/modifier/modifier_spec.rb +0 -83
- data/pi_build_modifier/spec/pi_build_modifier/modifier_task_spec.rb +0 -63
- data/pi_build_modifier/spec/pi_build_modifier/net-tweaks/wifi_network_spec.rb +0 -91
- data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/run_modifier_spec.rb +0 -74
- data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/ssh_spec.rb +0 -73
- data/pi_build_modifier/spec/pi_build_modifier/system/system_spec.rb +0 -66
- data/pi_customizer/lib/pi_customizer/build/builder/prepare_start_execute_builder.rb +0 -43
- data/pi_customizer/lib/pi_customizer/build/environment/aws/aws.rb +0 -76
- data/pi_customizer/lib/pi_customizer/build/environment/environment_builder_factory.rb +0 -81
- data/pi_customizer/spec/pi_customizer/builder/build_executor_spec.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3590f0a62efe485418702779492c5bde407747512c6046e1f0235212d3cecfa4
|
4
|
+
data.tar.gz: b48fd21a511f936bc111fe66207f95c55692afdb3bc7d690714efb81b7d26817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 847bb56ecdac8c8d17210ce31bef76317a489de5e94fec0686aa7eafdf1f01355ec821fcf3bb1bd0e64e290da6b8ed7cf2523456a115031a4bfb27bad8edb917
|
7
|
+
data.tar.gz: 228cde5dd9b4d42974a1af2768e2790712f03a65328a9fc1cfc38c8b614dfc8174a0680ef747b8911a176defe581d656091c0ff8d8707244380455c61fc234df
|
data/.gitignore
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at ottenwbe.public@gmail.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/README.md
CHANGED
@@ -9,30 +9,27 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
The _pi_customizer_ allows you to adapt Raspbian images to your needs.
|
12
|
-
To this end,
|
12
|
+
To this end, an image is built from [scratch](https://github.com/ottenwbe/pi-gen.git)
|
13
13
|
with all customizations baked into the image.
|
14
14
|
|
15
15
|
The image is built in an isolated [build environment](#environments), e.g.,
|
16
16
|
a vagrant box, which is orchestrated by the pi_customizer.
|
17
|
-
The customization is performed by
|
17
|
+
The customization is performed behind the scenes by Ruby scripts (_pi_build_modifier_) in the build environment by adapting the [pi-gen](https://github.com/RPi-Distro/pi-gen) build scripts.
|
18
18
|
|
19
|
-
|
20
|
-
# WIP Notice
|
21
|
-
|
22
|
-
This project is still under construction and in a pre release phase.
|
19
|
+
Finally, pi_customizer also allows you to write the image to an SD card.
|
23
20
|
|
24
21
|
# Install
|
25
22
|
|
26
23
|
## Prerequisites
|
27
24
|
|
28
25
|
To customize the build process the following prerequisites are expected:
|
29
|
-
* The _pi_customizer_ gem is installed (see the [
|
26
|
+
* The _pi_customizer_ gem is installed (see the [__Install Gem__](#deploy_gem) section for details)
|
30
27
|
* One of the supported build environments is accessible (see the [__Environments__](#environments) section):
|
31
28
|
* Vagrant
|
32
29
|
* Docker (feature is still in development)
|
33
30
|
|
34
31
|
<a name="deploy_gem"></a>
|
35
|
-
##
|
32
|
+
## Install Gem
|
36
33
|
|
37
34
|
To customize your Raspbian image the pi_customizer gem must be installed on the machine that coordinates the build process.
|
38
35
|
This is typically your local machine.
|
@@ -81,7 +78,7 @@ Note: feature still in development
|
|
81
78
|
Docker uses a temporary folder as volume to build the image.
|
82
79
|
The folder location can be changed with the build option __tmp-folder__, which is set to "${PWD}/tmp" by default.
|
83
80
|
|
84
|
-
Note: the type of the
|
81
|
+
Note: the type of the workspace directory needs to be changed on SELinux
|
85
82
|
|
86
83
|
chcon -Rt svirt_sandbox_file_t "${PWD}/tmp"
|
87
84
|
|
@@ -98,8 +95,8 @@ To build a default image in a Vagrant box, simply execute on the command line
|
|
98
95
|
|
99
96
|
|
100
97
|
To customize your build:
|
101
|
-
1. All customizations have to be specified in a json configuration file (see the [
|
102
|
-
1. The build process itself is then configured with command line options (see `pi_customizer help build` for details)
|
98
|
+
1. All customizations have to be specified in a json configuration file (see the [Config File](#config_file) section for details).
|
99
|
+
1. The build process itself is then configured with command line options (see `pi_customizer help build` or the [CLI](#cli_options) section for details)
|
103
100
|
|
104
101
|
|
105
102
|
<a name="config_file"></a>
|
@@ -110,7 +107,9 @@ An example of the json config file with all current configuration options
|
|
110
107
|
{
|
111
108
|
"system": {
|
112
109
|
"name" : "custompi",
|
113
|
-
"type" : "lite"
|
110
|
+
"type" : "lite",
|
111
|
+
"username" : "pi",
|
112
|
+
"password" : "raspberry"
|
114
113
|
},
|
115
114
|
"ssh" : {
|
116
115
|
"enabled" : true
|
@@ -139,6 +138,10 @@ An example of the json config file with all current configuration options
|
|
139
138
|
|
140
139
|
* To build a lite version of the pi image, specify the __type__ as lite, otherwise specify it as full. The default is _full_.
|
141
140
|
|
141
|
+
* Select the __username__ for the first user, by default this is __pi__.
|
142
|
+
|
143
|
+
* To change the default __raspberry__ password, specify a __password__.
|
144
|
+
|
142
145
|
### The ssh section
|
143
146
|
|
144
147
|
* To disable ssh by default, set __enabled__ to false.
|
@@ -156,9 +159,39 @@ An example of the json config file with all current configuration options
|
|
156
159
|
|
157
160
|
* The wifi section allows you to specify networks and passphrase __OR__ wpa_passpharse as well as the wpa_country.
|
158
161
|
|
162
|
+
<a name="cli_options"></a>
|
163
|
+
## Command Line Options
|
164
|
+
|
165
|
+
Change the location of the configuration file with ```--config, -c```.
|
166
|
+
|
167
|
+
```
|
168
|
+
pi_customizer -c myconfig.conf
|
169
|
+
```
|
170
|
+
|
171
|
+
Change the git location of the pi-gen build sources with ```--build_sources_git_url -g``` or the used branch/tag ```--build_sources_git_tag, -t```. __NOTE__: Only works with tags from 2019 or later.
|
172
|
+
|
173
|
+
```
|
174
|
+
pi_customizer -g https://github.com/ottenwbe/pi-gen.git -t 2019-06-20-raspbian-buster
|
175
|
+
```
|
176
|
+
|
177
|
+
Change the workspace directory on the local machine with ```--local_workspace_dir, -l```. Environment configuration and built images are stored in the workspace.
|
178
|
+
|
179
|
+
```
|
180
|
+
pi_customizer -l ./workspace
|
181
|
+
```
|
182
|
+
|
159
183
|
# Development
|
160
184
|
|
161
|
-
|
185
|
+
## Why Ruby?
|
186
|
+
|
187
|
+
Well, the author wanted to learn Ruby.
|
188
|
+
|
189
|
+
## Structure
|
190
|
+
|
191
|
+
For now, the sources of both gems (pi_customizer and pi_build_modifier) are versioned in one repository.
|
192
|
+
This might change if their versions run out of sync.
|
193
|
+
|
194
|
+
## Prerequisites
|
162
195
|
|
163
196
|
* Make sure Ruby is installed (and dependencies to build native extensions). See, https://github.com/rbenv/rbenv and https://github.com/rbenv/ruby-build.
|
164
197
|
|
@@ -170,6 +203,7 @@ An example of the json config file with all current configuration options
|
|
170
203
|
|
171
204
|
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
|
172
205
|
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
|
206
|
+
echo 'export PATH="$HOME/.rbenv/shim:$PATH"' >> ~/.zshrc
|
173
207
|
~/.rbenv/bin/rbenv init
|
174
208
|
exec $SHELL
|
175
209
|
|
@@ -181,23 +215,24 @@ An example of the json config file with all current configuration options
|
|
181
215
|
rbenv global 2.5.5
|
182
216
|
```
|
183
217
|
|
184
|
-
|
185
|
-
* Install Gems
|
218
|
+
* Install build dependencies
|
186
219
|
|
187
220
|
```
|
188
221
|
gem install bundler rake rspec rdoc
|
189
222
|
```
|
190
223
|
|
224
|
+
* Install dependencies
|
225
|
+
|
226
|
+
```
|
227
|
+
cd pi_customizer/ && bundle install && cd ..
|
228
|
+
cd pi_build_modifier/ && bundle install && cd ..
|
229
|
+
```
|
230
|
+
|
191
231
|
## Test
|
192
232
|
|
193
233
|
RSpec tests can be executed for all modules by calling the following rake command in the project root.
|
194
234
|
|
195
235
|
rake spec
|
196
|
-
|
197
|
-
## Structure
|
198
|
-
|
199
|
-
For now, the sources of both gems (pi_customizer and pi_build_modifier) are versioned in one repository.
|
200
|
-
This might change if their versions run out of sync.
|
201
236
|
|
202
237
|
## Contributing
|
203
238
|
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ begin
|
|
14
14
|
require 'rspec/core/rake_task'
|
15
15
|
|
16
16
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
17
|
+
|
17
18
|
# find all spec files (for all gems)
|
18
19
|
pattern = ''
|
19
20
|
all_gems.each do |gem|
|
@@ -26,6 +27,7 @@ begin
|
|
26
27
|
# tell rspec to execute tests on all spec files
|
27
28
|
t.pattern = pattern
|
28
29
|
end
|
30
|
+
|
29
31
|
rescue LoadError
|
30
32
|
puts 'RSpec is not installed. This means rake is not able to execute tests! '
|
31
33
|
puts '* Try: gem install rspec'
|
@@ -33,7 +35,6 @@ end
|
|
33
35
|
|
34
36
|
task :default => :spec
|
35
37
|
|
36
|
-
|
37
38
|
# release task
|
38
39
|
|
39
40
|
desc 'Release and upload to Rubygems.org'
|
@@ -64,20 +65,20 @@ end
|
|
64
65
|
desc "Show the gem's versions"
|
65
66
|
task :versions do
|
66
67
|
require_relative "#{PI_CUSTOMIZER}/lib/#{PI_CUSTOMIZER}/version"
|
67
|
-
puts "#{PI_CUSTOMIZER} Versions"
|
68
|
+
puts "#{PI_CUSTOMIZER} Versions"
|
68
69
|
puts ' '
|
69
70
|
puts '*** Dev VERSION ***'
|
70
71
|
puts ' '
|
71
72
|
puts "#{PI_CUSTOMIZER}: #{PiCustomizer::VERSION} "
|
72
|
-
system "gem list #{PI_CUSTOMIZER} --pre --remote"
|
73
|
+
system "gem list #{PI_CUSTOMIZER} --pre --remote"
|
73
74
|
puts ' '
|
74
|
-
require_relative "#{PI_BUILD_MODIFIER}/lib/#{PI_BUILD_MODIFIER}/version"
|
75
|
+
require_relative "#{PI_BUILD_MODIFIER}/lib/#{PI_BUILD_MODIFIER}/version"
|
75
76
|
puts "#{PI_BUILD_MODIFIER} Versions"
|
76
77
|
puts ' '
|
77
78
|
puts '*** Dev VERSION ***'
|
78
79
|
puts ' '
|
79
80
|
puts "#{PI_BUILD_MODIFIER}: #{PiBuildModifier::VERSION}"
|
80
|
-
system "gem list #{PI_BUILD_MODIFIER} --pre --remote"
|
81
|
+
system "gem list #{PI_BUILD_MODIFIER} --pre --remote"
|
81
82
|
end
|
82
83
|
|
83
84
|
# build tasks
|
data/docs/concept.md
CHANGED
@@ -7,21 +7,3 @@
|
|
7
7
|
|
8
8
|
* __Modification__ steps change files in the remote workspace based on a user defined configuration file
|
9
9
|
* __Build__ steps are all executed in the environment
|
10
|
-
|
11
|
-
# Build Steps
|
12
|
-
|
13
|
-
1. Environment creation and selection
|
14
|
-
1. Environment startup
|
15
|
-
1. Workspace creation
|
16
|
-
1. Load sources to workspace
|
17
|
-
1. Load modification sources
|
18
|
-
1. Modify sources in workspace
|
19
|
-
1. Build pi image
|
20
|
-
1. Ship pi image to destination
|
21
|
-
1. Delete Environment
|
22
|
-
|
23
|
-
# Modes
|
24
|
-
1. Prepare and Run - Prepare everything for the environment (e.g., a Vagrantfile) and then simply run the Vagrantfile to build the image
|
25
|
-
1. Example: Vagrant
|
26
|
-
1. Start and Adapt - Start an Environment (e.g., a VM in AWS) and then simply run then configure the environment to build it afterwards
|
27
|
-
1. Examples: Docker
|
data/docs/incubation.md
CHANGED
@@ -1,16 +1,10 @@
|
|
1
|
-
Potential improvements:
|
2
|
-
|
3
|
-
|
4
1
|
* As a builder of a pi image I want to add ssh-keys and bake them into the image (hostkey, admin users public key, ...) to avoid adding it afterwards manually
|
5
2
|
* As a builder of a pi image I want to be able to disable the swap file for my image, e.g., to be able to install kubernetes on it
|
6
3
|
* sudo systemctl disable dphys-swapfile
|
7
4
|
* As a maintainer of the pi image build sources fork I want to be informed if the templates used for the pi_build_modifier are out of date, to avoid inconsistencies
|
8
|
-
|
9
|
-
*
|
10
|
-
|
11
|
-
* Change hostname
|
12
|
-
|
13
|
-
* Install Docker
|
5
|
+
* As a builder of a pi image I want to change the hostname of the pi image
|
6
|
+
* As a build of a pi image I want to install custom software
|
7
|
+
* As a build of a pi image I want to install Docker
|
14
8
|
* echo deb https://apt.dockerproject.org/repo debian-stretch main > /etc/apt/sources.list.d/docker.list; apt update
|
15
9
|
* apt install docker-ce
|
16
10
|
* ------------ or:
|
@@ -27,11 +21,6 @@ Potential improvements:
|
|
27
21
|
tee /etc/apt/sources.list.d/docker.list
|
28
22
|
|
29
23
|
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.09 | head -1 | awk '{print $3}')
|
30
|
-
|
31
|
-
* Install Kubernetes
|
32
|
-
* curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
|
33
|
-
* echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
|
34
|
-
* apt-get update && apt-get install -y kubelet kubeadm kubectl
|
35
24
|
|
36
25
|
|
37
26
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pi_build_modifier (0.5.0.pre.alpha)
|
5
|
+
json (~> 2.2)
|
6
|
+
openssl (~> 2.1)
|
7
|
+
thor (~> 0.20)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.3)
|
13
|
+
docile (1.3.1)
|
14
|
+
json (2.2.0)
|
15
|
+
openssl (2.1.2)
|
16
|
+
rake (12.3.2)
|
17
|
+
rdoc (6.1.1)
|
18
|
+
rspec (3.8.0)
|
19
|
+
rspec-core (~> 3.8.0)
|
20
|
+
rspec-expectations (~> 3.8.0)
|
21
|
+
rspec-mocks (~> 3.8.0)
|
22
|
+
rspec-core (3.8.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-expectations (3.8.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-mocks (3.8.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-support (3.8.0)
|
31
|
+
simplecov (0.16.1)
|
32
|
+
docile (~> 1.1)
|
33
|
+
json (>= 1.8, < 3)
|
34
|
+
simplecov-html (~> 0.10.0)
|
35
|
+
simplecov-html (0.10.2)
|
36
|
+
thor (0.20.3)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (~> 2.0)
|
43
|
+
pi_build_modifier!
|
44
|
+
rake (~> 12.3)
|
45
|
+
rdoc (~> 6.1)
|
46
|
+
rspec (~> 3.8)
|
47
|
+
simplecov (~> 0.16)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.0.2
|
@@ -19,11 +19,9 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'thor'
|
22
|
-
require 'pi_build_modifier/
|
23
|
-
require 'pi_build_modifier/modifier/erb_mapper'
|
22
|
+
require 'pi_build_modifier/modify/modifiers'
|
24
23
|
require 'pi_build_modifier/version'
|
25
|
-
require 'pi_build_modifier/
|
26
|
-
require 'pi_build_modifier/config/logex'
|
24
|
+
require 'pi_build_modifier/utils/logex'
|
27
25
|
|
28
26
|
module PiBuildModifier
|
29
27
|
|
@@ -38,12 +36,11 @@ module PiBuildModifier
|
|
38
36
|
desc 'modify CONFIG WORKSPACE', 'Modify the pi image sources at the specified WORKSPACE with the specified configuration file CONFIG.'
|
39
37
|
def modify(config, workspace)
|
40
38
|
$logger.debug "Modifying with a configuration read from '#{config}' in the workspace '#{workspace}'"
|
41
|
-
|
42
|
-
task.execute
|
39
|
+
Modifiers::ModifiersBuilder::build_defaults(workspace, config).modify_configs
|
43
40
|
end
|
44
41
|
|
45
42
|
##
|
46
|
-
# The version command allows users to query for the current version of the
|
43
|
+
# The version command allows users to query for the current version of the pi_build_modifier gem. It is printed on the command line.
|
47
44
|
|
48
45
|
desc 'v, version', 'Show the version of the modifier.'
|
49
46
|
def version
|
@@ -0,0 +1,335 @@
|
|
1
|
+
# Copyright (c) 2017-2019 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
|
+
##
|
22
|
+
# configs.rb comprises all configurations of the pi-build sources to avoid a require hell
|
23
|
+
|
24
|
+
require 'json'
|
25
|
+
require 'openssl'
|
26
|
+
require 'pi_build_modifier/utils/logex'
|
27
|
+
|
28
|
+
module PiBuildModifier
|
29
|
+
|
30
|
+
######################## Init ########################
|
31
|
+
|
32
|
+
##
|
33
|
+
# Configuration changes of the pi-gen build sources
|
34
|
+
|
35
|
+
module Configs
|
36
|
+
|
37
|
+
def Configs.create_config_modifiers
|
38
|
+
[TypeConfig.new]
|
39
|
+
end
|
40
|
+
|
41
|
+
def Configs.create_erb_modifiers
|
42
|
+
[Locale.new, Boot.new, Wifi.new]
|
43
|
+
end
|
44
|
+
|
45
|
+
def Configs.create_config_file_modifiers
|
46
|
+
[SystemConfig.new, SshConfig.new]
|
47
|
+
end
|
48
|
+
|
49
|
+
######################## Configuration Constants ########################
|
50
|
+
|
51
|
+
SYSTEM = 'system'
|
52
|
+
NAME = 'name'
|
53
|
+
ENABLED = 'enabled'
|
54
|
+
SSH = 'ssh'
|
55
|
+
PASSPHRASE = 'passphrase'
|
56
|
+
WPA_PASSPHRASE = 'wpa_passphrase'
|
57
|
+
SSID = 'ssid'
|
58
|
+
LOCALE = 'locale'
|
59
|
+
GEN = 'gen'
|
60
|
+
SYS = 'sys'
|
61
|
+
CGROUPS = 'cgroups'
|
62
|
+
CGROUP_MEMORY = 'memory'
|
63
|
+
TYPE = 'type'
|
64
|
+
USERNAME = 'username'
|
65
|
+
PASSWORD = 'password'
|
66
|
+
|
67
|
+
######################## Config File Modifiers (ConfigFileModifier) ########################
|
68
|
+
|
69
|
+
|
70
|
+
##
|
71
|
+
# Customization of the pi image's name
|
72
|
+
|
73
|
+
class SystemConfig
|
74
|
+
|
75
|
+
attr_reader :name, :username, :password
|
76
|
+
|
77
|
+
def initialize
|
78
|
+
@name = 'custompi'
|
79
|
+
@username = nil
|
80
|
+
@password = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def map(json_data)
|
84
|
+
unless json_data.nil?
|
85
|
+
@name = json_data[SYSTEM][NAME] if json_data.has_key?(SYSTEM) && json_data[SYSTEM].has_key?(NAME)
|
86
|
+
@username = json_data[SYSTEM][USERNAME] if json_data.has_key?(SYSTEM) && json_data[SYSTEM].has_key?(USERNAME)
|
87
|
+
@password = json_data[SYSTEM][PASSWORD] if json_data.has_key?(SYSTEM) && json_data[SYSTEM].has_key?(PASSWORD)
|
88
|
+
else
|
89
|
+
$logger.error "No json configuration found"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def verify
|
94
|
+
if (!@name.is_a? String) || @name.empty?
|
95
|
+
raise "No valid image name string provided in the config file! E.g., it might be an empty string or not a string at all. Configured image name: '#{@name}'."
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def config_line
|
100
|
+
result = "IMG_NAME='#{@name}'"
|
101
|
+
unless @username.nil?
|
102
|
+
result = "#{result}\nFIRST_USER_NAME=#{@username}"
|
103
|
+
end
|
104
|
+
unless @password.nil?
|
105
|
+
result = "#{result}\nFIRST_USER_PASS=#{@password}"
|
106
|
+
end
|
107
|
+
result
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Enables or Disables SSH by default in the built image
|
114
|
+
|
115
|
+
class SshConfig
|
116
|
+
|
117
|
+
attr_reader :enable
|
118
|
+
|
119
|
+
def initialize
|
120
|
+
@enable = true
|
121
|
+
end
|
122
|
+
|
123
|
+
def map(json_data)
|
124
|
+
unless json_data.nil?
|
125
|
+
@enable = json_data[SSH][ENABLED] if json_data.has_key?(SSH) && json_data[SSH].has_key?(ENABLED)
|
126
|
+
else
|
127
|
+
$logger.error 'Ssh could not be configured: Invalid json data.'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def verify
|
132
|
+
# no verify
|
133
|
+
end
|
134
|
+
|
135
|
+
def config_line
|
136
|
+
if @enable
|
137
|
+
"ENABLE_SSH=1"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
######################## ERB Modifiers (ERBConfigModifier) ########################
|
143
|
+
|
144
|
+
##
|
145
|
+
# Wifi represents the wpa_supplicant's configuration
|
146
|
+
|
147
|
+
class Wifi
|
148
|
+
|
149
|
+
attr_reader :template_path, :relative_output_path
|
150
|
+
|
151
|
+
def initialize
|
152
|
+
@networks = map_network(nil)
|
153
|
+
@wpa_country = 'DE'
|
154
|
+
@template_path = File.join(File.dirname(__FILE__), '/templates/wpa_supplicant.conf.erb').to_s
|
155
|
+
@relative_output_path = 'stage2/02-net-tweaks/files/wpa_supplicant.conf'
|
156
|
+
end
|
157
|
+
|
158
|
+
##
|
159
|
+
# map the 'wifi' section in the json configuration to the instance variables.
|
160
|
+
|
161
|
+
def map(json_data)
|
162
|
+
unless json_data.nil?
|
163
|
+
@networks = map_network(json_data['wifi']) if json_data.has_key?('wifi')
|
164
|
+
@wpa_country = json_data['wifi']['wpa_country'] if json_data.has_key?('wifi') && json_data['wifi'].has_key?('wpa_country')
|
165
|
+
else
|
166
|
+
$logger.warn("Could not map wifi config due to missing Json")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
private def map_network(json_data)
|
171
|
+
if json_data.nil? or not json_data.has_key?('networks')
|
172
|
+
networks = Array.new(0)
|
173
|
+
else
|
174
|
+
networks = json_data['networks'].map do |rd|
|
175
|
+
ssid = if rd.has_key?(SSID)
|
176
|
+
rd[SSID]
|
177
|
+
else
|
178
|
+
'no_ssid'
|
179
|
+
end
|
180
|
+
psk = if rd.has_key?(PASSPHRASE)
|
181
|
+
OpenSSL::PKCS5.pbkdf2_hmac_sha1(rd[PASSPHRASE], ssid, 4096, 32).unpack("H*").first
|
182
|
+
elsif rd.has_key?(WPA_PASSPHRASE)
|
183
|
+
rd[WPA_PASSPHRASE]
|
184
|
+
else
|
185
|
+
'no_psk'
|
186
|
+
end
|
187
|
+
WifiNetwork.new(ssid, psk)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
networks
|
191
|
+
end
|
192
|
+
|
193
|
+
def verify
|
194
|
+
# no verify
|
195
|
+
end
|
196
|
+
|
197
|
+
def get_binding
|
198
|
+
binding
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
##
|
204
|
+
# Customization of the locales
|
205
|
+
|
206
|
+
class Locale
|
207
|
+
|
208
|
+
attr_accessor :gen_locales, :sys_locales
|
209
|
+
|
210
|
+
attr_reader :template_path, :relative_output_path
|
211
|
+
|
212
|
+
def initialize(gen_locales = ['en_GB.UTF-8 UTF-8'], sys_locale = 'en_GB.UTF-8')
|
213
|
+
@gen_locales = gen_locales
|
214
|
+
@sys_locale = sys_locale
|
215
|
+
@template_path = File.join(File.dirname(__FILE__), '/templates/00-debconf.erb').to_s
|
216
|
+
@relative_output_path = 'stage0/01-locale/00-debconf'
|
217
|
+
end
|
218
|
+
|
219
|
+
def map(json_data)
|
220
|
+
unless json_data.nil?
|
221
|
+
@gen_locales = json_data[LOCALE][GEN].map {|gen| gen} if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(GEN)
|
222
|
+
@sys_locale = json_data[LOCALE][SYS] if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(SYS)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def verify
|
227
|
+
# no verify
|
228
|
+
end
|
229
|
+
|
230
|
+
def get_binding
|
231
|
+
binding
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
##
|
237
|
+
# Enable cgroups during boot
|
238
|
+
|
239
|
+
class Boot
|
240
|
+
|
241
|
+
attr_accessor :cgroups
|
242
|
+
|
243
|
+
attr_reader :template_path, :relative_output_path
|
244
|
+
|
245
|
+
def initialize(cgroups = [''])
|
246
|
+
@cgroups = cgroups
|
247
|
+
@template_path = File.join(File.dirname(__FILE__), '/templates/07-resize-init.diff.erb').to_s
|
248
|
+
@relative_output_path = 'stage2/01-sys-tweaks/00-patches/07-resize-init.diff'
|
249
|
+
end
|
250
|
+
|
251
|
+
def map(json_data)
|
252
|
+
unless json_data.nil? || !json_data.has_key?(CGROUPS)
|
253
|
+
if json_data[CGROUPS].has_key?(CGROUP_MEMORY) && json_data[CGROUPS][CGROUP_MEMORY]
|
254
|
+
@cgroups << 'cgroup_enable=memory cgroup_memory=1 swapaccount=1'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def verify
|
260
|
+
# no verify
|
261
|
+
end
|
262
|
+
|
263
|
+
def get_binding
|
264
|
+
binding
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
######################## Config Modifiers (ConfigModifier) ########################
|
270
|
+
|
271
|
+
module Type
|
272
|
+
FULL = 'full'
|
273
|
+
LITE = 'lite'
|
274
|
+
end
|
275
|
+
|
276
|
+
class TypeConfig
|
277
|
+
|
278
|
+
def initialize
|
279
|
+
@type = Type::FULL
|
280
|
+
end
|
281
|
+
|
282
|
+
def map(json_data)
|
283
|
+
unless json_data.nil?
|
284
|
+
@type = json_data[SYSTEM][TYPE] if json_data.has_key?(SYSTEM) && json_data[SYSTEM].has_key?(TYPE)
|
285
|
+
else
|
286
|
+
$logger.error "No json configuration found"
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def verify
|
291
|
+
unless (@type == Type::FULL) || (@type == Type::LITE)
|
292
|
+
raise "Invalid type '#{@type}' specified. Must be in (#{Type::LITE}, #{Type::FULL}.)"
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def modify(workspace)
|
297
|
+
if @type.nil? || @type == Type::LITE
|
298
|
+
make_lite(workspace)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
private def make_lite(workspace)
|
303
|
+
%W(#{workspace}/stage3/SKIP #{workspace}/stage4/SKIP #{workspace}/stage5/SKIP).each do |skip_file|
|
304
|
+
FileUtils.mkdir_p File.dirname(skip_file)
|
305
|
+
FileUtils.touch skip_file
|
306
|
+
end
|
307
|
+
%W(#{workspace}/stage4/EXPORT* #{workspace}/stage5/EXPORT*).each do |export_file|
|
308
|
+
FileUtils.rm_f export_file if File.exist?(export_file)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
######################## Helper ########################
|
314
|
+
|
315
|
+
##
|
316
|
+
# WifiNetwork represents the network section of the wpa_supplicant's configuration
|
317
|
+
|
318
|
+
class WifiNetwork
|
319
|
+
attr_reader :ssid, :psk
|
320
|
+
|
321
|
+
def initialize(ssid, psk)
|
322
|
+
@ssid = ssid
|
323
|
+
@psk = psk
|
324
|
+
end
|
325
|
+
|
326
|
+
def to_s
|
327
|
+
sprintf('{
|
328
|
+
ssid="%s"
|
329
|
+
psk=%s
|
330
|
+
}', ssid, psk)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
end
|