# Copyright (C) 2011-2012 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class BuildConfigurator include Configurator register :build description 'Builds a repository using the ./configure, make, make install commands' settings :path => 'Path to source files', :tarball_url => 'URL to source code tarball to be downloaded, supports .tgz and .zip', :tarball_dir => 'Name of directory created when untaring tarball, required if "tarball_url" is set', :pre_step => 'Command ran prior to ./configure', :message => 'Progress message to display if any while building', :configure_opts => 'Hash of options to be given to the configure script. ' + 'The keys are the platform families (:darwin, :linux or :windows)' validate_has_settings :path # No way to check, return false # # === Return # false:: Always return false def check_linux false end alias :check_darwin :check_linux alias :check_windows :check_linux # Run command line # # === Return # true:: Always return true def run_linux if tarball_url && tarball_dir.nil? report_fatal("tarball_url is specified (#{tarball_url.inspect}) but tarball_dir is missing") end report_check message if message Command.execute('mkdir', '-p', path, :abort_on_failure => "Failed to create #{path}") if tarball_url Dir.chdir(path) do filename = File.basename(tarball_url) unless File.exists?(File.join(Dir.pwd, filename)) Command.execute('curl', '-O', '-f', tarball_url, :abort_on_failure => "Failed to curl #{tarball_url}") end abf = { :abort_on_failure => "Failed to uncompress #{filename}" } case filename when /\.tar\.gz$|\.tgz$/ then Command.execute('tar', '-xzvf', filename, abf) when /\.zip$/ then Command.execute('unzip', filename, abf) when /\.gzip$/ then Command.execute('gunzip', filename, abf) else report_fatal("Unknown file extension #{File.extname(filename)}") end path File.join(path, tarball_dir) if !File.directory?(path) report_fatal("Could not find tarball dir #{tarball_dir.inspect} after untaring #{filename}") end end end Dir.chdir(path) do Command.execute(*command_args(pre_step)) if pre_step opts = configure_opts && configure_opts[Platform.family] Command.execute(*command_args("./configure #{opts}")) Command.execute(*command_args('make')) report_success report("Please enter you password to run the install step") Command.sudo('echo') report_check 'Installing' Command.sudo(*command_args('make install')) end report_success if message true end alias :run_darwin :run_linux # Run command line on Windows # # === Return # true:: Always return true def run_windows true # TBD end protected # Build arguments for Command.execute from command line # # === Arguments # command(String):: Command line to run # # === Return # args(Array):: Array of arguments to be passed to Command.execute def command_args(command) args = command.split(' ').compact args += [ { :abort_on_failure => "Failed to run #{command.rstrip}" } ] end end end