Skip to content

Instantly share code, notes, and snippets.

@rcreasey
Created January 12, 2010 22:13
Show Gist options
  • Select an option

  • Save rcreasey/275679 to your computer and use it in GitHub Desktop.

Select an option

Save rcreasey/275679 to your computer and use it in GitHub Desktop.
define :source_package do
source_root = "/export/source"
build_root = "/export/builds"
build_directory = "#{build_root}/#{$1}" if params[:filename] =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tb2)/
[source_root, build_root].each do |r|
directory r do
mode 0755
action :create
not_if { File.directory?( r ) }
end
end
# fetch remote file
remote_file "#{source_root}/#{params[:filename]}" do
source "#{params[:location]}/#{params[:filename]}"
not_if { File.exists?( "#{source_root}/#{params[:filename]}" ) }
end
# extract file
extract_command = case params[:filename]
when /(tar.gz)|(tgz)$/
'tar xzf'
when /(tar.bz2)|(tb2)$/
'tar xjf'
when /tar$/
'tar xf'
when /zip$/
'unzip'
else
raise "Unknown source archive format: #{archive_name}"
end
extract_command << " #{source_root}/#{params[:filename]} -C #{build_root}"
# decide what to configure
configure_options = "./configure --prefix=#{params[:prefix]} "
unless params[:configure].nil? or params[:configure][:with].nil?
params[:configure][:enable] = params[:configure][:enable].compact.reject {|s| s.empty?}
configure_options << params[:configure][:with].map {|o| "--with-#{o} "}.join(' ')
end
unless params[:configure].nil? or params[:configure][:enable].nil?
params[:configure][:enable] = params[:configure][:enable].compact.reject {|s| s.empty?}
configure_options << params[:configure][:enable].map {|o| "--enable-#{o} " unless o.eql?('')}.join(' ')
end
# execute commands
execute "extracting and building #{params[:name]}" do
command [extract_command, "cd #{build_directory}", configure_options, "make", "make install"].join(' && ')
not_if { File.directory?( params[:prefix] ) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment