You are not logged in.
Pages: 1
Hi all, I'm in trying to implement a bash script to automagically detect which video driver the computer has and then provide a bare minimum xorg.conf file with the correct detected video driver. I'm not a good coder but I've come up with this:
#!/bin/bash
lspci | grep "VGA" | awk '{print $5}' > /tmp/videodriver
XDRIVER=$(cat /tmp/videodriver)
if [ "$XDRIVER" == "Intel" ]
then
XDRIVER=i810
MANUFACTURER="Intel Corporation"
fi
if [ "$XDRIVER" == "nVidia" ]
then
XDRIVER=nv
MANUFACTURER="nVidia Corporation"
fi
if [ "$XDRIVER" == "ATI" ]
then
XDRIVER=ati
MANUFACTURER="ATI Technologies Inc"
fi
if [ "$XDRIVER" == "" ]
then
XDRIVER=vesa
MANUFACTURER="VESA Capable"
fi
echo "Found a" $MANUFACTURER "device. Will try to use the" $XDRIVER "driver."
cp -v /etc/X11/xorg.$XDRIVER /etc/X11/xorg.conf
I'm hoping to hear some suggestions or possible improvements. One downside I find in this is that I have to already have the xorg.<name> files built, and the most perfect solution would be to create a generic one and then overwrite the driver section(don't know yet how to do this). I've found raymano's script but unfortunately hwd isn't working for me so I'm trying this way. Thank you.
There is no knowledge that is not power!
Offline
look at sed -i this will allow inline editing.
As for generating, I can only think of X -configure and copy it across though I generally find this actually detects my system very well and wouldn't need the editing.
Plus arch has hwdetect got a feeling this or a variant can generate a xorg file.
Edit its
hwd -xa from beginners guide have no experience with it though.
Last edited by FeatherMonkey (2007-11-20 19:54:36)
Offline
hwd is outdated so it no longer works so that wont help him much. It can't even detect the latest xorg-server. The best thing to run is "X -configure" since it works flawlessly.
Last edited by szlend (2007-11-20 20:21:14)
Offline
I would recommend something like this:
#!/bin/sh
VENDOR=$(lspci | grep "VGA" | awk '{print $5}')
case "$VENDOR" in
Intel)
XDRIVER="i810"
MANUFACTURER="Intel Corporation"
;;
nVidia)
XDRIVER="nv"
MANUFACTURER="nVidia Corporation"
;;
ATI)
XDRIVER="ati"
MANUFACTURER="ATI Technologies Inc"
;;
*)
XDRIVER="vesa"
MANUFACTURER="VESA-capable"
;;
esac
echo "Found a $MANUFACTURER device, will try to use the $XDRIVER driver."
[ -e /etc/X11/xorg.conf ] && mv /etc/X11/xorg.conf /etc/X11/xorg.conf.orig
ln -sf /etc/X11/xorg.$XDRIVER /etc/X11/xorg.conf
You might also want to check out the Bash Programming HOWTO and the Advanced Bash Scripting Guide.
Offline
hwd is outdated so it no longer works so that wont help him much.
I am upgrading hwd by replacing the lshwd hardware detect engine with lspci (pciutils) and lsusb (usbutils). Version 5.0 will be released soon.
For the Xorg PCI device/driver list hwd will use this table:
http://www.calel.org/pci-devices/xorg-device-list.html
Markku
Offline
Just to show what a scripting guru I am
awk '/VGA/ {print $5}'
and you don't need grep anymore.
Offline
awk '/VGA/ {print $5}'
While we're at it:
sed -n '/VGA/s#.*: \(\w*\).*#\1#p'
Offline
Yeah, great for showing up! Actually I wanted to help a little, the guru thing was a joke (obviously I hope).
Now I'm really curious, which one would you use and why?
Offline
Actually, awk is a lot more powerful and you could write the entire thing as a single awk script (as opposed to just using it for getting the xth element of an lspci line).
Try this out:
lspci | awk '/VGA/ {
if ($5 == "nVidia") {
manuf="Nvidia corp"
xdriv="nv" }
if ($5 == "Intel") {
manuf="Intel corp"
xdriv="i810" }
print "Found a", manuf, "will use", xdriv, "driver."
system("echo copy copy, move move, symlink symlink " xdriv " " xdriv) }'
This shouldn't be hard to finish into the same program.
Offline
Man this scriptin' is way ahead for me...
There is no knowledge that is not power!
Offline
Nothing the UNIX Grymoire can't fix.
Offline
woo! i'll never use sed again... awk for teh win! kill sed!
KISS = "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience." - Albert Einstein
Offline
Don't kill it, have mercy!
Take some time to browse beginning from http://sed.sourceforge.net/#docs. If you don't have the time, http://sed.sourceforge.net/sed1line.txt may provide some nice short-cuts.
Offline
well, the grymoire has a nice sed page too:
Anyhow, sed is a marvelous utility. Unfortunately, most people never learn its real power.
this makes it sound like vi (or emacs, but I don't use emacs )
Last edited by lloeki (2007-11-23 14:04:58)
To know recursion, you must first know recursion.
Offline
he should add a paragraph to that sentence
Anyhow, sed is a marvelous utility. Unfortunately, most people never learn its real power. [...] Because it's pretty much the model example of un-newbiefriendlyness
awk i got preeeety fast though
Last edited by test1000 (2007-11-23 15:53:23)
KISS = "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience." - Albert Einstein
Offline
well, read this small paragraph and you will get to know why
that said, sed is pretty simple to use and learn actually (and the grymoire really helps in that matter), it's just that the documentation is completely useless unless you know what it means (which defeats the whole point of a documentation)
To know recursion, you must first know recursion.
Offline
lcpci -nn
01:00.0 VGA compatible controller [0300]: ATI Technologies Inc Radeon Mobility X1400 [1002:7145]
03:00.0 Ethernet controller [0200]: Broadcom Corporation BCM4401-B0 100Base-TX [14e4:170c] (rev 02)
03:01.0 FireWire (IEEE 1394) [0c00]: Ricoh Co Ltd R5C832 IEEE 1394 Controller [1180:0832]
03:01.1 SD Host controller [0805]: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter [1180:0822] (rev 19)
03:01.2 System peripheral [0880]: Ricoh Co Ltd R5C843 MMC Host Controller [1180:0843] (rev 01)
0c:00.0 Network controller [0280]: Intel Corporation PRO/Wireless 3945ABG Network Connection [8086:4222] (rev 02)
For my information, to improve the script in hwd, what would be an accurate syntax to grep/awk the id number e.g. 8086:4222 of Network controller
ID=$(lspci -nn | .......
Markku
Offline
Maybe using "lspci -mn" would be a better idea. See "MACHINE READABLE OUTPUT" in lspci man.
Offline
This I also thought. Whoever developed pciutils didn't keep the same format in both -nn and -mnn, split the vendor and device ids and merged in the descriptions.
lspci -nn
0c:00.0 Network controller [0280]: Intel Corporation PRO/Wireless 3945ABG Network Connection [8086:4222] (rev 02)
lspci -mnn
0c:00.0 "Network controller [0280]" "Intel Corporation [8086]" "PRO/Wireless 3945ABG Network Connection [4222]" -r02 "Intel Corporation [8086]" "Unknown device [1021]"
This is what I have in mind. But "[ ]" is not unique character when some hardwares use it in the description.
lspci -nn | awk /Network/ | sed 's/\[/"/g' | sed 's/\]/"/g' | awk -F\" '{print $4}'
Markku
Offline
Pages: 1