Skip to content

Instantly share code, notes, and snippets.

@kzk
Created June 9, 2011 06:14
Show Gist options
  • Save kzk/1016167 to your computer and use it in GitHub Desktop.
Save kzk/1016167 to your computer and use it in GitHub Desktop.
gen-installer.rb
require 'erb'
require 'optparse'
opts = {}
parser = OptionParser.new
parser.on('-i [INSTANCE]') { |v| in_rpm = v }
parser.on('-o [FILENAME]') { |v| out_bin = v }
parser.parse!(ARGV)
if in_rpm.nil? || out_bin.nil?
puts <<END
-i and -o option is required.
Usage:
./gen-installer.rb -i sedue-4.2.2-0.x86_64.rpm -o sedue-installer-4.2.2.bin
END
end
# generate script
script_template = <<END
#!/bin/sh
PATH=/usr/bin:/bin
umask 022
echo "Unpacking..."
rm -fR #{in_rpm}
tail -n +<%= nlines+1 %> ./#{out_bin} >#{in_rpm}
rpm -qlp #{in_rpm}
echo "Remove temporary files..."
rm -fR #{in_rpm}
echo " "
echo "Done."
exit 0
END
nlines = script_template.split(/\n/).length
erb = ERB.new(script_template)
script = erb.result(binding)
puts script
# concat script + binary
open("tmp-script.sh", 'w') { |f|
f.puts script
}
`cat tmp-script.sh #{in_rpm} > #{out_bin}`
`chmod +x ./#{out_bin}`
`rm -fR tmp-script.sh`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment