Hi,
I’m writing a little script for installing ati-drivers on linux machines
but I have a little problem. I need to change the /etc/X11/xorg.conf
file for this. This file is built like this (just a cut-out):
Now I need to change the driver value within the Section “Device” from
ati|vesa|radeon|nomatterwhat… to fglrx, but how to find it? E.g.
IO.foreach(’/etc/X11/xorg.conf’) { |line| puts line if line =~
/^Section “Device”/ } finds me the correct section but how to “navigate”
now in it? Is iteration at all the answer to this problem?
E.g. IO.foreach(’/etc/X11/xorg.conf’) { |line| puts line if line =~
/^Section “Device”/ } finds me the correct section but how to
“navigate” now in it? Is iteration at all the answer to this
problem?
I usually do something like this (where fh is my filehandle):
while line = fh.gets
flag = true if /Section “Device”/.match(line)
flag = false if flag && line.gsub!(/(Driver\s+)"(.*)"/,
‘\1"fglrx"’)
puts line
end
Hi,
I’m writing a little script for installing ati-drivers on linux machines
but I have a little problem. I need to change the /etc/X11/xorg.conf file
for this.
For what you’re trying to do, you could just read the file in as a
string,
use String#sub on it and write it to file again, but here is something a
little more fun (for me to write anyway): http://pastie.caboo.se/91056
Usage:
xconf=XConf.new “/etc/X11/xorg.conf”
xconf[“Device”][“Driver”]=‘“fglrx”’
xconf.write #This will backup the old config to /etc/X11/xorg.conf.old #or
xconf.write “new_config”
The new config won’t contain comments.
I just quickly hacked this up, so this isn’t thoroughly tested and may
contain
bugs (the above example works as it should, though, I tested that much).
There’s obviously some room for improvement here, but for the beginning
this seems decent enough.