lib/beaker/host/unix/exec.rb
#Add the provided key/val to the current ssh environment
#@param [String] key The key to add the value to
#@param [String] val The value for the key
#@example
#  host.add_env_var('PATH', '/usr/bin:PATH')
Add the provided key/val to the current ssh environment
Add the provided key / val to the current ssh environment
def add_env_var key, val
    key = key.to_s
    env_file = self[:ssh_env_file]
    escaped_val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
    if exec(Beaker::Command.new("grep ^#{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true ).exit_code == 0
      return 
    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
    mirror_env_to_profile_d(env_file)
  end
def add_env_var key , val key = key . to_s env_file = self [ :ssh_env_file ] escaped_val = Regexp . escape ( val ) . gsub ( '/' , '\/' ) . gsub ( ';' , '\;' ) if exec ( Beaker :: Command . new ( "grep ^#{key}=.*#{escaped_val} #{env_file}" ) , :accept_all_exit_codes => true ) . exit_code == 0 return 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 mirror_env_to_profile_d ( env_file ) end
Add the provided key/val to the current ssh environment
Add the provided key / val to the current ssh environment
#see if the key/value pair already exists #nothing to do here, key value pair already exists #see if the key already exists #update the profile.d to current state #match it to the contents of ssh_env_file
key
val
val The value for the key
val The value for the key
example
None