pi_customizer 0.3.0.pre.alpha → 0.3.1.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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +24 -0
  3. data/.travis.yml +28 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/LICENSE +1 -1
  6. data/README.md +208 -2
  7. data/Rakefile +134 -6
  8. data/Vagrantfile +13 -2
  9. data/docs/concept.md +27 -0
  10. data/docs/incubation.md +38 -0
  11. data/pi_build_modifier/.gitignore +12 -0
  12. data/{.rspec → pi_build_modifier/.rspec} +0 -0
  13. data/pi_build_modifier/Gemfile +6 -0
  14. data/pi_build_modifier/LICENSE.txt +21 -0
  15. data/pi_build_modifier/README.md +3 -0
  16. data/pi_build_modifier/Rakefile +13 -0
  17. data/pi_build_modifier/bin/pi_build_modifier +25 -0
  18. data/pi_build_modifier/lib/pi_build_modifier.rb +53 -0
  19. data/pi_build_modifier/lib/pi_build_modifier/boot-files/boot.rb +64 -0
  20. data/pi_build_modifier/lib/pi_build_modifier/boot-files/templates/07-resize-init.diff.erb +5 -0
  21. data/pi_build_modifier/lib/pi_build_modifier/config/logex.rb +25 -0
  22. data/pi_build_modifier/lib/pi_build_modifier/locale/locale_debconf.rb +66 -0
  23. data/pi_build_modifier/lib/pi_build_modifier/locale/templates/00-debconf.erb +6 -0
  24. data/pi_build_modifier/lib/pi_build_modifier/modifier/erb_mapper.rb +72 -0
  25. data/pi_build_modifier/lib/pi_build_modifier/modifier/mapper.rb +49 -0
  26. data/pi_build_modifier/lib/pi_build_modifier/modifier/pi_modifier.rb +81 -0
  27. data/pi_build_modifier/lib/pi_build_modifier/modifier_task.rb +79 -0
  28. data/pi_build_modifier/lib/pi_build_modifier/net-tweaks/templates/wpa_supplicant.conf.erb +5 -0
  29. data/pi_build_modifier/lib/pi_build_modifier/net-tweaks/wifi_network.rb +124 -0
  30. data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/run_modifier.rb +63 -0
  31. data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/ssh.rb +61 -0
  32. data/pi_build_modifier/lib/pi_build_modifier/sys_tweaks/templates/ssh.sh.erb +8 -0
  33. data/pi_build_modifier/lib/pi_build_modifier/system/system_type.rb +84 -0
  34. data/pi_build_modifier/lib/pi_build_modifier/version.rb +23 -0
  35. data/pi_build_modifier/pi_build_modifier.gemspec +32 -0
  36. data/pi_build_modifier/spec/fixtures/config.json +26 -0
  37. data/pi_build_modifier/spec/pi_build_modifier/boot/boot_spec.rb +103 -0
  38. data/pi_build_modifier/spec/pi_build_modifier/locale/locale_spec.rb +87 -0
  39. data/pi_build_modifier/spec/pi_build_modifier/modifier/mapper_spec.rb +105 -0
  40. data/pi_build_modifier/spec/pi_build_modifier/modifier/modifier_spec.rb +83 -0
  41. data/pi_build_modifier/spec/pi_build_modifier/modifier_task_spec.rb +63 -0
  42. data/pi_build_modifier/spec/pi_build_modifier/net-tweaks/wifi_network_spec.rb +91 -0
  43. data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/run_modifier_spec.rb +74 -0
  44. data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/ssh_spec.rb +73 -0
  45. data/pi_build_modifier/spec/pi_build_modifier/system/system_spec.rb +66 -0
  46. data/pi_build_modifier/spec/pi_build_modifier_spec.rb +73 -0
  47. data/pi_build_modifier/spec/spec_helper.rb +10 -0
  48. data/pi_customizer/.rspec +2 -0
  49. data/{Gemfile → pi_customizer/Gemfile} +0 -0
  50. data/pi_customizer/LICENSE +21 -0
  51. data/pi_customizer/README.md +3 -0
  52. data/pi_customizer/Rakefile +13 -0
  53. data/pi_customizer/Vagrantfile +16 -0
  54. data/{bin → pi_customizer/bin}/pi_customizer +1 -1
  55. data/{envs → pi_customizer/envs}/aws/outputs.tf +0 -0
  56. data/{envs → pi_customizer/envs}/aws/pi-build-env.tf +0 -0
  57. data/{envs → pi_customizer/envs}/aws/variables.tf +0 -0
  58. data/{envs → pi_customizer/envs}/docker/Dockerfile +0 -0
  59. data/{envs → pi_customizer/envs}/sh/build-pi-img.sh +0 -0
  60. data/{lib → pi_customizer/lib}/pi_customizer.rb +7 -6
  61. data/{lib → pi_customizer/lib}/pi_customizer/build/builder/build_executor.rb +31 -2
  62. data/{lib → pi_customizer/lib}/pi_customizer/build/builder/builder.rb +4 -2
  63. data/{lib → pi_customizer/lib}/pi_customizer/build/builder/prepare_start_execute_builder.rb +1 -1
  64. data/{lib → pi_customizer/lib}/pi_customizer/build/builder/start_prepare_execute_builder.rb +1 -1
  65. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/aws/aws.rb +1 -1
  66. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/docker/docker.rb +1 -1
  67. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/environment.rb +1 -1
  68. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/environment_builder_factory.rb +9 -3
  69. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/vagrant/templates/Vagrantfile.erb +3 -7
  70. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/vagrant/vagrant.rb +1 -1
  71. data/{lib → pi_customizer/lib}/pi_customizer/build/environment/vagrant/vagrant_file.rb +2 -2
  72. data/{lib → pi_customizer/lib}/pi_customizer/build/workspace/local_workspace.rb +1 -1
  73. data/{lib → pi_customizer/lib}/pi_customizer/build/workspace/remote_workspace.rb +14 -4
  74. data/{lib → pi_customizer/lib}/pi_customizer/utils/logex.rb +1 -1
  75. data/{lib → pi_customizer/lib}/pi_customizer/version.rb +2 -2
  76. data/{lib → pi_customizer/lib}/pi_customizer/write/image_writer.rb +1 -1
  77. data/{pi_customizer.gemspec → pi_customizer/pi_customizer.gemspec} +5 -5
  78. data/pi_customizer/spec/fixtures/TestVagrantfile +61 -0
  79. data/pi_customizer/spec/fixtures/image.img +1 -0
  80. data/pi_customizer/spec/fixtures/image.zip +0 -0
  81. data/pi_customizer/spec/pi_customizer/builder/build_executor_spec.rb +64 -0
  82. data/pi_customizer/spec/pi_customizer/environment/aws_spec.rb +57 -0
  83. data/pi_customizer/spec/pi_customizer/environment/environment_builder_factory_spec.rb +48 -0
  84. data/pi_customizer/spec/pi_customizer/environment/environment_spec.rb +75 -0
  85. data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_file_spec.rb +63 -0
  86. data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_spec.rb +41 -0
  87. data/pi_customizer/spec/pi_customizer/version_spec.rb +29 -0
  88. data/pi_customizer/spec/pi_customizer/workspace/local_workspace_spec.rb +74 -0
  89. data/pi_customizer/spec/pi_customizer/workspace/remote_workspace_spec.rb +51 -0
  90. data/pi_customizer/spec/pi_customizer/write/image_writer_spec.rb +59 -0
  91. data/pi_customizer/spec/pi_customizer_spec.rb +93 -0
  92. data/pi_customizer/spec/spec_helper.rb +10 -0
  93. data/version.rb +21 -0
  94. metadata +102 -41
data/Vagrantfile CHANGED
@@ -1,16 +1,27 @@
1
1
  # -*- mode: ruby -*-
2
2
  # vi: set ft=ruby :
3
3
 
4
+ # Vagrantbox to execute unit tests in a clean environment
5
+
4
6
  Vagrant.configure('2') do |config|
5
7
 
6
8
  config.vm.box = "ubuntu/xenial64"
7
9
 
8
10
  config.vm.provision 'shell', inline: <<-SHELL
9
11
  sudo apt update
12
+ sudo apt -y upgrade
10
13
  sudo apt -y install build-essential ruby-full
11
- gem install bundler
12
- cd /vagrant
14
+
15
+ gem install bundler
16
+
17
+ cd /vagrant/pi_customizer
18
+ bundle install
19
+
20
+ cd /vagrant/pi_build_modifier
13
21
  bundle install
22
+
23
+ cd /vagrant
24
+
14
25
  rake spec
15
26
  SHELL
16
27
  end
data/docs/concept.md ADDED
@@ -0,0 +1,27 @@
1
+ # Concepts
2
+ * The pi_customizer defines and orchestrates an __environment__ to run the build of an RasPi image in (e.g., in a VAGRANT box).
3
+ * To store the configuration for the environment and to define a place for the finished image, pi_customizer defines a __local workspace__.
4
+ * Once the environment is up and running, it hosts a __remote workspace__.
5
+ * The __remote workspace__ comprises all files needed to __modify__ and __build__ a RasPi image
6
+ * The workspace is populated by default from a forked git repo of the official raspbian build tool
7
+
8
+ * __Modification__ steps change files in the remote workspace based on a user defined configuration file
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
@@ -0,0 +1,38 @@
1
+ Potential improvements:
2
+
3
+
4
+ * 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
+ * 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
+ * sudo systemctl disable dphys-swapfile
7
+ * 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
+ * Add users
10
+
11
+ * Change hostname
12
+
13
+ * Install Docker
14
+ * echo deb https://apt.dockerproject.org/repo debian-stretch main > /etc/apt/sources.list.d/docker.list; apt update
15
+ * apt install docker-ce
16
+ * ------------ or:
17
+ apt-get update
18
+ apt-get install \
19
+ apt-transport-https \
20
+ ca-certificates \
21
+ curl \
22
+ gnupg2 \
23
+ software-properties-common
24
+ curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
25
+ echo "deb [arch=armhf] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
26
+ $(lsb_release -cs) stable" | \
27
+ tee /etc/apt/sources.list.d/docker.list
28
+
29
+ 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
+
36
+
37
+
38
+
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /pi_build_modifier/spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
File without changes
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pi_build_modifier.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-2019 Beate Ottenwälder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # pi_build_modifier
2
+
3
+ see https://github.com/ottenwbe/pi-gen-environment
@@ -0,0 +1,13 @@
1
+ lib = File.join(File.dirname(__FILE__), '/lib')
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ begin
5
+ require 'bundler/gem_tasks'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task :default => :spec
11
+ rescue LoadError
12
+ puts 'RSpec or Bundler is not installed. This means rake is not able to execute tests!'
13
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2017-2019 Beate Ottenwälder
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'pi_build_modifier'
24
+
25
+ PiBuildModifier::PiBuildModifier.start(ARGV)
@@ -0,0 +1,53 @@
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 'thor'
22
+ require 'pi_build_modifier/net-tweaks/wifi_network'
23
+ require 'pi_build_modifier/modifier/erb_mapper'
24
+ require 'pi_build_modifier/version'
25
+ require 'pi_build_modifier/modifier_task'
26
+ require 'pi_build_modifier/config/logex'
27
+
28
+ module PiBuildModifier
29
+
30
+ ##
31
+ # PiBuildModifier implements all cli commands of pi_build_modifier.
32
+
33
+ class PiBuildModifier < Thor
34
+
35
+ ##
36
+ # The modify command allows users to modify pi-gen sources in a given workspace based on a given configuration
37
+
38
+ desc 'modify CONFIG WORKSPACE', 'Modify the pi image sources at the specified WORKSPACE with the specified configuration file CONFIG.'
39
+ def modify(config, workspace)
40
+ $logger.debug "Modifying with a configuration read from '#{config}' in the workspace '#{workspace}'"
41
+ task = Task::Modifier.new(config, workspace)
42
+ task.execute
43
+ end
44
+
45
+ ##
46
+ # The version command allows users to query for the current version of the pi_customizer gem. It is printed on the command line.
47
+
48
+ desc 'v, version', 'Show the version of the modifier.'
49
+ def version
50
+ puts VERSION
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,64 @@
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 'json'
23
+
24
+ module PiBuildModifier
25
+
26
+ ##
27
+ # The Locale class is used to customize 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_enable=memory cgroup_memory=1 swapaccount=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-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 PiBuildModifier
24
+ $logger = Logger.new(STDOUT)
25
+ end
@@ -0,0 +1,66 @@
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 'json'
23
+
24
+ module PiBuildModifier
25
+
26
+ ##
27
+ # The Locale class is used to customize the locales
28
+
29
+ class Locale
30
+
31
+ LOCALE = 'locale'
32
+
33
+ GEN = 'gen'
34
+
35
+ SYS = 'sys'
36
+
37
+ attr_accessor :gen_locales, :sys_locales, :template
38
+
39
+ attr_reader :template_path, :relative_output_path
40
+
41
+ def initialize(gen_locales = ['en_GB.UTF-8 UTF-8'], sys_locale = 'en_GB.UTF-8')
42
+ @gen_locales = gen_locales
43
+ @sys_locale = sys_locale
44
+ @template_path = File.join(File.dirname(__FILE__), '/templates/00-debconf.erb').to_s
45
+ @relative_output_path = 'stage0/01-locale/00-debconf'
46
+ end
47
+
48
+ def mapper(workspace)
49
+ ERBMapper.new(self,workspace)
50
+ end
51
+
52
+ def map(json_data)
53
+ unless json_data.nil?
54
+ @gen_locales = json_data[LOCALE][GEN].map {|gen| gen} if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(GEN)
55
+ @sys_locale = json_data[LOCALE][SYS] if json_data.has_key?(LOCALE) && json_data[LOCALE].has_key?(SYS)
56
+ end
57
+ end
58
+
59
+ def get_binding
60
+ binding
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
@@ -0,0 +1,6 @@
1
+ # Locales to be generated:
2
+ # Choices: All locales, aa_DJ ISO-8859-1, aa_DJ.UTF-8 UTF-8, aa_ER UTF-8, aa_ER@saaho UTF-8, aa_ET UTF-8, af_ZA ISO-8859-1, af_ZA.UTF-8 UTF-8, ak_GH UTF-8, am_ET UTF-8, an_ES ISO-8859-15, an_ES.UTF-8 UTF-8, anp_IN UTF-8, ar_AE ISO-8859-6, ar_AE.UTF-8 UTF-8, ar_BH ISO-8859-6, ar_BH.UTF-8 UTF-8, ar_DZ ISO-8859-6, ar_DZ.UTF-8 UTF-8, ar_EG ISO-8859-6, ar_EG.UTF-8 UTF-8, ar_IN UTF-8, ar_IQ ISO-8859-6, ar_IQ.UTF-8 UTF-8, ar_JO ISO-8859-6, ar_JO.UTF-8 UTF-8, ar_KW ISO-8859-6, ar_KW.UTF-8 UTF-8, ar_LB ISO-8859-6, ar_LB.UTF-8 UTF-8, ar_LY ISO-8859-6, ar_LY.UTF-8 UTF-8, ar_MA ISO-8859-6, ar_MA.UTF-8 UTF-8, ar_OM ISO-8859-6, ar_OM.UTF-8 UTF-8, ar_QA ISO-8859-6, ar_QA.UTF-8 UTF-8, ar_SA ISO-8859-6, ar_SA.UTF-8 UTF-8, ar_SD ISO-8859-6, ar_SD.UTF-8 UTF-8, ar_SS UTF-8, ar_SY ISO-8859-6, ar_SY.UTF-8 UTF-8, ar_TN ISO-8859-6, ar_TN.UTF-8 UTF-8, ar_YE ISO-8859-6, ar_YE.UTF-8 UTF-8, as_IN UTF-8, ast_ES ISO-8859-15, ast_ES.UTF-8 UTF-8, ayc_PE UTF-8, az_AZ UTF-8, be_BY CP1251, be_BY.UTF-8 UTF-8, be_BY@latin UTF-8, bem_ZM UTF-8, ber_DZ UTF-8, ber_MA UTF-8, bg_BG CP1251, bg_BG.UTF-8 UTF-8, bho_IN UTF-8, bn_BD UTF-8, bn_IN UTF-8, bo_CN UTF-8, bo_IN UTF-8, br_FR ISO-8859-1, br_FR.UTF-8 UTF-8, br_FR@euro ISO-8859-15, brx_IN UTF-8, bs_BA ISO-8859-2, bs_BA.UTF-8 UTF-8, byn_ER UTF-8, ca_AD ISO-8859-15, ca_AD.UTF-8 UTF-8, ca_ES ISO-8859-1, ca_ES.UTF-8 UTF-8, ca_ES.UTF-8@valencia UTF-8, ca_ES@euro ISO-8859-15, ca_ES@valencia ISO-8859-15, ca_FR ISO-8859-15, ca_FR.UTF-8 UTF-8, ca_IT ISO-8859-15, ca_IT.UTF-8 UTF-8, cmn_TW UTF-8, crh_UA UTF-8, cs_CZ ISO-8859-2, cs_CZ.UTF-8 UTF-8, csb_PL UTF-8, cv_RU UTF-8, cy_GB ISO-8859-14, cy_GB.UTF-8 UTF-8, da_DK ISO-8859-1, da_DK.UTF-8 UTF-8, de_AT ISO-8859-1, de_AT.UTF-8 UTF-8, de_AT@euro ISO-8859-15, de_BE ISO-8859-1, de_BE.UTF-8 UTF-8, de_BE@euro ISO-8859-15, de_CH ISO-8859-1, de_CH.UTF-8 UTF-8, de_DE ISO-8859-1, de_DE.UTF-8 UTF-8, de_DE@euro ISO-8859-15, de_LI.UTF-8 UTF-8, de_LU ISO-8859-1, de_LU.UTF-8 UTF-8, de_LU@euro ISO-8859-15, doi_IN UTF-8, dv_MV UTF-8, dz_BT UTF-8, el_CY ISO-8859-7, el_CY.UTF-8 UTF-8, el_GR ISO-8859-7, el_GR.UTF-8 UTF-8, en_AG UTF-8, en_AU ISO-8859-1, en_AU.UTF-8 UTF-8, en_BW ISO-8859-1, en_BW.UTF-8 UTF-8, en_CA ISO-8859-1, en_CA.UTF-8 UTF-8, en_DK ISO-8859-1, en_DK.ISO-8859-15 ISO-8859-15, en_DK.UTF-8 UTF-8, en_GB ISO-8859-1, en_GB.ISO-8859-15 ISO-8859-15, en_GB.UTF-8 UTF-8, en_HK ISO-8859-1, en_HK.UTF-8 UTF-8, en_IE ISO-8859-1, en_IE.UTF-8 UTF-8, en_IE@euro ISO-8859-15, en_IN UTF-8, en_NG UTF-8, en_NZ ISO-8859-1, en_NZ.UTF-8 UTF-8, en_PH ISO-8859-1, en_PH.UTF-8 UTF-8, en_SG ISO-8859-1, en_SG.UTF-8 UTF-8, en_US ISO-8859-1, en_US.ISO-8859-15 ISO-8859-15, en_US.UTF-8 UTF-8, en_ZA ISO-8859-1, en_ZA.UTF-8 UTF-8, en_ZM UTF-8, en_ZW ISO-8859-1, en_ZW.UTF-8 UTF-8, eo ISO-8859-3, eo.UTF-8 UTF-8, es_AR ISO-8859-1, es_AR.UTF-8 UTF-8, es_BO ISO-8859-1, es_BO.UTF-8 UTF-8, es_CL ISO-8859-1, es_CL.UTF-8 UTF-8, es_CO ISO-8859-1, es_CO.UTF-8 UTF-8, es_CR ISO-8859-1, es_CR.UTF-8 UTF-8, es_CU UTF-8, es_DO ISO-8859-1, es_DO.UTF-8 UTF-8, es_EC ISO-8859-1, es_EC.UTF-8 UTF-8, es_ES ISO-8859-1, es_ES.UTF-8 UTF-8, es_ES@euro ISO-8859-15, es_GT ISO-8859-1, es_GT.UTF-8 UTF-8, es_HN ISO-8859-1, es_HN.UTF-8 UTF-8, es_MX ISO-8859-1, es_MX.UTF-8 UTF-8, es_NI ISO-8859-1, es_NI.UTF-8 UTF-8, es_PA ISO-8859-1, es_PA.UTF-8 UTF-8, es_PE ISO-8859-1, es_PE.UTF-8 UTF-8, es_PR ISO-8859-1, es_PR.UTF-8 UTF-8, es_PY ISO-8859-1, es_PY.UTF-8 UTF-8, es_SV ISO-8859-1, es_SV.UTF-8 UTF-8, es_US ISO-8859-1, es_US.UTF-8 UTF-8, es_UY ISO-8859-1, es_UY.UTF-8 UTF-8, es_VE ISO-8859-1, es_VE.UTF-8 UTF-8, et_EE ISO-8859-1, et_EE.ISO-8859-15 ISO-8859-15, et_EE.UTF-8 UTF-8, eu_ES ISO-8859-1, eu_ES.UTF-8 UTF-8, eu_ES@euro ISO-8859-15, eu_FR ISO-8859-1, eu_FR.UTF-8 UTF-8, eu_FR@euro ISO-8859-15, fa_IR UTF-8, ff_SN UTF-8, fi_FI ISO-8859-1, fi_FI.UTF-8 UTF-8, fi_FI@euro ISO-8859-15, fil_PH UTF-8, fo_FO ISO-8859-1, fo_FO.UTF-8 UTF-8, fr_BE ISO-8859-1, fr_BE.UTF-8 UTF-8, fr_BE@euro ISO-8859-15, fr_CA ISO-8859-1, fr_CA.UTF-8 UTF-8, fr_CH ISO-8859-1, fr_CH.UTF-8 UTF-8, fr_FR ISO-8859-1, fr_FR.UTF-8 UTF-8, fr_FR@euro ISO-8859-15, fr_LU ISO-8859-1, fr_LU.UTF-8 UTF-8, fr_LU@euro ISO-8859-15, fur_IT UTF-8, fy_DE UTF-8, fy_NL UTF-8, ga_IE ISO-8859-1, ga_IE.UTF-8 UTF-8, ga_IE@euro ISO-8859-15, gd_GB ISO-8859-15, gd_GB.UTF-8 UTF-8, gez_ER UTF-8, gez_ER@abegede UTF-8, gez_ET UTF-8, gez_ET@abegede UTF-8, gl_ES ISO-8859-1, gl_ES.UTF-8 UTF-8, gl_ES@euro ISO-8859-15, gu_IN UTF-8, gv_GB ISO-8859-1, gv_GB.UTF-8 UTF-8, ha_NG UTF-8, hak_TW UTF-8, he_IL ISO-8859-8, he_IL.UTF-8 UTF-8, hi_IN UTF-8, hne_IN UTF-8, hr_HR ISO-8859-2, hr_HR.UTF-8 UTF-8, hsb_DE ISO-8859-2, hsb_DE.UTF-8 UTF-8, ht_HT UTF-8, hu_HU ISO-8859-2, hu_HU.UTF-8 UTF-8, hy_AM UTF-8, hy_AM.ARMSCII-8 ARMSCII-8, ia_FR UTF-8, id_ID ISO-8859-1, id_ID.UTF-8 UTF-8, ig_NG UTF-8, ik_CA UTF-8, is_IS ISO-8859-1, is_IS.UTF-8 UTF-8, it_CH ISO-8859-1, it_CH.UTF-8 UTF-8, it_IT ISO-8859-1, it_IT.UTF-8 UTF-8, it_IT@euro ISO-8859-15, iu_CA UTF-8, iw_IL ISO-8859-8, iw_IL.UTF-8 UTF-8, ja_JP.EUC-JP EUC-JP, ja_JP.UTF-8 UTF-8, ka_GE GEORGIAN-PS, ka_GE.UTF-8 UTF-8, kk_KZ PT154, kk_KZ RK1048, kk_KZ.UTF-8 UTF-8, kl_GL ISO-8859-1, kl_GL.UTF-8 UTF-8, km_KH UTF-8, kn_IN UTF-8, ko_KR.EUC-KR EUC-KR, ko_KR.UTF-8 UTF-8, kok_IN UTF-8, ks_IN UTF-8, ks_IN@devanagari UTF-8, ku_TR ISO-8859-9, ku_TR.UTF-8 UTF-8, kw_GB ISO-8859-1, kw_GB.UTF-8 UTF-8, ky_KG UTF-8, lb_LU UTF-8, lg_UG ISO-8859-10, lg_UG.UTF-8 UTF-8, li_BE UTF-8, li_NL UTF-8, lij_IT UTF-8, lo_LA UTF-8, lt_LT ISO-8859-13, lt_LT.UTF-8 UTF-8, lv_LV ISO-8859-13, lv_LV.UTF-8 UTF-8, lzh_TW UTF-8, mag_IN UTF-8, mai_IN UTF-8, mg_MG ISO-8859-15, mg_MG.UTF-8 UTF-8, mhr_RU UTF-8, mi_NZ ISO-8859-13, mi_NZ.UTF-8 UTF-8, mk_MK ISO-8859-5, mk_MK.UTF-8 UTF-8, ml_IN UTF-8, mn_MN UTF-8, mni_IN UTF-8, mr_IN UTF-8, ms_MY ISO-8859-1, ms_MY.UTF-8 UTF-8, mt_MT ISO-8859-3, mt_MT.UTF-8 UTF-8, my_MM UTF-8, nan_TW UTF-8, nan_TW@latin UTF-8, nb_NO ISO-8859-1, nb_NO.UTF-8 UTF-8, nds_DE UTF-8, nds_NL UTF-8, ne_NP UTF-8, nhn_MX UTF-8, niu_NU UTF-8, niu_NZ UTF-8, nl_AW UTF-8, nl_BE ISO-8859-1, nl_BE.UTF-8 UTF-8, nl_BE@euro ISO-8859-15, nl_NL ISO-8859-1, nl_NL.UTF-8 UTF-8, nl_NL@euro ISO-8859-15, nn_NO ISO-8859-1, nn_NO.UTF-8 UTF-8, nr_ZA UTF-8, nso_ZA UTF-8, oc_FR ISO-8859-1, oc_FR.UTF-8 UTF-8, om_ET UTF-8, om_KE ISO-8859-1, om_KE.UTF-8 UTF-8, or_IN UTF-8, os_RU UTF-8, pa_IN UTF-8, pa_PK UTF-8, pap_AN UTF-8, pap_AW UTF-8, pap_CW UTF-8, pl_PL ISO-8859-2, pl_PL.UTF-8 UTF-8, ps_AF UTF-8, pt_BR ISO-8859-1, pt_BR.UTF-8 UTF-8, pt_PT ISO-8859-1, pt_PT.UTF-8 UTF-8, pt_PT@euro ISO-8859-15, quz_PE UTF-8, ro_RO ISO-8859-2, ro_RO.UTF-8 UTF-8, ru_RU ISO-8859-5, ru_RU.CP1251 CP1251, ru_RU.KOI8-R KOI8-R, ru_RU.UTF-8 UTF-8, ru_UA KOI8-U, ru_UA.UTF-8 UTF-8, rw_RW UTF-8, sa_IN UTF-8, sat_IN UTF-8, sc_IT UTF-8, sd_IN UTF-8, sd_IN@devanagari UTF-8, se_NO UTF-8, shs_CA UTF-8, si_LK UTF-8, sid_ET UTF-8, sk_SK ISO-8859-2, sk_SK.UTF-8 UTF-8, sl_SI ISO-8859-2, sl_SI.UTF-8 UTF-8, so_DJ ISO-8859-1, so_DJ.UTF-8 UTF-8, so_ET UTF-8, so_KE ISO-8859-1, so_KE.UTF-8 UTF-8, so_SO ISO-8859-1, so_SO.UTF-8 UTF-8, sq_AL ISO-8859-1, sq_AL.UTF-8 UTF-8, sq_MK UTF-8, sr_ME UTF-8, sr_RS UTF-8, sr_RS@latin UTF-8, ss_ZA UTF-8, st_ZA ISO-8859-1, st_ZA.UTF-8 UTF-8, sv_FI ISO-8859-1, sv_FI.UTF-8 UTF-8, sv_FI@euro ISO-8859-15, sv_SE ISO-8859-1, sv_SE.ISO-8859-15 ISO-8859-15, sv_SE.UTF-8 UTF-8, sw_KE UTF-8, sw_TZ UTF-8, szl_PL UTF-8, ta_IN UTF-8, ta_LK UTF-8, te_IN UTF-8, tg_TJ KOI8-T, tg_TJ.UTF-8 UTF-8, th_TH TIS-620, th_TH.UTF-8 UTF-8, the_NP UTF-8, ti_ER UTF-8, ti_ET UTF-8, tig_ER UTF-8, tk_TM UTF-8, tl_PH ISO-8859-1, tl_PH.UTF-8 UTF-8, tn_ZA UTF-8, tr_CY ISO-8859-9, tr_CY.UTF-8 UTF-8, tr_TR ISO-8859-9, tr_TR.UTF-8 UTF-8, ts_ZA UTF-8, tt_RU UTF-8, tt_RU@iqtelif UTF-8, ug_CN UTF-8, uk_UA KOI8-U, uk_UA.UTF-8 UTF-8, unm_US UTF-8, ur_IN UTF-8, ur_PK UTF-8, uz_UZ ISO-8859-1, uz_UZ.UTF-8 UTF-8, uz_UZ@cyrillic UTF-8, ve_ZA UTF-8, vi_VN UTF-8, wa_BE ISO-8859-1, wa_BE.UTF-8 UTF-8, wa_BE@euro ISO-8859-15, wae_CH UTF-8, wal_ET UTF-8, wo_SN UTF-8, xh_ZA ISO-8859-1, xh_ZA.UTF-8 UTF-8, yi_US CP1255, yi_US.UTF-8 UTF-8, yo_NG UTF-8, yue_HK UTF-8, zh_CN GB2312, zh_CN.GB18030 GB18030, zh_CN.GBK GBK, zh_CN.UTF-8 UTF-8, zh_HK BIG5-HKSCS, zh_HK.UTF-8 UTF-8, zh_SG GB2312, zh_SG.GBK GBK, zh_SG.UTF-8 UTF-8, zh_TW BIG5, zh_TW.EUC-TW EUC-TW, zh_TW.UTF-8 UTF-8, zu_ZA ISO-8859-1, zu_ZA.UTF-8 UTF-8
3
+ locales locales/locales_to_be_generated multiselect <%= @gen_locales.join(', ') %>
4
+ # Default locale for the system environment:
5
+ # Choices: None, C.UTF-8, en_GB.UTF-8
6
+ locales locales/default_environmentg_locale select <%= @sys_locale %>
@@ -0,0 +1,72 @@
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 'json'
22
+ require 'pathname'
23
+ require 'fileutils'
24
+ require 'pi_build_modifier/modifier/mapper'
25
+
26
+ module PiBuildModifier
27
+ class ERBMapper < Mapper
28
+
29
+ def initialize(data, working_dir)
30
+ if data.nil?
31
+ raise 'Cannot initialize ERBMapper, since no valid object for mapping is given.'
32
+ end
33
+ @data = data
34
+ @template_path = @data.template_path
35
+ @output_path = working_dir + '/' + @data.relative_output_path
36
+ end
37
+
38
+ def check(json_data)
39
+ @data.check(json_data)
40
+ end
41
+
42
+ def map(json_data)
43
+ @data.map(json_data)
44
+ end
45
+
46
+ def modify
47
+ read_template
48
+ create_conf
49
+ end
50
+
51
+ private def read_template
52
+ File.open(@template_path.to_s, 'r+') do |f|
53
+ @template = f.read
54
+ end
55
+ end
56
+
57
+ def render
58
+ ERB.new(@template).result(@data.get_binding)
59
+ end
60
+
61
+ private def create_conf
62
+
63
+ puts "create dir at #{@output_path}"
64
+
65
+ FileUtils.mkdir_p File.dirname @output_path
66
+
67
+ File.open(@output_path, 'w+') do |f|
68
+ f.write(render)
69
+ end
70
+ end
71
+ end
72
+ end