lib/capitate/plugins/script.rb in capitate-0.2.3 vs lib/capitate/plugins/script.rb in capitate-0.2.5

- old
+ new

@@ -49,15 +49,12 @@ # def install(name, options, &block) build_dest = options[:build_dest] build_dest ||= "/tmp/#{name}" url = options[:url] - dependencies = options[:dependencies] - package.install(dependencies) if dependencies - - unpack(url, build_dest, options[:clean], options[:unpack_dir]) do |dir| + unpack(url, build_dest, options) do |dir| yield(dir) if block_given? end end @@ -83,41 +80,49 @@ run_via "mkdir -p #{File.dirname(dest)}" put template.load(script), dest end # If want verbose, -v - run_via "sh -v #{dest} && rm -rf #{File.dirname(dest)}" + run_all <<-CMDS + sh -v #{dest} + rm -rf #{File.dirname(dest)} + CMDS end # Download and unpack URL. # Yields path to unpacked source. # # ==== Options # +url+:: URL to download # +dest+:: Destination directory - # +clean+:: If true will remove the unpacked directory - # +unpack_dir+:: Directory that is unpacked from tgz (if not matching the file name) + # +options+:: + # - +clean+:: If true will remove the unpacked directory. _Defaults to true_ + # - +unpack_dir+:: Directory that is unpacked from tgz (if not matching the file name) # # ==== Examples # script.unpack("http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz", "/tmp/rubygems") do # sudo "ruby setup.rb" # end # - def unpack(url, dest, clean = true, unpack_dir = nil, &block) + def unpack(url, dest, options, &block) file = url.split("/").last # TODO: Support other types if file !~ /\.tar\.gz\Z|\.tgz\Z/ raise "Can't unpack this file: #{file}; only support tar.gz and tgz formats" end + options[:clean] = true if options[:clean].nil? + unpack_dir = options[:unpack_dir] + clean = options[:clean] + unpack_dir ||= file.gsub(/\.tar\.gz|\.tgz/, "") http_get_method = fetch(:http_get_method, "wget -nv") - + run_all <<-CMDS - mkdir -p #{dest} && cd #{dest} && #{http_get_method} #{url} + sh -c "mkdir -p #{dest} && cd #{dest} && #{http_get_method} #{url}" sh -c "cd #{dest} && tar zxf #{file}" CMDS if block_given? yield("#{dest}/#{unpack_dir}") @@ -131,13 +136,12 @@ # # ==== Options # +cmds+:: Commands (separated by newlines) # +options+:: See invoke_command options # - def run_all(cmds, options = {}, &block) + def run_all(cmds, options = {}, &block) cmds.split("\n").each do |cmd| - cmd = cmd.gsub(/^\s+/, "") - #sh_cmd = %{sh -c "#{cmd.gsub("\"", "\"\"")}"} + cmd = cmd.gsub(/^\s+/, "") run_via(cmd, options, &block) end end end \ No newline at end of file