Class | BoxGrinder::RPMBasedOSPlugin |
In: |
lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb
lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb |
Parent: | BasePlugin |
Add default repos (if present) to the list of additional repositories specified in appliance definition.
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 95 95: def add_repos(repos) 96: return if repos.empty? 97: 98: repos[@appliance_config.os.version].each do |name, repo| 99: r = { 'name' => name, 'ephemeral' => true } 100: 101: ['baseurl', 'mirrorlist'].each { |type| r[type] = substitute_vars(repo[type]) unless repo[type].nil? } 102: 103: @appliance_config.repos << r 104: end 105: end
Add default repos (if present) to the list of additional repositories specified in appliance definition.
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 95 95: def add_repos(repos) 96: return if repos.empty? 97: 98: repos[@appliance_config.os.version].each do |name, repo| 99: r = { 'name' => name, 'ephemeral' => true } 100: 101: ['baseurl', 'mirrorlist'].each { |type| r[type] = substitute_vars(repo[type]) unless repo[type].nil? } 102: 103: @appliance_config.repos << r 104: end 105: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 28 28: def after_init 29: register_deliverable( 30: :disk => "#{@appliance_config.name}-sda.#{@plugin_config['format']}", 31: :descriptor => "#{@appliance_config.name}.xml" 32: ) 33: 34: @linux_helper = LinuxHelper.new(:log => @log) 35: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 28 28: def after_init 29: register_deliverable( 30: :disk => "#{@appliance_config.name}-sda.#{@plugin_config['format']}", 31: :descriptor => "#{@appliance_config.name}.xml" 32: ) 33: 34: @linux_helper = LinuxHelper.new(:log => @log) 35: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 277 277: def apply_root_password(guestfs) 278: @log.debug "Applying root password..." 279: guestfs.sh("/usr/bin/passwd -d root") 280: guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root") 281: @log.debug "Password applied." 282: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 277 277: def apply_root_password(guestfs) 278: @log.debug "Applying root password..." 279: guestfs.sh("/usr/bin/passwd -d root") 280: guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root") 281: @log.debug "Password applied." 282: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 116 116: def build_with_appliance_creator(appliance_definition_file, repos = {}) 117: @appliance_definition_file = appliance_definition_file 118: 119: if File.extname(appliance_definition_file).eql?('.ks') 120: kickstart_file = appliance_definition_file 121: else 122: add_repos(repos) if @appliance_config.default_repos 123: kickstart_file = Kickstart.new(@config, @appliance_config, @dir, :log => @log).create 124: RPMDependencyValidator.new(@config, @appliance_config, @dir, :log => @log).resolve_packages 125: end 126: 127: @log.info "Building #{@appliance_config.name} appliance..." 128: 129: execute_appliance_creator(kickstart_file) 130: 131: FileUtils.mv(Dir.glob("#{@dir.tmp}/#{@appliance_config.name}/*"), @dir.tmp) 132: FileUtils.rm_rf("#{@dir.tmp}/#{@appliance_config.name}/") 133: 134: @image_helper.customize([@deliverables.disk]) do |guestfs, guestfs_helper| 135: # TODO is this really needed? 136: @log.debug "Uploading '/etc/resolv.conf'..." 137: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 138: @log.debug "'/etc/resolv.conf' uploaded." 139: 140: change_configuration(guestfs_helper) 141: # TODO check if this is still required 142: apply_root_password(guestfs) 143: set_label_for_swap_partitions(guestfs, guestfs_helper) 144: use_labels_for_partitions(guestfs) 145: disable_firewall(guestfs) 146: set_motd(guestfs) 147: install_repos(guestfs) 148: install_files(guestfs) 149: 150: guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0 151: 152: # https://issues.jboss.org/browse/BGBUILD-148 153: recreate_rpm_database(guestfs, guestfs_helper) if @config.os.name != @appliance_config.os.name or @config.os.version != @appliance_config.os.version 154: 155: execute_post(guestfs_helper) 156: 157: yield guestfs, guestfs_helper if block_given? 158: end 159: 160: @log.info "Base image for #{@appliance_config.name} appliance was built successfully." 161: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 116 116: def build_with_appliance_creator(appliance_definition_file, repos = {}) 117: @appliance_definition_file = appliance_definition_file 118: 119: if File.extname(appliance_definition_file).eql?('.ks') 120: kickstart_file = appliance_definition_file 121: else 122: add_repos(repos) if @appliance_config.default_repos 123: kickstart_file = Kickstart.new(@config, @appliance_config, @dir, :log => @log).create 124: RPMDependencyValidator.new(@config, @appliance_config, @dir, :log => @log).resolve_packages 125: end 126: 127: @log.info "Building #{@appliance_config.name} appliance..." 128: 129: execute_appliance_creator(kickstart_file) 130: 131: FileUtils.mv(Dir.glob("#{@dir.tmp}/#{@appliance_config.name}/*"), @dir.tmp) 132: FileUtils.rm_rf("#{@dir.tmp}/#{@appliance_config.name}/") 133: 134: @image_helper.customize([@deliverables.disk]) do |guestfs, guestfs_helper| 135: # TODO is this really needed? 136: @log.debug "Uploading '/etc/resolv.conf'..." 137: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 138: @log.debug "'/etc/resolv.conf' uploaded." 139: 140: change_configuration(guestfs_helper) 141: # TODO check if this is still required 142: apply_root_password(guestfs) 143: set_label_for_swap_partitions(guestfs, guestfs_helper) 144: use_labels_for_partitions(guestfs) 145: disable_firewall(guestfs) 146: set_motd(guestfs) 147: install_repos(guestfs) 148: install_files(guestfs) 149: 150: guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0 151: 152: # https://issues.jboss.org/browse/BGBUILD-148 153: recreate_rpm_database(guestfs, guestfs_helper) if @config.os.name != @appliance_config.os.name or @config.os.version != @appliance_config.os.version 154: 155: execute_post(guestfs_helper) 156: 157: yield guestfs, guestfs_helper if block_given? 158: end 159: 160: @log.info "Base image for #{@appliance_config.name} appliance was built successfully." 161: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 284 284: def change_configuration(guestfs_helper) 285: guestfs_helper.augeas do 286: set('/etc/ssh/sshd_config', 'UseDNS', 'no') 287: set('/etc/sysconfig/selinux', 'SELINUX', 'permissive') 288: end 289: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 284 284: def change_configuration(guestfs_helper) 285: guestfs_helper.augeas do 286: set('/etc/ssh/sshd_config', 'UseDNS', 'no') 287: set('/etc/sysconfig/selinux', 'SELINUX', 'permissive') 288: end 289: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 198 198: def cleanup_after_appliance_creator(pid) 199: @log.debug "Sending TERM signal to process '#{pid}'..." 200: Process.kill("TERM", pid) 201: 202: @log.debug "Waiting for process to be terminated..." 203: Process.wait(pid) 204: 205: @log.debug "Cleaning appliance-creator mount points..." 206: 207: Dir["#{@dir.tmp}/imgcreate-*"].each do |dir| 208: dev_mapper = @exec_helper.execute "mount | grep #{dir} | awk '{print $1}'" 209: 210: mappings = {} 211: 212: dev_mapper.each do |mapping| 213: if mapping =~ /(loop\d+)p(\d+)/ 214: mappings[$1] = [] if mappings[$1].nil? 215: mappings[$1] << $2 unless mappings[$1].include?($2) 216: end 217: end 218: 219: (['/var/cache/yum', '/dev/shm', '/dev/pts', '/proc', '/sys'] + @appliance_config.hardware.partitions.keys.reverse).each do |mount_point| 220: @log.trace "Unmounting '#{mount_point}'..." 221: @exec_helper.execute "umount -d #{dir}/install_root#{mount_point}" 222: end 223: 224: mappings.each do |loop, partitions| 225: @log.trace "Removing mappings from loop device #{loop}..." 226: @exec_helper.execute "/sbin/kpartx -d /dev/#{loop}" 227: @exec_helper.execute "losetup -d /dev/#{loop}" 228: 229: partitions.each do |part| 230: @log.trace "Removing mapping for partition #{part} from loop device #{loop}..." 231: @exec_helper.execute "rm /dev/#{loop}#{part}" 232: end 233: end 234: end 235: 236: @log.debug "Cleaned up after appliance-creator." 237: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 198 198: def cleanup_after_appliance_creator(pid) 199: @log.debug "Sending TERM signal to process '#{pid}'..." 200: Process.kill("TERM", pid) 201: 202: @log.debug "Waiting for process to be terminated..." 203: Process.wait(pid) 204: 205: @log.debug "Cleaning appliance-creator mount points..." 206: 207: Dir["#{@dir.tmp}/imgcreate-*"].each do |dir| 208: dev_mapper = @exec_helper.execute "mount | grep #{dir} | awk '{print $1}'" 209: 210: mappings = {} 211: 212: dev_mapper.each do |mapping| 213: if mapping =~ /(loop\d+)p(\d+)/ 214: mappings[$1] = [] if mappings[$1].nil? 215: mappings[$1] << $2 unless mappings[$1].include?($2) 216: end 217: end 218: 219: (['/var/cache/yum', '/dev/shm', '/dev/pts', '/proc', '/sys'] + @appliance_config.hardware.partitions.keys.reverse).each do |mount_point| 220: @log.trace "Unmounting '#{mount_point}'..." 221: @exec_helper.execute "umount -d #{dir}/install_root#{mount_point}" 222: end 223: 224: mappings.each do |loop, partitions| 225: @log.trace "Removing mappings from loop device #{loop}..." 226: @exec_helper.execute "/sbin/kpartx -d /dev/#{loop}" 227: @exec_helper.execute "losetup -d /dev/#{loop}" 228: 229: partitions.each do |part| 230: @log.trace "Removing mapping for partition #{part} from loop device #{loop}..." 231: @exec_helper.execute "rm /dev/#{loop}#{part}" 232: end 233: end 234: end 235: 236: @log.debug "Cleaned up after appliance-creator." 237: end
issues.jboss.org/browse/BGBUILD-177
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 240 240: def disable_firewall(guestfs) 241: @log.debug "Disabling firewall..." 242: guestfs.sh("lokkit -q --disabled") 243: @log.debug "Firewall disabled." 244: end
issues.jboss.org/browse/BGBUILD-177
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 240 240: def disable_firewall(guestfs) 241: @log.debug "Disabling firewall..." 242: guestfs.sh("lokkit -q --disabled") 243: @log.debug "Firewall disabled." 244: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 163 163: def execute_appliance_creator(kickstart_file) 164: begin 165: @exec_helper.execute "appliance-creator -d -v -t '#{@dir.tmp}' --cache=#{@config.dir.cache}/rpms-cache/#{@appliance_config.path.main} --config '#{kickstart_file}' -o '#{@dir.tmp}' --name '#{@appliance_config.name}' --vmem #{@appliance_config.hardware.memory} --vcpu #{@appliance_config.hardware.cpus} --format #{@plugin_config['format']}" 166: rescue InterruptionError => e 167: cleanup_after_appliance_creator(e.pid) 168: abort 169: end 170: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 163 163: def execute_appliance_creator(kickstart_file) 164: begin 165: @exec_helper.execute "appliance-creator -d -v -t '#{@dir.tmp}' --cache=#{@config.dir.cache}/rpms-cache/#{@appliance_config.path.main} --config '#{kickstart_file}' -o '#{@dir.tmp}' --name '#{@appliance_config.name}' --vmem #{@appliance_config.hardware.memory} --vcpu #{@appliance_config.hardware.cpus} --format #{@plugin_config['format']}" 166: rescue InterruptionError => e 167: cleanup_after_appliance_creator(e.pid) 168: abort 169: end 170: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 172 172: def execute_post(guestfs_helper) 173: @log.info "Executing post operations after build..." 174: unless @appliance_config.post['base'].nil? 175: @appliance_config.post['base'].each do |cmd| 176: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 177: end 178: @log.debug "Post commands from appliance definition file executed." 179: else 180: @log.debug "No commands specified, skipping." 181: end 182: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 172 172: def execute_post(guestfs_helper) 173: @log.info "Executing post operations after build..." 174: unless @appliance_config.post['base'].nil? 175: @appliance_config.post['base'].each do |cmd| 176: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 177: end 178: @log.debug "Post commands from appliance definition file executed." 179: else 180: @log.debug "No commands specified, skipping." 181: end 182: end
Copies specified files into appliance.
There are two types of paths:
Please use relative paths. Relative means relative to the appliance definition file. Using absolute paths will cause creating whole directory structure in appliance, which is most probably not exactly what you want.
issues.jboss.org/browse/BGBUILD-276
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 339 339: def install_files(guestfs) 340: @log.debug "Installing files specified in appliance definition file..." 341: 342: @appliance_config.files.each do |dir, files| 343: 344: @log.debug "Proceding files for '#{dir}' destination directory..." 345: 346: local_files = [] 347: 348: # Create the directory if it doesn't exists 349: guestfs.mkdir_p(dir) unless guestfs.exists(dir) != 0 350: 351: files.each do |f| 352: if f.match(/^(http|ftp|https):\/\//) 353: # Remote url provided 354: @log.trace "Remote url detected: '#{f}'." 355: 356: # We have a remote file, try to download it using curl! 357: guestfs.sh("cd #{dir} && curl -O -L #{f}") 358: else 359: @log.trace "Local path detected: '#{f}'." 360: 361: file_path = (f.match(/^\//) ? f : "#{File.dirname(@appliance_definition_file)}/#{f}") 362: 363: # TODO validate this earlier 364: raise ValidationError, "File '#{f}' specified in files section of appliance definition file doesn't exists." unless File.exists?(file_path) 365: 366: local_files << f 367: end 368: end 369: 370: next if local_files.empty? 371: 372: @log.trace "Tarring files..." 373: @exec_helper.execute("cd #{File.dirname(@appliance_definition_file)} && tar -cvf /tmp/bg_install_files.tar --wildcards #{local_files.join(' ')}") 374: @log.trace "Files tarred." 375: 376: @log.trace "Uploading and unpacking..." 377: guestfs.tar_in("/tmp/bg_install_files.tar", dir) 378: @log.trace "Files uploaded." 379: 380: end 381: @log.debug "Files installed." 382: end
Copies specified files into appliance.
There are two types of paths:
Please use relative paths. Relative means relative to the appliance definition file. Using absolute paths will cause creating whole directory structure in appliance, which is most probably not exactly what you want.
issues.jboss.org/browse/BGBUILD-276
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 339 339: def install_files(guestfs) 340: @log.debug "Installing files specified in appliance definition file..." 341: 342: @appliance_config.files.each do |dir, files| 343: 344: @log.debug "Proceding files for '#{dir}' destination directory..." 345: 346: local_files = [] 347: 348: # Create the directory if it doesn't exists 349: guestfs.mkdir_p(dir) unless guestfs.exists(dir) != 0 350: 351: files.each do |f| 352: if f.match(/^(http|ftp|https):\/\//) 353: # Remote url provided 354: @log.trace "Remote url detected: '#{f}'." 355: 356: # We have a remote file, try to download it using curl! 357: guestfs.sh("cd #{dir} && curl -O -L #{f}") 358: else 359: @log.trace "Local path detected: '#{f}'." 360: 361: file_path = (f.match(/^\//) ? f : "#{File.dirname(@appliance_definition_file)}/#{f}") 362: 363: # TODO validate this earlier 364: raise ValidationError, "File '#{f}' specified in files section of appliance definition file doesn't exists." unless File.exists?(file_path) 365: 366: local_files << f 367: end 368: end 369: 370: next if local_files.empty? 371: 372: @log.trace "Tarring files..." 373: @exec_helper.execute("cd #{File.dirname(@appliance_definition_file)} && tar -cvf /tmp/bg_install_files.tar --wildcards #{local_files.join(' ')}") 374: @log.trace "Files tarred." 375: 376: @log.trace "Uploading and unpacking..." 377: guestfs.tar_in("/tmp/bg_install_files.tar", dir) 378: @log.trace "Files uploaded." 379: 380: end 381: @log.debug "Files installed." 382: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 308 308: def install_repos(guestfs) 309: @log.debug "Installing repositories from appliance definition file..." 310: @appliance_config.repos.each do |repo| 311: if repo['ephemeral'] 312: @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance." 313: next 314: end 315: 316: @log.debug "Installing #{repo['name']} repo..." 317: repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name']) 318: 319: ['baseurl', 'mirrorlist'].each do |type| 320: repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil? 321: end 322: 323: guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0) 324: end 325: @log.debug "Repositories installed." 326: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 308 308: def install_repos(guestfs) 309: @log.debug "Installing repositories from appliance definition file..." 310: @appliance_config.repos.each do |repo| 311: if repo['ephemeral'] 312: @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance." 313: next 314: end 315: 316: @log.debug "Installing #{repo['name']} repo..." 317: repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name']) 318: 319: ['baseurl', 'mirrorlist'].each do |type| 320: repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil? 321: end 322: 323: guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0) 324: end 325: @log.debug "Repositories installed." 326: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 41 41: def read_file(file) 42: read_kickstart(file) if File.extname(file).eql?('.ks') 43: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 41 41: def read_file(file) 42: read_kickstart(file) if File.extname(file).eql?('.ks') 43: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 45 45: def read_kickstart(file) 46: appliance_config = ApplianceConfig.new 47: appliance_config.name = File.basename(file, '.ks') 48: 49: name = nil 50: version = nil 51: 52: kickstart = File.read(file) 53: 54: kickstart.each do |line| 55: n = line.scan(/^# bg_os_name: (.*)/).flatten.first 56: v = line.scan(/^# bg_os_version: (.*)/).flatten.first 57: 58: name = n unless n.nil? 59: version = v unless v.nil? 60: end 61: 62: raise "No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora" if name.nil? 63: raise "No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14" if version.nil? 64: 65: appliance_config.os.name = name 66: appliance_config.os.version = version 67: 68: partitions = {} 69: 70: kickstart.each do |line| 71: # Parse also the partition scheme 72: if line =~ /^part ([\/\w]+)/ 73: root = $1 74: partitions[root] = {} 75: 76: # size 77: partitions[root]['size'] = $1.to_f / 1024 if line =~ /--size[=\s]*(\d+)/ 78: # fs type 79: partitions[root]['type'] = $1 if line =~ /--fstype[=\s]*(\w+)/ 80: # fs options 81: partitions[root]['options'] = $1 if line =~ /--fsoptions[=\s]*([,\w]+)/ 82: 83: raise "Partition size not specified for #{root} partition in #{file}" if partitions[root]['size'].nil? 84: end 85: end 86: 87: raise "No partitions specified in your kickstart file #{file}" if partitions.empty? 88: 89: appliance_config.hardware.partitions = partitions 90: 91: appliance_config 92: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 45 45: def read_kickstart(file) 46: appliance_config = ApplianceConfig.new 47: appliance_config.name = File.basename(file, '.ks') 48: 49: name = nil 50: version = nil 51: 52: kickstart = File.read(file) 53: 54: kickstart.each do |line| 55: n = line.scan(/^# bg_os_name: (.*)/).flatten.first 56: v = line.scan(/^# bg_os_version: (.*)/).flatten.first 57: 58: name = n unless n.nil? 59: version = v unless v.nil? 60: end 61: 62: raise "No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora" if name.nil? 63: raise "No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14" if version.nil? 64: 65: appliance_config.os.name = name 66: appliance_config.os.version = version 67: 68: partitions = {} 69: 70: kickstart.each do |line| 71: # Parse also the partition scheme 72: if line =~ /^part ([\/\w]+)/ 73: root = $1 74: partitions[root] = {} 75: 76: # size 77: partitions[root]['size'] = $1.to_f / 1024 if line =~ /--size[=\s]*(\d+)/ 78: # fs type 79: partitions[root]['type'] = $1 if line =~ /--fstype[=\s]*(\w+)/ 80: # fs options 81: partitions[root]['options'] = $1 if line =~ /--fsoptions[=\s]*([,\w]+)/ 82: 83: raise "Partition size not specified for #{root} partition in #{file}" if partitions[root]['size'].nil? 84: end 85: end 86: 87: raise "No partitions specified in your kickstart file #{file}" if partitions.empty? 88: 89: appliance_config.hardware.partitions = partitions 90: 91: appliance_config 92: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 304 304: def recreate_kernel_image(guestfs, modules = []) 305: @linux_helper.recreate_kernel_image(guestfs, modules) 306: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 304 304: def recreate_kernel_image(guestfs, modules = []) 305: @linux_helper.recreate_kernel_image(guestfs, modules) 306: end
issues.jboss.org/browse/BGBUILD-148
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 185 185: def recreate_rpm_database(guestfs, guestfs_helper) 186: @log.debug "Recreating RPM database..." 187: 188: guestfs.download("/var/lib/rpm/Packages", "#{@dir.tmp}/Packages") 189: @exec_helper.execute("/usr/lib/rpm/rpmdb_dump #{@dir.tmp}/Packages > #{@dir.tmp}/Packages.dump") 190: guestfs.upload("#{@dir.tmp}/Packages.dump", "/tmp/Packages.dump") 191: guestfs.sh("rm -rf /var/lib/rpm/*") 192: guestfs_helper.sh("cd /var/lib/rpm/ && cat /tmp/Packages.dump | /usr/lib/rpm/rpmdb_load Packages") 193: guestfs_helper.sh("rpm --rebuilddb") 194: 195: @log.debug "RPM database recreated..." 196: end
issues.jboss.org/browse/BGBUILD-148
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 185 185: def recreate_rpm_database(guestfs, guestfs_helper) 186: @log.debug "Recreating RPM database..." 187: 188: guestfs.download("/var/lib/rpm/Packages", "#{@dir.tmp}/Packages") 189: @exec_helper.execute("/usr/lib/rpm/rpmdb_dump #{@dir.tmp}/Packages > #{@dir.tmp}/Packages.dump") 190: guestfs.upload("#{@dir.tmp}/Packages.dump", "/tmp/Packages.dump") 191: guestfs.sh("rm -rf /var/lib/rpm/*") 192: guestfs_helper.sh("cd /var/lib/rpm/ && cat /tmp/Packages.dump | /usr/lib/rpm/rpmdb_load Packages") 193: guestfs_helper.sh("rpm --rebuilddb") 194: 195: @log.debug "RPM database recreated..." 196: end
issues.jboss.org/browse/BGBUILD-301
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 247 247: def set_label_for_swap_partitions(guestfs, guestfs_helper) 248: @log.trace "Searching for swap partition to set label..." 249: 250: guestfs_helper.mountable_partitions(guestfs.list_devices.first, :list_swap => true).each do |p| 251: if guestfs.vfs_type(p).eql?('swap') 252: @log.debug "Setting 'swap' label for partiiton '#{p}'." 253: guestfs.mkswap_L('swap', p) 254: @log.debug "Label set." 255: # We assume here that nobody will want to have two swap partitions 256: break 257: end 258: end 259: end
issues.jboss.org/browse/BGBUILD-301
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 247 247: def set_label_for_swap_partitions(guestfs, guestfs_helper) 248: @log.trace "Searching for swap partition to set label..." 249: 250: guestfs_helper.mountable_partitions(guestfs.list_devices.first, :list_swap => true).each do |p| 251: if guestfs.vfs_type(p).eql?('swap') 252: @log.debug "Setting 'swap' label for partiiton '#{p}'." 253: guestfs.mkswap_L('swap', p) 254: @log.debug "Label set." 255: # We assume here that nobody will want to have two swap partitions 256: break 257: end 258: end 259: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 291 291: def set_motd(guestfs) 292: @log.debug "Setting up '/etc/motd'..." 293: # set nice banner for SSH 294: motd_file = "/etc/init.d/motd" 295: guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file) 296: guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}") 297: guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}") 298: 299: guestfs.sh("/bin/chmod +x #{motd_file}") 300: guestfs.sh("/sbin/chkconfig --add motd") 301: @log.debug "'/etc/motd' is nice now." 302: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 291 291: def set_motd(guestfs) 292: @log.debug "Setting up '/etc/motd'..." 293: # set nice banner for SSH 294: motd_file = "/etc/init.d/motd" 295: guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file) 296: guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}") 297: guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}") 298: 299: guestfs.sh("/bin/chmod +x #{motd_file}") 300: guestfs.sh("/sbin/chkconfig --add motd") 301: @log.debug "'/etc/motd' is nice now." 302: end
Substitute variables in selected string.
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 108 108: def substitute_vars(str) 109: return if str.nil? 110: @appliance_config.variables.keys.each do |var| 111: str = str.gsub("##{var}#", @appliance_config.variables[var]) 112: end 113: str 114: end
Substitute variables in selected string.
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 108 108: def substitute_vars(str) 109: return if str.nil? 110: @appliance_config.variables.keys.each do |var| 111: str = str.gsub("##{var}#", @appliance_config.variables[var]) 112: end 113: str 114: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 261 261: def use_labels_for_partitions(guestfs) 262: @log.debug "Using labels for partitions..." 263: device = guestfs.list_devices.first 264: 265: # /etc/fstab 266: if fstab = guestfs.read_file('/etc/fstab').gsub!(/^(\/dev\/sda.)/) { |path| "LABEL=#{guestfs.vfs_label(path.gsub('/dev/sda', device))}" } 267: guestfs.write_file('/etc/fstab', fstab, 0) 268: end 269: 270: # /boot/grub/grub.conf 271: if grub = guestfs.read_file('/boot/grub/grub.conf').gsub!(/(\/dev\/sda.)/) { |path| "LABEL=#{guestfs.vfs_label(path.gsub('/dev/sda', device))}" } 272: guestfs.write_file('/boot/grub/grub.conf', grub, 0) 273: end 274: @log.debug "Done." 275: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 261 261: def use_labels_for_partitions(guestfs) 262: @log.debug "Using labels for partitions..." 263: device = guestfs.list_devices.first 264: 265: # /etc/fstab 266: if fstab = guestfs.read_file('/etc/fstab').gsub!(/^(\/dev\/sda.)/) { |path| "LABEL=#{guestfs.vfs_label(path.gsub('/dev/sda', device))}" } 267: guestfs.write_file('/etc/fstab', fstab, 0) 268: end 269: 270: # /boot/grub/grub.conf 271: if grub = guestfs.read_file('/boot/grub/grub.conf').gsub!(/(\/dev\/sda.)/) { |path| "LABEL=#{guestfs.vfs_label(path.gsub('/dev/sda', device))}" } 272: guestfs.write_file('/boot/grub/grub.conf', grub, 0) 273: end 274: @log.debug "Done." 275: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 37 37: def validate 38: set_default_config_value('format', 'raw') 39: end