Module: Capitate::Plugins::Script
- Defined in:
- lib/capitate/plugins/script.rb
Instance Method Summary collapse
-
#run_all(cmds, options = {}, &block) ⇒ Object
Run all commands (separated by newlines).
-
#sh(script, override_binding = nil) ⇒ Object
Run (sh) script.
-
#unpack(url, dest, options, &block) ⇒ Object
Download and unpack URL.
Instance Method Details
#run_all(cmds, options = {}, &block) ⇒ Object
Run all commands (separated by newlines).
Uses run_via to execute, so will use run or sudo depending on the current :run_method
Options
cmds-
Commands (separated by newlines)
options-
See Capistrano invoke_command options
87 88 89 90 91 92 |
# File 'lib/capitate/plugins/script.rb', line 87 def run_all(cmds, = {}, &block) cmds.split("\n").each do |cmd| cmd = cmd.gsub(/^\s+/, "") run_via(cmd, , &block) end end |
#sh(script, override_binding = nil) ⇒ Object
Run (sh) script. If script has .erb extension it will evaluate it.
Options
script-
Name of sh file (relative to templates dir)
override_binding+-
Binding to override, otherwise defaults to current (task) context
Examples
script.sh("ruby/openssl_fix.sh")
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/capitate/plugins/script.rb', line 12 def sh(script, override_binding = nil) if File.extname(script) == ".erb" name = script[0...script.length-4] dest = "/tmp/cap/#{name}" run_via "mkdir -p #{File.dirname(dest)}" put template.load(script, override_binding || binding), dest else name = script dest = "/tmp/cap/#{name}" run_via "mkdir -p #{File.dirname(dest)}" put template.load(script), dest end # If want verbose, -v run_all <<-CMDS sh -v #{dest} rm -rf #{File.dirname(dest)} CMDS end |
#unpack(url, dest, options, &block) ⇒ Object
Download and unpack URL. Yields path to unpacked source.
Options
url-
URL to download
dest-
Destination directory
options-
Options (see Unpack options)
Unpack 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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/capitate/plugins/script.rb', line 50 def unpack(url, dest, , &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 [:clean] = true if [:clean].nil? unpack_dir = [:unpack_dir] clean = [:clean] unpack_dir ||= file.gsub(/\.tar\.gz|\.tgz/, "") http_get_method = fetch(:http_get_method, "wget -nv") run_all <<-CMDS 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}") run_via "rm -f #{dest}/#{file}" run_via "rm -rf #{dest}" if clean end end |