Module: Caterer::Util::Shell
- Included in:
- Provisioner::ChefSolo, Server
- Defined in:
- lib/caterer/util/shell.rb
Instance Method Summary collapse
- #bash(cmd) ⇒ Object
- #env(vars) ⇒ Object
- #env_string(key, val) ⇒ Object
-
#escape(cmd) ⇒ Object
strategy: 1- escape the escapes 2- escape quotes 3- escape dollar signs.
- #su(user, cmd) ⇒ Object
Instance Method Details
#bash(cmd) ⇒ Object
16 17 18 |
# File 'lib/caterer/util/shell.rb', line 16 def bash(cmd) "bash -c \"#{escape(cmd)}\"" end |
#env(vars) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/caterer/util/shell.rb', line 24 def env(vars) vars ||= {} env = '' vars.each do |key, val| env += " " if not env == '' env += env_string(key, val) end (env == '')? env : "#{env} " end |
#env_string(key, val) ⇒ Object
34 35 36 37 |
# File 'lib/caterer/util/shell.rb', line 34 def env_string(key, val) key = key.to_s if not key.is_a? String %Q{#{key.upcase}="#{escape(val)}"} end |
#escape(cmd) ⇒ Object
strategy: 1- escape the escapes 2- escape quotes 3- escape dollar signs
9 10 11 12 13 14 |
# File 'lib/caterer/util/shell.rb', line 9 def escape(cmd) cmd.gsub!(/\\/, "\\\\\\") cmd.gsub!(/"/, "\\\"") cmd.gsub!(/\$/, "\\$") cmd end |
#su(user, cmd) ⇒ Object
20 21 22 |
# File 'lib/caterer/util/shell.rb', line 20 def su(user, cmd) "su #{user} -l -c \"#{escape(cmd)}\"" end |