lib/capitate/plugins/script.rb in capitate-0.1.9 vs lib/capitate/plugins/script.rb in capitate-0.2.1
- old
+ new
@@ -14,13 +14,16 @@
# script.make_install("nginx", { :url => "http://sysoev.ru/nginx/nginx-0.5.35.tar.gz", ... })
#
def make_install(name, options)
install(name, options) do |dir|
configure_options = options[:configure_options] || ""
- sudo "echo 'Configuring #{name}...' && cd #{dir} && ./configure #{configure_options} > configure.log"
- sudo "echo 'Compiling #{name}...' && cd #{dir} && make > make.log"
- sudo "echo 'Installing #{name}...' && cd #{dir} && make install > make_install.log"
+
+ run_all <<-CMDS
+ echo 'Configuring #{name}...' && cd #{dir} && ./configure #{configure_options} > configure.log
+ echo 'Compiling #{name}...' && cd #{dir} && make > make.log
+ echo 'Installing #{name}...' && cd #{dir} && make install > make_install.log
+ CMDS
end
end
# Download, unpack and yield (unpacked source director).
#
@@ -60,25 +63,22 @@
#
def sh(script, override_binding = nil)
if File.extname(script) == ".erb"
name = script[0...script.length-4]
- dest = "/tmp/#{name}"
- run "mkdir -p #{File.dirname(dest)}"
+ dest = "/tmp/cap/#{name}"
+ run_via "mkdir -p #{File.dirname(dest)}"
put template.load(script, override_binding || binding), dest
else
name = script
- dest = "/tmp/#{name}"
- run "mkdir -p #{File.dirname(dest)}"
+ dest = "/tmp/cap/#{name}"
+ run_via "mkdir -p #{File.dirname(dest)}"
put template.load(script), dest
end
# If want verbose, -v
- sudo "sh -v #{dest}"
-
- # Cleanup
- sudo "rm -rf #{File.dirname(dest)}"
+ run_via "sh -v #{dest} && rm -rf #{File.dirname(dest)}"
end
# Download and unpack URL.
# Yields path to unpacked source.
#
@@ -101,17 +101,31 @@
raise "Can't unpack this file: #{file}; only support tar.gz and tgz formats"
end
unpack_dir ||= file.gsub(/\.tar\.gz|\.tgz/, "")
- sudo "echo 'Getting #{url}...' && mkdir -p #{dest} && cd #{dest} && wget -nv #{url}"
- sudo "echo 'Unpacking...' && cd #{dest} && tar zxf #{file}"
+ run_all <<-CMDS
+ echo 'Getting #{url}...' && mkdir -p #{dest} && cd #{dest} && wget -nv #{url}
+ echo 'Unpacking...' && cd #{dest} && tar zxf #{file}
+ CMDS
if block_given?
yield("#{dest}/#{unpack_dir}")
- sudo "rm -f #{dest}/#{file}"
- sudo "rm -rf #{dest}" if clean
+ run_via "rm -f #{dest}/#{file}"
+ run_via "rm -rf #{dest}" if clean
end
+ end
+
+ # Run all commands (separated by newlines)
+ #
+ # ==== Options
+ # +cmds+:: Commands (separated by newlines)
+ # +options+:: See invoke_command options
+ #
+ def run_all(cmds, options = {}, &block)
+ cmds.split("\n").each do |cmd|
+ run_via(cmd, options, &block)
+ end
end
end
Capistrano.plugin :script, Capitate::Plugins::Script
\ No newline at end of file