Method: Unix::Exec#add_env_var
- Defined in:
- lib/beaker/host/unix/exec.rb
#add_env_var(key, val) ⇒ Object
Add the provided key/val to the current ssh environment
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/beaker/host/unix/exec.rb', line 214 def add_env_var key, val key = key.to_s env_file = self[:ssh_env_file] escaped_val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;') # see if the key/value pair already exists if exec(Beaker::Command.new("grep ^#{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true).exit_code == 0 return # nothing to do here, key value pair already exists # see if the key already exists elsif exec(Beaker::Command.new("grep ^#{key}= #{env_file}"), :accept_all_exit_codes => true).exit_code == 0 exec(Beaker::SedCommand.new(self['platform'], "s/^#{key}=/#{key}=#{escaped_val}:/", env_file)) else exec(Beaker::Command.new("echo \"#{key}=#{val}\" >> #{env_file}")) end # update the profile.d to current state # match it to the contents of ssh_env_file mirror_env_to_profile_d(env_file) end |