Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module System
- def add_env_var(variable, path)
- envfile = "/etc/profile.d/99generic.sh"
- foundvar = false
- arr = IO.readlines( envfile ) if File::exists?( envfile )
- length = arr.length - 1
- for i in 0..length
- if arr[i][variable] then
- line = arr[i].chomp.split( '=' )
- paths = line[1].split( ':' ) << path
- arr[i] = line[0] + "=" + paths.uniq.join( ':' ) + "\n"
- foundvar = true
- break
- end
- end
- if !foundvar then
- arr << "export #{variable}=#{path}"
- end
- aFile = File.new( envfile, "w" )
- aFile.syswrite( "#{arr.flatten}" )
- end
- end
Add Comment
Please, Sign In to add comment