Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. module System
  2.  
  3. def add_env_var(variable, path)
  4. envfile = "/etc/profile.d/99generic.sh"
  5. foundvar = false
  6. arr = IO.readlines( envfile ) if File::exists?( envfile )
  7. length = arr.length - 1
  8.  
  9. for i in 0..length
  10. if arr[i][variable] then
  11. line = arr[i].chomp.split( '=' )
  12. paths = line[1].split( ':' ) << path
  13. arr[i] = line[0] + "=" + paths.uniq.join( ':' ) + "\n"
  14. foundvar = true
  15. break
  16. end
  17. end
  18.  
  19. if !foundvar then
  20. arr << "export #{variable}=#{path}"
  21. end
  22.  
  23. aFile = File.new( envfile, "w" )
  24. aFile.syswrite( "#{arr.flatten}" )
  25. end
  26. end
Add Comment
Please, Sign In to add comment