pi_build_modifier 0.3.0.pre.alpha → 0.3.1.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +24 -12
- data/.travis.yml +26 -4
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE +21 -0
- data/README.md +208 -2
- data/Rakefile +134 -6
- data/Vagrantfile +27 -0
- data/docs/concept.md +27 -0
- data/docs/incubation.md +38 -0
- data/pi_build_modifier/.gitignore +12 -0
- data/{.rspec → pi_build_modifier/.rspec} +0 -0
- data/{Gemfile → pi_build_modifier/Gemfile} +0 -0
- data/{LICENSE.txt → pi_build_modifier/LICENSE.txt} +1 -1
- data/pi_build_modifier/README.md +3 -0
- data/pi_build_modifier/Rakefile +13 -0
- data/{bin → pi_build_modifier/bin}/pi_build_modifier +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/boot.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/templates/07-resize-init.diff.erb +0 -0
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/config/logex.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/locale/locale_debconf.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/locale/templates/00-debconf.erb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/erb_mapper.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/mapper.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/pi_modifier.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier_task.rb +10 -3
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/templates/wpa_supplicant.conf.erb +0 -0
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/wifi_network.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/run_modifier.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/ssh.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/templates/ssh.sh.erb +0 -0
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/system/system_type.rb +1 -1
- data/{lib → pi_build_modifier/lib}/pi_build_modifier/version.rb +2 -2
- data/{lib → pi_build_modifier/lib}/pi_build_modifier.rb +4 -1
- data/{pi_build_modifier.gemspec → pi_build_modifier/pi_build_modifier.gemspec} +7 -7
- data/pi_build_modifier/spec/fixtures/config.json +26 -0
- data/pi_build_modifier/spec/pi_build_modifier/boot/boot_spec.rb +103 -0
- data/pi_build_modifier/spec/pi_build_modifier/locale/locale_spec.rb +87 -0
- data/pi_build_modifier/spec/pi_build_modifier/modifier/mapper_spec.rb +105 -0
- data/pi_build_modifier/spec/pi_build_modifier/modifier/modifier_spec.rb +83 -0
- data/pi_build_modifier/spec/pi_build_modifier/modifier_task_spec.rb +63 -0
- data/pi_build_modifier/spec/pi_build_modifier/net-tweaks/wifi_network_spec.rb +91 -0
- data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/run_modifier_spec.rb +74 -0
- data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/ssh_spec.rb +73 -0
- data/pi_build_modifier/spec/pi_build_modifier/system/system_spec.rb +66 -0
- data/pi_build_modifier/spec/pi_build_modifier_spec.rb +73 -0
- data/pi_build_modifier/spec/spec_helper.rb +10 -0
- data/pi_customizer/.rspec +2 -0
- data/pi_customizer/Gemfile +3 -0
- data/pi_customizer/LICENSE +21 -0
- data/pi_customizer/README.md +3 -0
- data/pi_customizer/Rakefile +13 -0
- data/pi_customizer/Vagrantfile +16 -0
- data/pi_customizer/bin/pi_customizer +25 -0
- data/pi_customizer/envs/aws/outputs.tf +3 -0
- data/pi_customizer/envs/aws/pi-build-env.tf +160 -0
- data/pi_customizer/envs/aws/variables.tf +55 -0
- data/pi_customizer/envs/docker/Dockerfile +6 -0
- data/pi_customizer/envs/sh/build-pi-img.sh +28 -0
- data/pi_customizer/lib/pi_customizer/build/builder/build_executor.rb +149 -0
- data/pi_customizer/lib/pi_customizer/build/builder/builder.rb +59 -0
- data/pi_customizer/lib/pi_customizer/build/builder/prepare_start_execute_builder.rb +43 -0
- data/pi_customizer/lib/pi_customizer/build/builder/start_prepare_execute_builder.rb +43 -0
- data/pi_customizer/lib/pi_customizer/build/environment/aws/aws.rb +76 -0
- data/pi_customizer/lib/pi_customizer/build/environment/docker/docker.rb +94 -0
- data/pi_customizer/lib/pi_customizer/build/environment/environment.rb +73 -0
- data/pi_customizer/lib/pi_customizer/build/environment/environment_builder_factory.rb +81 -0
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/templates/Vagrantfile.erb +61 -0
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant.rb +77 -0
- data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant_file.rb +95 -0
- data/pi_customizer/lib/pi_customizer/build/workspace/local_workspace.rb +92 -0
- data/pi_customizer/lib/pi_customizer/build/workspace/remote_workspace.rb +79 -0
- data/pi_customizer/lib/pi_customizer/utils/logex.rb +25 -0
- data/pi_customizer/lib/pi_customizer/version.rb +27 -0
- data/pi_customizer/lib/pi_customizer/write/image_writer.rb +67 -0
- data/pi_customizer/lib/pi_customizer.rb +84 -0
- data/pi_customizer/pi_customizer.gemspec +30 -0
- data/pi_customizer/spec/fixtures/TestVagrantfile +61 -0
- data/pi_customizer/spec/fixtures/image.img +1 -0
- data/pi_customizer/spec/fixtures/image.zip +0 -0
- data/pi_customizer/spec/pi_customizer/builder/build_executor_spec.rb +64 -0
- data/pi_customizer/spec/pi_customizer/environment/aws_spec.rb +57 -0
- data/pi_customizer/spec/pi_customizer/environment/environment_builder_factory_spec.rb +48 -0
- data/pi_customizer/spec/pi_customizer/environment/environment_spec.rb +75 -0
- data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_file_spec.rb +63 -0
- data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_spec.rb +41 -0
- data/pi_customizer/spec/pi_customizer/version_spec.rb +29 -0
- data/pi_customizer/spec/pi_customizer/workspace/local_workspace_spec.rb +74 -0
- data/pi_customizer/spec/pi_customizer/workspace/remote_workspace_spec.rb +51 -0
- data/pi_customizer/spec/pi_customizer/write/image_writer_spec.rb +59 -0
- data/pi_customizer/spec/pi_customizer_spec.rb +93 -0
- data/pi_customizer/spec/spec_helper.rb +10 -0
- data/version.rb +21 -0
- metadata +106 -41
@@ -0,0 +1,81 @@
|
|
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
|
+
require 'pi_customizer/build/environment/environment'
|
22
|
+
require 'pi_customizer/build/environment/aws/aws'
|
23
|
+
require 'pi_customizer/build/environment/vagrant/vagrant'
|
24
|
+
require 'pi_customizer/build/environment/docker/docker'
|
25
|
+
require 'pi_customizer/build/builder/builder'
|
26
|
+
require 'pi_customizer/build/builder/prepare_start_execute_builder'
|
27
|
+
require 'pi_customizer/build/builder/start_prepare_execute_builder'
|
28
|
+
require 'pi_customizer/build/workspace/remote_workspace'
|
29
|
+
require 'pi_customizer/build/workspace/local_workspace'
|
30
|
+
require 'pi_customizer/utils/logex'
|
31
|
+
|
32
|
+
|
33
|
+
module PiCustomizer
|
34
|
+
module Environment
|
35
|
+
|
36
|
+
ENV_AWS = 'AWS'
|
37
|
+
ENV_VAGRANT = 'VAGRANT'
|
38
|
+
ENV_DOCKER = 'DOCKER'
|
39
|
+
ENV_ECHO = 'ECHO'
|
40
|
+
|
41
|
+
##
|
42
|
+
# The builder_factory creates a builder for the selected environment env. The builder orchestrates the environment and the build process in the environment.
|
43
|
+
|
44
|
+
def Environment.builder_factory(env, local_workspace, remote_workspace, skip_build_steps)
|
45
|
+
|
46
|
+
environment = environment_factory(env, local_workspace, remote_workspace)
|
47
|
+
|
48
|
+
case env
|
49
|
+
when ENV_AWS, ENV_VAGRANT
|
50
|
+
env_builder = Builder::PrepareExecuteBuilder.new(environment, skip_build_steps)
|
51
|
+
when ENV_DOCKER, ENV_ECHO
|
52
|
+
puts "Echo: - Git Path: #{remote_workspace.git_path}, Workspace Path: #{remote_workspace.workspace_directory}, Config Path: #{local_workspace.config_path}, #{skip_build_steps}"
|
53
|
+
env_builder = Builder::StartExecuteBuilder.new(environment, skip_build_steps)
|
54
|
+
else
|
55
|
+
$logger.warn 'No valid build environment defined!'
|
56
|
+
env_builder = Builder::PiBuilder.new(environment, skip_build_steps)
|
57
|
+
end
|
58
|
+
env_builder
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# The environment_factory creates an environment configuration tailored to the selected build environment env
|
63
|
+
|
64
|
+
def Environment.environment_factory(env, local_workspace, remote_workspace)
|
65
|
+
case env
|
66
|
+
when ENV_AWS
|
67
|
+
environment = AWS.new(remote_workspace, local_workspace)
|
68
|
+
when ENV_VAGRANT
|
69
|
+
environment = Vagrant.new(remote_workspace, local_workspace)
|
70
|
+
when ENV_DOCKER
|
71
|
+
environment = Docker.new(remote_workspace, local_workspace)
|
72
|
+
when ENV_ECHO
|
73
|
+
environment = EnvironmentControl.new(remote_workspace, local_workspace)
|
74
|
+
else
|
75
|
+
$logger.warn 'No valid environment (e.g., AWS or VAGRANT) defined!'
|
76
|
+
environment = EnvironmentControl.new(remote_workspace, local_workspace)
|
77
|
+
end
|
78
|
+
environment
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
$dependencies = <<SCRIPT
|
5
|
+
sudo apt update
|
6
|
+
sudo apt -y upgrade
|
7
|
+
sudo apt -y install quilt parted qemu-user-static debootstrap zerofree pxz zip dosfstools libcap2-bin bsdtar
|
8
|
+
sudo apt -y install git curl ruby-full build-essential
|
9
|
+
sudo apt -y install wpasupplicant openssl libssl-dev
|
10
|
+
SCRIPT
|
11
|
+
|
12
|
+
$install_modifier_gem = <<SCRIPT
|
13
|
+
# install gem
|
14
|
+
<% if config.modifier_gem_path.nil? %>gem install pi_build_modifier --pre <% else %>gem install /home/ubuntu/pi_build_modifier.gem<% end %>
|
15
|
+
SCRIPT
|
16
|
+
|
17
|
+
$prepare = <<SCRIPT
|
18
|
+
rm -rf <%= workspace.workspace_directory %>
|
19
|
+
mkdir -p <%= workspace.workspace_directory %>
|
20
|
+
echo 'git clone to workspace'
|
21
|
+
git clone --branch <%= workspace.git_tag %> <%= workspace.git_path %> <%= workspace.workspace_directory %>
|
22
|
+
SCRIPT
|
23
|
+
|
24
|
+
$modify = <<SCRIPT
|
25
|
+
# Execute gem with parameters
|
26
|
+
cd <%= workspace.workspace_directory %>
|
27
|
+
pi_build_modifier modify <%= config_file_destination %> <%= workspace.workspace_directory %>
|
28
|
+
sudo ./build.sh
|
29
|
+
mkdir -p <%= workspace.workspace_directory %>/deploy
|
30
|
+
cp -r <%= workspace.workspace_directory %>/deploy /vagrant
|
31
|
+
echo "Pi Image copied to your local workspace <%= config.workspace_directory.to_s %>"
|
32
|
+
SCRIPT
|
33
|
+
|
34
|
+
Vagrant.configure('2') do |config|
|
35
|
+
|
36
|
+
config.vm.box = 'ubuntu/xenial64' #Note, that 'debian/stretch64' cannot be resized with the disksize plugin
|
37
|
+
|
38
|
+
unless Vagrant.has_plugin?("vagrant-disksize")
|
39
|
+
raise 'vagrant-disksize plugin is not installed! Use: vagrant plugin install vagrant-disksize'
|
40
|
+
end
|
41
|
+
|
42
|
+
config.disksize.size = '<%= disk_size %>'
|
43
|
+
|
44
|
+
# Prepare environment by updating the dependencies
|
45
|
+
config.vm.provision 'shell', inline: $dependencies
|
46
|
+
|
47
|
+
<% unless config.modifier_gem_path.nil? %>config.vm.provision 'file', source: '<%= config.modifier_gem_path.to_s %>', destination: '/home/ubuntu/pi_build_modifier.gem' <% end %>
|
48
|
+
|
49
|
+
# Modifier gem is installed
|
50
|
+
config.vm.provision 'shell', inline: $install_modifier_gem
|
51
|
+
|
52
|
+
# Copy config file
|
53
|
+
config.vm.provision 'file', source: '<%= config.config_path.to_s %>', destination: '<%= config_file_destination %>'
|
54
|
+
|
55
|
+
# Prepare the modification
|
56
|
+
config.vm.provision 'shell', inline: $prepare
|
57
|
+
|
58
|
+
# Actually modify the build sources and then build the environment
|
59
|
+
config.vm.provision 'shell', inline: $modify
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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
|
+
require 'fileutils'
|
22
|
+
require 'pi_customizer/build/environment/vagrant/vagrant_file'
|
23
|
+
require 'pi_customizer/build/environment/environment'
|
24
|
+
require 'pi_customizer/utils/logex'
|
25
|
+
|
26
|
+
module PiCustomizer
|
27
|
+
module Environment
|
28
|
+
class Vagrant < EnvironmentControl
|
29
|
+
|
30
|
+
VAGRANT_SOURCE = File.join(File.dirname(__FILE__), '/templates')
|
31
|
+
|
32
|
+
def check
|
33
|
+
$logger.info '[Check] Pre-flight checks are executing...'
|
34
|
+
ensure_vagrant
|
35
|
+
end
|
36
|
+
|
37
|
+
def prepare
|
38
|
+
$logger.info '[Prepare] pi-image in vagrant environment'
|
39
|
+
VagrantFileRenderer.new(VagrantFile.new(@config, @workspace)).create_from_template
|
40
|
+
end
|
41
|
+
|
42
|
+
def start
|
43
|
+
$logger.info '[Start] pi-image in local vagrant environment'
|
44
|
+
Dir.chdir(@config.workspace_directory) do
|
45
|
+
system 'vagrant destroy -f' # cleanup old environment
|
46
|
+
system 'vagrant up --provider=virtualbox --no-provision'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_image
|
51
|
+
$logger.info '[Build] pi-image in local vagrant environment'
|
52
|
+
Dir.chdir(@config.workspace_directory) do
|
53
|
+
system 'vagrant provision'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def clean_up
|
58
|
+
$logger.info '[Clean Up] pi-image in local vagrant environment'
|
59
|
+
end
|
60
|
+
|
61
|
+
def stop
|
62
|
+
$logger.info '[Stop] pi-image in local vagrant environment'
|
63
|
+
Dir.chdir(@config.workspace_directory) do
|
64
|
+
system 'vagrant destroy -f'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def ensure_vagrant
|
69
|
+
unless system 'vagrant -v'
|
70
|
+
raise 'Vagrant not installed. Please ensure that vagrant is installed correctly.'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,95 @@
|
|
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
|
+
require 'erb'
|
22
|
+
require 'fileutils'
|
23
|
+
require 'pi_customizer/build/workspace/remote_workspace'
|
24
|
+
require 'pi_customizer/build/workspace/local_workspace'
|
25
|
+
|
26
|
+
module PiCustomizer
|
27
|
+
module Environment
|
28
|
+
|
29
|
+
##
|
30
|
+
# VagrantFile describes the dynamic attributes of a Vagrantfile which is used to start up the vagrant environment
|
31
|
+
|
32
|
+
class VagrantFile
|
33
|
+
|
34
|
+
attr_accessor :vagrant_template_path, :disk_size, :config_file_destination, :workspace, :config
|
35
|
+
|
36
|
+
def initialize(config, workspace)
|
37
|
+
@vagrant_template_path = File.join(File.dirname(__FILE__), '/templates/Vagrantfile.erb')
|
38
|
+
@disk_size = '60GB'
|
39
|
+
@config_file_destination = '/vagrant/config.json'
|
40
|
+
@config = if config.nil?
|
41
|
+
Workspace::LocalWorkspace.new
|
42
|
+
else
|
43
|
+
config
|
44
|
+
end
|
45
|
+
@workspace = if workspace.nil?
|
46
|
+
Workspace::RemoteWorkspace.new
|
47
|
+
else
|
48
|
+
workspace
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_binding
|
53
|
+
binding
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
class VagrantFileRenderer
|
60
|
+
|
61
|
+
def initialize(vagrant_file)
|
62
|
+
@vagrant_file = vagrant_file
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_from_template
|
66
|
+
check_dependencies
|
67
|
+
read_template
|
68
|
+
write_vagrantfile
|
69
|
+
end
|
70
|
+
|
71
|
+
private def check_dependencies
|
72
|
+
unless File.file?(@vagrant_file.vagrant_template_path.to_s)
|
73
|
+
raise "'Vagrantfile.erb' template not specified. Expected template in path '%s'" % [@vagrant_file.vagrant_template_path]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private def read_template
|
78
|
+
File.open(@vagrant_file.vagrant_template_path.to_s, 'r+') do |f|
|
79
|
+
@template = f.read
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def render
|
84
|
+
ERB.new(@template).result(@vagrant_file.get_binding)
|
85
|
+
end
|
86
|
+
|
87
|
+
private def write_vagrantfile
|
88
|
+
FileUtils.mkdir_p @vagrant_file.config.workspace_directory
|
89
|
+
File.open(@vagrant_file.config.workspace_directory.to_s + '/Vagrantfile', 'w+') do |f|
|
90
|
+
f.write(render)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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
|
+
require 'fileutils'
|
22
|
+
require 'pathname'
|
23
|
+
require 'pi_customizer/utils/logex'
|
24
|
+
|
25
|
+
module PiCustomizer
|
26
|
+
module Workspace
|
27
|
+
|
28
|
+
##
|
29
|
+
# The default path which points to the configuration file
|
30
|
+
|
31
|
+
DEFAULT_CONFIG_PATH = File.join(File.dirname(__FILE__), '/../../../../resources/config.json')
|
32
|
+
|
33
|
+
##
|
34
|
+
# The default directory which is used to store temporary build files, e.g., the Vagrantfile for a build with vagrant
|
35
|
+
|
36
|
+
DEFAULT_LOCAL_WORKSPACE_DIRECTORY = Dir.pwd + '/tmp'
|
37
|
+
|
38
|
+
##
|
39
|
+
# The LocalWorkspace class encapsulates the configuration of the workspace on the machine where the build of the pi image is triggered
|
40
|
+
|
41
|
+
class LocalWorkspace
|
42
|
+
|
43
|
+
attr_reader :config_path, :workspace_directory, :modifier_gem_path
|
44
|
+
|
45
|
+
def initialize(config_path = '', workspace_directory = '', modifier_gem_path = '')
|
46
|
+
self.config_path = config_path
|
47
|
+
self.workspace_directory = workspace_directory
|
48
|
+
self.modifier_gem_path = modifier_gem_path
|
49
|
+
$logger.debug "Local Workspace is at '#{@config_path}' with tmp directory '#{@workspace_directory}' and modifier_gem_path '#{@modifier_gem_path}'"
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Checks for value equality between a pair of LocalWorkspace's attributes
|
54
|
+
|
55
|
+
def ==(other)
|
56
|
+
(@workspace_directory == other.workspace_directory) && (@modifier_gem_path == other.modifier_gem_path) && (@config_path == other.config_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
private def config_path=(config_path)
|
60
|
+
@config_path = if config_path.nil? or config_path == ''
|
61
|
+
Pathname.new(DEFAULT_CONFIG_PATH)
|
62
|
+
else
|
63
|
+
absolute_path_name(config_path)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private def workspace_directory=(workspace_directory)
|
68
|
+
@workspace_directory = if workspace_directory.nil? or workspace_directory == ''
|
69
|
+
Pathname.new(DEFAULT_LOCAL_WORKSPACE_DIRECTORY)
|
70
|
+
else
|
71
|
+
absolute_path_name(workspace_directory)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private def modifier_gem_path=(modifier_gem_path)
|
76
|
+
@modifier_gem_path = if modifier_gem_path.nil? or modifier_gem_path == ''
|
77
|
+
nil
|
78
|
+
else
|
79
|
+
absolute_path_name(modifier_gem_path)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private def absolute_path_name(path)
|
84
|
+
tmp_path = Pathname.new(path)
|
85
|
+
if tmp_path.relative?
|
86
|
+
tmp_path = File.expand_path(path, Dir.pwd)
|
87
|
+
end
|
88
|
+
tmp_path
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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
|
+
require 'fileutils'
|
22
|
+
require 'pi_customizer/utils/logex'
|
23
|
+
|
24
|
+
module PiCustomizer
|
25
|
+
module Workspace
|
26
|
+
|
27
|
+
##
|
28
|
+
# the default directory at the build environment where the build sources are cloned to
|
29
|
+
|
30
|
+
DEFAULT_REMOTE_WORKSPACE_DIRECTORY = '/build/pi-gen'
|
31
|
+
|
32
|
+
##
|
33
|
+
# the default directory for the build sources
|
34
|
+
|
35
|
+
DEFAULT_GIT_PATH = 'https://github.com/ottenwbe/pi-gen.git'
|
36
|
+
|
37
|
+
##
|
38
|
+
# the default directory for the build sources
|
39
|
+
|
40
|
+
DEFAULT_GIT_TAG = 'master'
|
41
|
+
|
42
|
+
##
|
43
|
+
# The RemoteWorkspace class encapsulates the configuration of the workspace in the build environment
|
44
|
+
|
45
|
+
class RemoteWorkspace
|
46
|
+
|
47
|
+
attr_reader :git_path, :workspace_directory, :git_tag
|
48
|
+
|
49
|
+
def initialize(workspace_dir = '', git_path = '', git_tag = '')
|
50
|
+
@workspace_directory = if workspace_dir.nil? or workspace_dir == ''
|
51
|
+
DEFAULT_REMOTE_WORKSPACE_DIRECTORY
|
52
|
+
else
|
53
|
+
workspace_dir.to_s
|
54
|
+
end
|
55
|
+
@git_path = if git_path.nil? or git_path == ''
|
56
|
+
DEFAULT_GIT_PATH
|
57
|
+
else
|
58
|
+
git_path.to_s
|
59
|
+
end
|
60
|
+
@git_tag = if git_tag.nil? or git_tag == ''
|
61
|
+
DEFAULT_GIT_TAG
|
62
|
+
else
|
63
|
+
git_tag.to_s
|
64
|
+
end
|
65
|
+
$logger.debug "Workspace at '#{@workspace_directory}' with sources from '#{@git_path}'"
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Checks for value equality between a pair of RemoteWorkspace's attributes
|
70
|
+
|
71
|
+
def ==(other)
|
72
|
+
(@git_path == other.git_path) && (@workspace_directory == other.workspace_directory) && (@git_tag == other.git_tag)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
@@ -0,0 +1,25 @@
|
|
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
|
+
require 'logger'
|
22
|
+
|
23
|
+
module PiCustomizer
|
24
|
+
$logger = Logger.new(STDOUT)
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
module PiCustomizer
|
22
|
+
|
23
|
+
##
|
24
|
+
# The current version of the pi_customizer gem
|
25
|
+
|
26
|
+
VERSION = '0.3.1.pre.alpha'
|
27
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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
|
+
require 'pi_customizer/utils/logex'
|
22
|
+
|
23
|
+
module PiCustomizer
|
24
|
+
|
25
|
+
##
|
26
|
+
# ImageWriter writes raspberry pi images to devices (e.g., SD cards)
|
27
|
+
|
28
|
+
class ImageWriter
|
29
|
+
|
30
|
+
def initialize()
|
31
|
+
@zip_formats = ['.zip']
|
32
|
+
@img_formats = ['.img']
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# writes zipped (or unzipped) images to a given device
|
37
|
+
|
38
|
+
def write(image, device)
|
39
|
+
dispatch_write(image, device)
|
40
|
+
end
|
41
|
+
|
42
|
+
private def dispatch_write(image, device)
|
43
|
+
extension = File.extname(image)
|
44
|
+
if @zip_formats.include? extension
|
45
|
+
write_zip(image, device)
|
46
|
+
elsif @img_formats.include? extension
|
47
|
+
write_img(image, device)
|
48
|
+
else
|
49
|
+
raise 'No valid image format'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private def write_zip(image, device)
|
54
|
+
run("unzip -p #{image} | dd of=#{device} bs=4M conv=fsync")
|
55
|
+
end
|
56
|
+
|
57
|
+
private def write_img(image, device)
|
58
|
+
run("dd if=#{image} of=#{device} bs=4M conv=fsync")
|
59
|
+
end
|
60
|
+
|
61
|
+
private def run(command)
|
62
|
+
system command
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|