Created
March 30, 2011 11:32
-
-
Save rubiojr/894242 to your computer and use it in GitHub Desktop.
Patch RHEL5 derived ISOs isolinux config file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'tmpdir' | |
require 'fileutils' | |
require 'thread' | |
def progress_loop(thread , msg = "Working... " , step_lag = 0.1) | |
$stdout.sync = true | |
line_reset = "\r\e[0K" + msg | |
while thread.status | |
print line_reset + "|" | |
sleep step_lag | |
print line_reset + "/" | |
sleep step_lag | |
print line_reset + "-" | |
sleep step_lag | |
print line_reset + '\\' | |
sleep step_lag | |
end | |
end | |
def patch_isolinux(iso, cfg, tmpdir = nil, debug = false) | |
tmpdir = Dir.mktmpdir if tmpdir.nil? | |
FileUtils.mkdir_p tmpdir + '/iso' | |
`mount -o loop #{iso} #{tmpdir}/iso` | |
if $? != 0 | |
$stderr.puts "ERROR: Mounting ISO (#{iso}) failed." | |
return false | |
end | |
begin | |
FileUtils.cp_r "#{tmpdir}/iso", "#{tmpdir}/newiso" | |
FileUtils.cp cfg, "#{tmpdir}/newiso/isolinux/isolinux.cfg" | |
isoout = File.basename(iso, File.extname(iso)) + '-patched.iso' | |
`mkisofs -R -J -T -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o #{isoout} #{tmpdir}/newiso > /dev/null 2>&1` | |
if $? != 0 | |
$stderr.puts "ERROR: mkisofs failed." | |
return false | |
end | |
rescue Exception => e | |
$stderr.puts "ERROR: #{e.message}" | |
return false | |
ensure | |
`umount #{tmpdir}/iso` | |
if not debug | |
FileUtils.rm_rf tmpdir + '/iso' | |
FileUtils.rm_rf tmpdir + '/newiso' | |
end | |
end | |
true | |
end | |
def usage | |
$stderr.puts """ | |
Usage: isolinux-patch isofile isolinux-cfg [tmpdir] | |
""" | |
end | |
iso = ARGV[0] | |
cfg = ARGV[1] | |
temp = ARGV[2] | |
if `whoami`.strip.chomp != 'root' | |
$stderr.puts 'Run this script as root.' | |
exit 1 | |
end | |
if iso.nil? or cfg.nil? | |
usage | |
exit 1 | |
end | |
if `which mkisofs`.strip.chomp.empty? | |
$stderr.puts "ERROR: mkisofs command not found." | |
exit | |
end | |
if not File.exist?(iso) | |
$stderr.puts "ERROR: #{iso} is not a valid file." | |
exit | |
end | |
if not File.exist?(cfg) | |
$stderr.puts "ERROR: #{cfg} is not a valid file." | |
end | |
t = Thread.new do | |
if not temp.nil? and File.directory?(temp) | |
patch_isolinux(iso, cfg, temp) | |
else | |
patch_isolinux(iso, cfg) | |
end | |
end | |
progress_loop t, "Patching ISO (this will take some time)... " | |
puts "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment