PackerFiles 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/PackerFiles.gemspec +36 -0
- data/README.md +32 -0
- data/Rakefile +21 -0
- data/bin/pkf +5 -0
- data/lib/PackerFiles/CLI/OS.rb +44 -0
- data/lib/PackerFiles/CLI/Root.rb +41 -0
- data/lib/PackerFiles/Core/Base.rb +23 -0
- data/lib/PackerFiles/Core/CDImage.rb +185 -0
- data/lib/PackerFiles/Core/Disk.rb +135 -0
- data/lib/PackerFiles/Core/Exceptions.rb +65 -0
- data/lib/PackerFiles/Core/Hypervisor.rb +96 -0
- data/lib/PackerFiles/Core/Keyboard.rb +38 -0
- data/lib/PackerFiles/Core/Locale.rb +62 -0
- data/lib/PackerFiles/Core/LogicalVolume.rb +41 -0
- data/lib/PackerFiles/Core/Network.rb +67 -0
- data/lib/PackerFiles/Core/Packages.rb +30 -0
- data/lib/PackerFiles/Core/Partition.rb +41 -0
- data/lib/PackerFiles/Core/TimeZone.rb +45 -0
- data/lib/PackerFiles/Core/User.rb +46 -0
- data/lib/PackerFiles/Core/VolumeGroup.rb +50 -0
- data/lib/PackerFiles/Core/example/CDImage.txt +75 -0
- data/lib/PackerFiles/Core/example/Disk.txt +29 -0
- data/lib/PackerFiles/Core/example/Hypervisor.txt +111 -0
- data/lib/PackerFiles/Core/example/Keyboard.txt +28 -0
- data/lib/PackerFiles/Core/example/Locale.txt +31 -0
- data/lib/PackerFiles/Core/example/Network.txt +68 -0
- data/lib/PackerFiles/Core/example/Packages.txt +22 -0
- data/lib/PackerFiles/Core/example/TimeZone.txt +36 -0
- data/lib/PackerFiles/Core/example/User.txt +48 -0
- data/lib/PackerFiles/OS/Builder.rb +116 -0
- data/lib/PackerFiles/OS/CentOS/CD.rb +81 -0
- data/lib/PackerFiles/OS/CentOS/Kickstart.rb +64 -0
- data/lib/PackerFiles/OS/CentOS/Server.rb +170 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Base_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Disk_erb.rb +35 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Keyboard_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Locale_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Network_erb.rb +17 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Packages_erb.rb +34 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Tail_erb.rb +15 -0
- data/lib/PackerFiles/OS/CentOS/Templates/TimeZone_erb.rb +10 -0
- data/lib/PackerFiles/OS/CentOS/Templates/User_erb.rb +20 -0
- data/lib/PackerFiles/OS/CentOS/Templates/boot_command_erb.rb +16 -0
- data/lib/PackerFiles/OS/CentOS/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/disable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Apt.rb +42 -0
- data/lib/PackerFiles/OS/Debian/CD.rb +65 -0
- data/lib/PackerFiles/OS/Debian/Mirrors.rb +73 -0
- data/lib/PackerFiles/OS/Debian/Preseed.rb +64 -0
- data/lib/PackerFiles/OS/Debian/Server.rb +169 -0
- data/lib/PackerFiles/OS/Debian/Templates/Apt_erb.rb +18 -0
- data/lib/PackerFiles/OS/Debian/Templates/Disk_erb.rb +69 -0
- data/lib/PackerFiles/OS/Debian/Templates/Keyboard_erb.rb +5 -0
- data/lib/PackerFiles/OS/Debian/Templates/Locale_erb.rb +7 -0
- data/lib/PackerFiles/OS/Debian/Templates/Mirrors_erb.rb +9 -0
- data/lib/PackerFiles/OS/Debian/Templates/Network_erb.rb +19 -0
- data/lib/PackerFiles/OS/Debian/Templates/Packages_erb.rb +6 -0
- data/lib/PackerFiles/OS/Debian/Templates/TimeZone_erb.rb +6 -0
- data/lib/PackerFiles/OS/Debian/Templates/User_erb.rb +14 -0
- data/lib/PackerFiles/OS/Debian/Templates/boot_command_erb.rb +24 -0
- data/lib/PackerFiles/OS/Debian/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Templates/disable_root_erb.rb +5 -0
- data/lib/PackerFiles/OS/Debian/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/example/Apt.txt +55 -0
- data/lib/PackerFiles/OS/DocGenerator.rb +51 -0
- data/lib/PackerFiles/OS/Finder.rb +96 -0
- data/lib/PackerFiles/OS/RHEL/CD.rb +32 -0
- data/lib/PackerFiles/OS/RHEL/Fedora.rb +59 -0
- data/lib/PackerFiles/OS/RHEL/FedoraCD.rb +68 -0
- data/lib/PackerFiles/OS/RHEL/Server.rb +32 -0
- data/lib/PackerFiles/OS/RHEL/Templates/Fedora_Tail_erb.rb +14 -0
- data/lib/PackerFiles/OS/RHEL/Templates/boot_command_fedora_erb.rb +16 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Base_erb.xml +32 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Disk_erb.xml +110 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Keyboard_erb.xml +7 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Locale_erb.xml +18 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Network_erb.xml +143 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Packages_erb.xml +29 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Tail_erb.xml +4 -0
- data/lib/PackerFiles/OS/SUSE/Templates/TimeZone_erb.xml +15 -0
- data/lib/PackerFiles/OS/SUSE/Templates/User_erb.xml +57 -0
- data/lib/PackerFiles/OS/SUSE/Templates/boot_command_erb.rb +23 -0
- data/lib/PackerFiles/OS/SUSE/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/disable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Ubuntu/CD.rb +81 -0
- data/lib/PackerFiles/OS/Ubuntu/Desktop.rb +50 -0
- data/lib/PackerFiles/OS/Ubuntu/DesktopCD.rb +16 -0
- data/lib/PackerFiles/OS/Ubuntu/Mirrors.rb +103 -0
- data/lib/PackerFiles/OS/Ubuntu/Server.rb +78 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/Apt_erb.rb +18 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_desktop_erb.rb +36 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_erb.rb +30 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/ubiquity_erb.rb +8 -0
- data/lib/PackerFiles/OS/example/Doc.txt +8 -0
- data/lib/PackerFiles/Provision/Base.rb +20 -0
- data/lib/PackerFiles/Provision/ChefSolo.rb +90 -0
- data/lib/PackerFiles/Provision/ChefSoloHelper.rb +72 -0
- data/lib/PackerFiles/Provision/Copy.rb +22 -0
- data/lib/PackerFiles/Provision/ExternalScript.rb +43 -0
- data/lib/PackerFiles/Provision/InlineScript.rb +37 -0
- data/lib/PackerFiles/Provision/Provisioners.rb +87 -0
- data/lib/PackerFiles/Provision/example/Provisioners.txt +21 -0
- data/lib/PackerFiles/Utils/AutoZone.rb +96 -0
- data/lib/PackerFiles/Utils/FastestURL.rb +73 -0
- data/lib/PackerFiles/Utils/Generator.rb +34 -0
- data/lib/PackerFiles/Utils/HashSerializer.rb +110 -0
- data/lib/PackerFiles/Utils/Size.rb +44 -0
- data/lib/PackerFiles/Utils/TypeAccessor.rb +71 -0
- data/lib/PackerFiles/Virtual/Hypervisors.rb +72 -0
- data/lib/PackerFiles/Virtual/KVM.rb +119 -0
- data/lib/PackerFiles/Virtual/KVMConverter.rb +79 -0
- data/lib/PackerFiles/Virtual/VMWare.rb +108 -0
- data/lib/PackerFiles/Virtual/VMWareConverter.rb +78 -0
- data/lib/PackerFiles/Virtual/VirtualBox.rb +98 -0
- data/lib/PackerFiles/Virtual/VirtualBoxConverter.rb +75 -0
- data/lib/PackerFiles/Virtual/example/Hypervisors.txt +23 -0
- data/lib/PackerFiles/version.rb +3 -0
- data/lib/PackerFiles.rb +44 -0
- data/spec/core/builder_spec.rb +84 -0
- data/spec/core/cdimage_spec.rb +159 -0
- data/spec/core/disk_spec.rb +191 -0
- data/spec/core/keyboard_spec.rb +36 -0
- data/spec/core/locale_spec.rb +73 -0
- data/spec/core/network_spec.rb +96 -0
- data/spec/core/packages_spec.rb +18 -0
- data/spec/core/timezone_spec.rb +43 -0
- data/spec/core/user_spec.rb +44 -0
- data/spec/core/volume_group_spec.rb +53 -0
- data/spec/os/centos/cd_spec.rb +12 -0
- data/spec/os/centos/data/Server-Script-Provisioner.rb +57 -0
- data/spec/os/centos/data/Server.rb +55 -0
- data/spec/os/centos/data/chef-solo-provisioner.rb +58 -0
- data/spec/os/centos/finder_spec.rb +22 -0
- data/spec/os/centos/templates/boot_command_spec.rb +57 -0
- data/spec/os/centos/templates/disk_spec.rb +79 -0
- data/spec/os/centos/templates/keyboard_spec.rb +18 -0
- data/spec/os/centos/templates/locale_spec.rb +26 -0
- data/spec/os/centos/templates/network_spec.rb +38 -0
- data/spec/os/centos/templates/packages_spec.rb +18 -0
- data/spec/os/centos/templates/timezone_spec.rb +37 -0
- data/spec/os/centos/templates/user_spec.rb +24 -0
- data/spec/os/debian/apt_spec.rb +50 -0
- data/spec/os/debian/cd_spec.rb +30 -0
- data/spec/os/debian/data/7zip.tar.gz +0 -0
- data/spec/os/debian/data/All-sections.rb +60 -0
- data/spec/os/debian/data/Chef-Solo-Provisioner.rb +60 -0
- data/spec/os/debian/data/Copy-Provisioner.rb +61 -0
- data/spec/os/debian/data/External-Script-Provisioner.rb +69 -0
- data/spec/os/debian/data/Missing-CDImage.rb +53 -0
- data/spec/os/debian/data/Missing-VMWare-KVM-sections.rb +51 -0
- data/spec/os/debian/data/Missing-sections.rb +53 -0
- data/spec/os/debian/data/Script-Provisioner.rb +62 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/Berksfile.lock +32 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/README.md +81 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/attributes/default.rb +3 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/metadata.rb +11 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/recipes/default.rb +30 -0
- data/spec/os/debian/data/chef-solo.json +5 -0
- data/spec/os/debian/data/test-script.sh +4 -0
- data/spec/os/debian/finder_spec.rb +59 -0
- data/spec/os/debian/mirrors_spec.rb +18 -0
- data/spec/os/debian/preseed_spec.rb +56 -0
- data/spec/os/debian/server_spec.rb +59 -0
- data/spec/os/debian/templates/apt_spec.rb +20 -0
- data/spec/os/debian/templates/boot_command_spec.rb +56 -0
- data/spec/os/debian/templates/disk_spec.rb +81 -0
- data/spec/os/debian/templates/keyboard_spec.rb +18 -0
- data/spec/os/debian/templates/locale_spec.rb +36 -0
- data/spec/os/debian/templates/mirrors_spec.rb +16 -0
- data/spec/os/debian/templates/network_spec.rb +38 -0
- data/spec/os/debian/templates/packages_spec.rb +17 -0
- data/spec/os/debian/templates/timezone_spec.rb +36 -0
- data/spec/os/debian/templates/user_spec.rb +25 -0
- data/spec/os/finder_spec.rb +21 -0
- data/spec/os/rhel/data/Fedora.rb +45 -0
- data/spec/os/rhel/data/Server-Custom.rb +54 -0
- data/spec/os/rhel/data/Server.rb +45 -0
- data/spec/os/rhel/finder_spec.rb +21 -0
- data/spec/os/ubuntu/cd_spec.rb +28 -0
- data/spec/os/ubuntu/data/Desktop.rb +61 -0
- data/spec/os/ubuntu/data/Server.rb +61 -0
- data/spec/os/ubuntu/finder_spec.rb +17 -0
- data/spec/os/ubuntu/mirrors_spec.rb +18 -0
- data/spec/utils/autozone_spec.rb +33 -0
- data/spec/virtual/virtual_box_spec.rb +16 -0
- metadata +405 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'OS/Builder'
|
3
|
+
require 'Core/Locale'
|
4
|
+
require 'Core/Keyboard'
|
5
|
+
require 'Core/TimeZone'
|
6
|
+
require 'Core/User'
|
7
|
+
require 'Core/Disk'
|
8
|
+
require 'Core/Network'
|
9
|
+
require 'Core/Packages'
|
10
|
+
require 'Core/CDImage'
|
11
|
+
require 'Virtual/VirtualBoxConverter'
|
12
|
+
require 'Virtual/KVMConverter'
|
13
|
+
require 'Virtual/VMWareConverter'
|
14
|
+
require_relative 'Kickstart'
|
15
|
+
require_relative 'CD'
|
16
|
+
|
17
|
+
# OS class that handles details for generating Packer files for CentOS
|
18
|
+
# Servers.
|
19
|
+
module PackerFiles
|
20
|
+
module CentOS
|
21
|
+
|
22
|
+
class Server < Builder
|
23
|
+
|
24
|
+
# List of type accessors used by this class that also gets converted
|
25
|
+
# to a preseed
|
26
|
+
def self.preseed_accessors
|
27
|
+
[Core::Locale, Core::Keyboard, Core::TimeZone,
|
28
|
+
Core::User, Core::Disk, Core::Network,
|
29
|
+
Core::Packages
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create accessors based on Type
|
34
|
+
self.preseed_accessors.each do |type|
|
35
|
+
type_accessor type
|
36
|
+
end
|
37
|
+
|
38
|
+
# Constructor. Yield self for further initialization
|
39
|
+
def initialize
|
40
|
+
yield self if block_given?
|
41
|
+
end
|
42
|
+
|
43
|
+
# hook function for generation
|
44
|
+
def generate_hook
|
45
|
+
|
46
|
+
# Construct objects that needs to be converted by using accessors.
|
47
|
+
# The tracker type_accessors tracks the mapping b/w Type names and
|
48
|
+
# method calls.
|
49
|
+
objects = []
|
50
|
+
objects.push self.Locale, self.Keyboard, self.TimeZone, self.User
|
51
|
+
objects.push self.Disk, self.Network, self.Packages
|
52
|
+
objects.each do |obj|
|
53
|
+
obj.normalize
|
54
|
+
end
|
55
|
+
|
56
|
+
# Call a hook function to customize kickstart generation by
|
57
|
+
# derived classes.
|
58
|
+
kickstart_write_hook(objects)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Hook function called before normalizing CD Image
|
62
|
+
def cd_image_hook
|
63
|
+
self.CDImage.impl = CD.new
|
64
|
+
end
|
65
|
+
|
66
|
+
# Hook function called for converting this object into a hash for
|
67
|
+
# VirtualBox
|
68
|
+
def vbox_converter_hook(gen)
|
69
|
+
Virtual::VirtualBoxConverter.new(self, gen).value
|
70
|
+
end
|
71
|
+
|
72
|
+
# Hook function called for converting this object into a hash for
|
73
|
+
# KVM
|
74
|
+
def kvm_converter_hook(gen)
|
75
|
+
Virtual::KVMConverter.new(self, gen).value
|
76
|
+
end
|
77
|
+
|
78
|
+
# Hook function called for converting this object into a hash for
|
79
|
+
# VMWare
|
80
|
+
def vmware_converter_hook(gen)
|
81
|
+
Virtual::VMWareConverter.new(self, gen).value
|
82
|
+
end
|
83
|
+
|
84
|
+
# Hook for writing into preseed file.
|
85
|
+
def kickstart_write_hook(objects)
|
86
|
+
|
87
|
+
# Preseed file by evaluating templates @ Debian folder.
|
88
|
+
kickstart = Kickstart.new(kickstart_file)
|
89
|
+
|
90
|
+
# Evaluate Head
|
91
|
+
kickstart.eval_file('CentOS/Templates/Base_erb.rb', {})
|
92
|
+
|
93
|
+
# Convert objects into Preseed configuration.
|
94
|
+
objects.each do |obj|
|
95
|
+
kickstart.convert obj, 'CentOS/Templates'
|
96
|
+
end
|
97
|
+
|
98
|
+
# Evaluate tail
|
99
|
+
kickstart.eval_file('CentOS/Templates/Tail_erb.rb', {'obj' => self})
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# Name of the preseed file
|
104
|
+
def kickstart_file
|
105
|
+
rel = self.CDImage.release
|
106
|
+
arch = self.CDImage.arch
|
107
|
+
name = "kickstart-centos-server-#{rel}-#{arch}.cfg"
|
108
|
+
File.join(http_dir, name)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Boot Command Override
|
112
|
+
def boot_command
|
113
|
+
file = PackerFiles.DirPath('CentOS/Templates/boot_command_erb.rb')
|
114
|
+
hash = { 'obj' => self, 'network' => self.Network }
|
115
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
116
|
+
value.split("\n")
|
117
|
+
end
|
118
|
+
|
119
|
+
# Shutdown command Override
|
120
|
+
def shutdown_command
|
121
|
+
file = PackerFiles.DirPath('CentOS/Templates/shutdown_command_erb.rb')
|
122
|
+
hash = { 'obj' => self.User }
|
123
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
124
|
+
value.chop
|
125
|
+
end
|
126
|
+
|
127
|
+
# Guest OS Type override
|
128
|
+
def guest_os_type
|
129
|
+
return "RedHat_64" if (self.CDImage.arch == "x86_64")
|
130
|
+
return "RedHat"
|
131
|
+
end
|
132
|
+
|
133
|
+
# VMWare Guest OS Type override
|
134
|
+
def vmware_guest_os_type
|
135
|
+
return "rhel4-64" if (self.CDImage.arch == "x86_64")
|
136
|
+
return "rhel4"
|
137
|
+
end
|
138
|
+
|
139
|
+
# VMWare Guest Flavor override
|
140
|
+
def vmware_guest_os_flavor
|
141
|
+
return "linux"
|
142
|
+
end
|
143
|
+
|
144
|
+
# Run any given command as root
|
145
|
+
def run_command_as_root
|
146
|
+
file = PackerFiles.DirPath('CentOS/Templates/command_as_root_erb.rb')
|
147
|
+
hash = { 'obj' => self }
|
148
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
149
|
+
value.chop
|
150
|
+
end
|
151
|
+
|
152
|
+
# Enable root user command w/o a password
|
153
|
+
def enable_root_for_user
|
154
|
+
file = PackerFiles.DirPath('CentOS/Templates/enable_root_erb.rb')
|
155
|
+
hash = { 'obj' => self }
|
156
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
157
|
+
value.chop
|
158
|
+
end
|
159
|
+
|
160
|
+
# Disable root user command w/o a password
|
161
|
+
def disable_root_for_user
|
162
|
+
file = PackerFiles.DirPath('CentOS/Templates/disable_root_erb.rb')
|
163
|
+
hash = { 'obj' => self }
|
164
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
165
|
+
value.chop
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Disk and Partition related
|
2
|
+
bootloader --location=mbr
|
3
|
+
zerombr
|
4
|
+
clearpart --all --initlabel
|
5
|
+
|
6
|
+
# Case 1: When just a disk is given, always use the regular atomic
|
7
|
+
# recipe, unless indicated otherwise.
|
8
|
+
<% if @obj.is_raw? -%>
|
9
|
+
autopart
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
# Case 2: A disk with multiple partitions
|
13
|
+
<% if @obj.only_partitions? -%>
|
14
|
+
<% @obj.partitions.each do |part| -%>
|
15
|
+
<% if part.file_system == 'linux-swap' -%>
|
16
|
+
partition swap --recommended --size=<%= part.size -%> --grow
|
17
|
+
<% else -%>
|
18
|
+
partition <%= part.mount_point -%> --size=<%= part.size -%> --fstype=<%= part.file_system %>
|
19
|
+
<% end -%>
|
20
|
+
<% end -%>
|
21
|
+
<% end -%>
|
22
|
+
|
23
|
+
# Case 3: A disk with Logical Volumes
|
24
|
+
<% if @obj.only_vg? -%>
|
25
|
+
partition pv.01 --size=<%= @obj.size -%> --grow
|
26
|
+
volgroup <%= @obj.vg.name -%> pv.01
|
27
|
+
<% @obj.vg.lvs.each do |lv| -%>
|
28
|
+
<% if lv.file_system == 'linux-swap' -%>
|
29
|
+
logvol swap --recommended --size=<%= lv.size -%> --grow --name=<%= lv.name -%> --vgname=<%= lv.vg_name %>
|
30
|
+
<% else -%>
|
31
|
+
logvol <%= lv.mount_point -%> --size=<%= lv.size -%> --fstype=<%= lv.file_system -%> --name=<%= lv.name -%> --vgname=<%= lv.vg_name %>
|
32
|
+
<% end -%>
|
33
|
+
<% end -%>
|
34
|
+
<% end -%>
|
35
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Network Configuration
|
2
|
+
<% if (@obj.is_static?) && ((@obj.type & PackerFiles::Core::Network::IPV4) > 0) -%>
|
3
|
+
network --device=<%= @obj.interface -%> --bootproto=static --ip=<%= @obj.ip -%> --netmask=<%= @obj.mask -%> --gateway=<%= @obj.gateway -%> --nameserver=<%= @obj.dns.join(',') -%>
|
4
|
+
<% elsif (@obj.is_static?) && ((@obj.type & PackerFiles::Core::Network::IPV6) > 0) -%>
|
5
|
+
network --device=<%= @obj.interface -%> --bootproto=static --ipv6=<%= @obj.ip -%> --netmask=<%= @obj.mask -%> --ipv6gateway=<%= @obj.gateway -%> --nameserver=<%= @obj.dns.join(',') -%>
|
6
|
+
<% elsif (!@obj.is_static?) && ((@obj.type & PackerFiles::Core::Network::IPV6) > 0) -%>
|
7
|
+
network --device=<%= @obj.interface -%> --bootproto=dhcp --noipv4
|
8
|
+
<% elsif (!@obj.is_static?) && ((@obj.type & PackerFiles::Core::Network::IPV4) > 0) -%>
|
9
|
+
network --device=<%= @obj.interface -%> --bootproto=dhcp --noipv6
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
# Enable Firewall
|
13
|
+
firewall --enabled --trust=<%= @obj.interface -%> --ssh
|
14
|
+
|
15
|
+
# Run SELINux in permissive mode
|
16
|
+
selinux --permissive
|
17
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Install the following packages
|
2
|
+
%packages --nobase --ignoremissing --excludedocs
|
3
|
+
<%= @obj.list.join("\n") -%>
|
4
|
+
|
5
|
+
# unnecessary firmware
|
6
|
+
-aic94xx-firmware
|
7
|
+
-atmel-firmware
|
8
|
+
-b43-openfwwf
|
9
|
+
-bfa-firmware
|
10
|
+
-ipw2100-firmware
|
11
|
+
-ipw2200-firmware
|
12
|
+
-ivtv-firmware
|
13
|
+
-iwl100-firmware
|
14
|
+
-iwl1000-firmware
|
15
|
+
-iwl3945-firmware
|
16
|
+
-iwl4965-firmware
|
17
|
+
-iwl5000-firmware
|
18
|
+
-iwl5150-firmware
|
19
|
+
-iwl6000-firmware
|
20
|
+
-iwl6000g2a-firmware
|
21
|
+
-iwl6050-firmware
|
22
|
+
-libertas-usb8388-firmware
|
23
|
+
-ql2100-firmware
|
24
|
+
-ql2200-firmware
|
25
|
+
-ql23xx-firmware
|
26
|
+
-ql2400-firmware
|
27
|
+
-ql2500-firmware
|
28
|
+
-rt61pci-firmware
|
29
|
+
-rt73usb-firmware
|
30
|
+
-xorg-x11-drv-ati-firmware
|
31
|
+
-zd1211-firmware
|
32
|
+
%end
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Misc. Parameters that are required for installation.
|
2
|
+
unsupported_hardware
|
3
|
+
text
|
4
|
+
firstboot --disabled
|
5
|
+
reboot
|
6
|
+
|
7
|
+
# Post Install Script
|
8
|
+
%post
|
9
|
+
|
10
|
+
# enable sudo for first user
|
11
|
+
<% str="%#{@obj.User.login} ALL=(ALL) NOPASSWD: ALL" -%>
|
12
|
+
echo "<%= str -%>" >> /etc/sudoers.d/<%= @obj.User.login %>
|
13
|
+
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
|
14
|
+
|
15
|
+
%end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Initial User configuration
|
2
|
+
<% if @obj.uid.nil?
|
3
|
+
uid = ''
|
4
|
+
else
|
5
|
+
uid = "--uid=#{@obj.uid}"
|
6
|
+
end
|
7
|
+
if @obj.groups.nil? || @obj.groups.empty?
|
8
|
+
groups = ''
|
9
|
+
else
|
10
|
+
groups = "--groups=" + @obj.groups.join(",")
|
11
|
+
end
|
12
|
+
-%>
|
13
|
+
user --name=<%= @obj.login -%> --password=<%= @obj.password -%> <%= uid -%> <%= groups %>
|
14
|
+
|
15
|
+
# Also specify the root password along with it.
|
16
|
+
rootpw <%= @obj.password -%>
|
17
|
+
|
18
|
+
# Enable shadow passwords with SHA-512 hash
|
19
|
+
auth --enableshadow --passalgo=sha512
|
20
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% kickstart = @obj.kickstart_file.gsub(@obj.http_dir,'').gsub('/', '') -%>
|
2
|
+
<% if @network.nil? -%>
|
3
|
+
<tab> text ks=http://{{user `host`}}:{{user `port`}}/<%= kickstart -%> <wait>
|
4
|
+
<% elsif !@network.is_static? -%>
|
5
|
+
<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<%= kickstart -%> <wait>
|
6
|
+
<% else -%>
|
7
|
+
<tab> text ks=http://{{user `host`}}:{{user `port`}}/<%= kickstart -%> <wait>
|
8
|
+
<% end -%>
|
9
|
+
<% if !@network.nil? && @network.is_static? -%>
|
10
|
+
ip=<%= @network.ip %> <wait>
|
11
|
+
netmask=<%= @network.mask %> <wait>
|
12
|
+
gateway=<%= @network.gateway %> <wait>
|
13
|
+
dns=<%= @network.dns.join(" ") %> <wait>
|
14
|
+
ksdevice=<%= @network.interface %> <wait>
|
15
|
+
<% end -%>
|
16
|
+
<enter><wait>
|
@@ -0,0 +1 @@
|
|
1
|
+
echo '<%= @obj.User.password -%>' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'
|
@@ -0,0 +1 @@
|
|
1
|
+
rm -rf /etc/sudoers/<%= @obj.User.login %>
|
@@ -0,0 +1 @@
|
|
1
|
+
echo "<%= @obj.User.login -%> ALL=NOPASSWD: ALL" >> /etc/sudoers.d/<%= @obj.User.login %>
|
@@ -0,0 +1 @@
|
|
1
|
+
sudo /sbin/halt -h -p
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'Core/Base'
|
3
|
+
require 'Core/Exceptions'
|
4
|
+
|
5
|
+
# Apt Setup handles all apt-related questions during the initial
|
6
|
+
# phase of OS installation.
|
7
|
+
module PackerFiles
|
8
|
+
module Debian
|
9
|
+
class Apt < Core::Base
|
10
|
+
|
11
|
+
# Accessors
|
12
|
+
attr_accessor :tasks
|
13
|
+
attr_accessor :non_free
|
14
|
+
attr_accessor :contrib
|
15
|
+
attr_accessor :upgrades
|
16
|
+
attr_accessor :kernel
|
17
|
+
|
18
|
+
# Documentation for this class
|
19
|
+
def self.doc_file
|
20
|
+
PackerFiles.DirPath('Debian/example/Apt.txt').first
|
21
|
+
end
|
22
|
+
|
23
|
+
# Constructor
|
24
|
+
def initialize
|
25
|
+
@tasks = []
|
26
|
+
@non_free = false
|
27
|
+
@contrib = false
|
28
|
+
@upgrades = 'none'
|
29
|
+
@kernel = 'linux-server'
|
30
|
+
yield self if block_given?
|
31
|
+
end
|
32
|
+
|
33
|
+
# Normalize
|
34
|
+
def normalize
|
35
|
+
raise Core::NilException.new(self, 'tasks') if @tasks.nil?
|
36
|
+
raise Core::NilException.new(self, 'kernel') if @kernel.nil?
|
37
|
+
raise Core::EmptyArrayException.new(self, 'tasks') if @tasks.empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'uri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require "Core/CDImage"
|
6
|
+
require "Utils/AutoZone"
|
7
|
+
|
8
|
+
# An implementation for CDImage which lists all available Debian CD Mirrors
|
9
|
+
module PackerFiles
|
10
|
+
module Debian
|
11
|
+
class CD < Core::CDImageImpl
|
12
|
+
|
13
|
+
# Index URL which contains all the Debian CD Mirror list
|
14
|
+
@@index = 'https://www.debian.org/CD/http-ftp/'
|
15
|
+
|
16
|
+
# Override method for getting the ISO name
|
17
|
+
def get_iso_name_pattern
|
18
|
+
'debian-@release@-@arch@-CD-1.iso'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Override method for getting checksums
|
22
|
+
def get_check_sum_pattern
|
23
|
+
'MD5SUMS'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Override method for checksum type
|
27
|
+
def get_check_sum_type
|
28
|
+
'md5'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Override method for getting index URLs.
|
32
|
+
def index_urls
|
33
|
+
master_index_urls + mirror_index_urls
|
34
|
+
end
|
35
|
+
|
36
|
+
# The Index URLs from the main debian CD Image server.
|
37
|
+
private
|
38
|
+
def master_index_urls
|
39
|
+
%w[
|
40
|
+
http://cdimage.debian.org/debian-cd/@release@/@arch@/iso-cd/
|
41
|
+
http://cdimage.debian.org/mirror/cdimage/archive/@release@/@arch@/iso-cd/
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
# The Index URLs from other debian CD mirrors. The CD Mirrors only support CD
|
46
|
+
# images and not DVD Images.
|
47
|
+
private
|
48
|
+
def mirror_index_urls
|
49
|
+
|
50
|
+
# Use nokogiri to parse the index page, to get all the URLs that contain
|
51
|
+
# country name [as detected by AutoZone]. Unfortunately this code can only
|
52
|
+
# be understood if HTML structure is visually inspected first. In short,
|
53
|
+
# debian mirrors for all the countries in the index file, looks like
|
54
|
+
# <li> "Country" <a rel="nofollow" href="http://debian.xfree.com.ar/debian-cd/"> </li>
|
55
|
+
page = Nokogiri::HTML(open(@@index))
|
56
|
+
country = Utils::AutoZone.new.JSON['country']
|
57
|
+
nodes = page.css('li').select {|node| node.text.include?(country)}
|
58
|
+
arefs = nodes.map {|node| node.css('a')}.flatten
|
59
|
+
mirrors = arefs.map {|aref| aref.attribute('href').value}
|
60
|
+
mirrors.map! {|m| URI::join(m, '@release@/@arch@/iso-cd/').to_s}
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'open-uri'
|
3
|
+
require 'benchmark'
|
4
|
+
require 'uri'
|
5
|
+
require 'Utils/AutoZone'
|
6
|
+
require 'Utils/FastestURL'
|
7
|
+
|
8
|
+
# Auto configures the debian mirror list. This is useful in pre-seeding
|
9
|
+
# the fastest possible mirror.
|
10
|
+
module PackerFiles
|
11
|
+
module Debian
|
12
|
+
class Mirrors
|
13
|
+
|
14
|
+
# default debian mirror
|
15
|
+
@@default = 'http://mirrors.kernel.org/debian'
|
16
|
+
|
17
|
+
# Default debian mirror list
|
18
|
+
@@mirrors = 'https://www.debian.org/mirror/list'
|
19
|
+
|
20
|
+
# accessors
|
21
|
+
attr_reader :hosts
|
22
|
+
attr_reader :best
|
23
|
+
attr_reader :proxy
|
24
|
+
|
25
|
+
# Constructor
|
26
|
+
def initialize
|
27
|
+
|
28
|
+
# A Single web page get more than this (in seconds) is SLOW
|
29
|
+
limit = 1
|
30
|
+
|
31
|
+
# No. of trials for a web page
|
32
|
+
trials = 4
|
33
|
+
|
34
|
+
# Get the name of the http proxy
|
35
|
+
@proxy = ENV['http_proxy']
|
36
|
+
|
37
|
+
# Get the host list of mirrors for this country
|
38
|
+
code = Utils::AutoZone.new.country_code.downcase
|
39
|
+
@hosts = country_mirror(code)
|
40
|
+
if @hosts.empty?
|
41
|
+
@hosts = [@@default] if @hosts.empty?
|
42
|
+
@best = URI::parse(@@default)
|
43
|
+
else
|
44
|
+
f = Utils::FastestURL.new(limit, trials)
|
45
|
+
all = f.best_urls(@hosts).flatten
|
46
|
+
begin
|
47
|
+
@best = URI::parse(all.first)
|
48
|
+
rescue Exception => e
|
49
|
+
puts "Exception: #{e}, All: #{all.to_s}"
|
50
|
+
raise e
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Given the country code, get a list of mirror sites that match
|
56
|
+
# the country code.
|
57
|
+
private
|
58
|
+
def country_mirror(code)
|
59
|
+
arr = []
|
60
|
+
regex = 'href=\"(http://.+\.' + code + '\/.+)"'
|
61
|
+
open(@@mirrors) {|f|
|
62
|
+
f.each_line do |line|
|
63
|
+
if match = line.match(regex)
|
64
|
+
arr.push(match[1])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
}
|
68
|
+
return arr
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
# OS class that handles details for generating Preseed files for Debian
|
5
|
+
# Servers.
|
6
|
+
module PackerFiles
|
7
|
+
module Debian
|
8
|
+
|
9
|
+
class Preseed
|
10
|
+
|
11
|
+
# Constructor. The preseed file name is the name of the file
|
12
|
+
# that will be written to.
|
13
|
+
def initialize(filename)
|
14
|
+
@preseed = filename
|
15
|
+
create_file
|
16
|
+
end
|
17
|
+
|
18
|
+
# Serializes the given object and write out the content
|
19
|
+
# in the output file.
|
20
|
+
def convert(obj, os_name)
|
21
|
+
file = erb_file(obj, os_name)
|
22
|
+
content = PackerFiles.evaluate_erb(file, { "obj" => obj })
|
23
|
+
add_content(content)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Evaluate a partially specified file name (should be in the Gem's
|
27
|
+
# file list though) and add the content to the @preseed file
|
28
|
+
def eval_file(file_name, hash)
|
29
|
+
erb_file = PackerFiles.DirPath(file_name).first
|
30
|
+
content = PackerFiles.evaluate_erb(erb_file, hash)
|
31
|
+
add_content(content)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Given an object, figure out the class name and return back the correct
|
35
|
+
# erb file name.
|
36
|
+
private
|
37
|
+
def erb_file(obj, os_name)
|
38
|
+
|
39
|
+
erb_file = File.join(os_name, obj.class.name.gsub(/.*::/,'') + '_erb.rb')
|
40
|
+
erb_path = PackerFiles.DirPath(erb_file)
|
41
|
+
|
42
|
+
if erb_path.nil? || erb_path.empty?
|
43
|
+
raise RuntimeError.new("Template Path #{erb_file} does not exist")
|
44
|
+
end
|
45
|
+
return erb_path.first
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create a new file with no content
|
49
|
+
private
|
50
|
+
def create_file
|
51
|
+
basename = File.dirname(@preseed)
|
52
|
+
FileUtils.mkdir_p(basename) if !Dir.exist?(basename)
|
53
|
+
File.open(@preseed, 'w') {|f| f.write ''}
|
54
|
+
end
|
55
|
+
|
56
|
+
# Add content to the preseed file
|
57
|
+
private
|
58
|
+
def add_content(content)
|
59
|
+
File.open(@preseed, 'a') {|f| f.write(content) }
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|