My changeConfiguration.sh script to change single- and dual-monitor and network configurations
Monday, December 31st, 2007My old notebook Fujitsu-Siemens Lifebook S7010 drove an Intel graphics card whose driver wasn’t able to detect the plugging of external monitors. So I wrote a little script to switch my xorg.conf file:
#!/bin/sh if diff /etc/X11/xorg.conf /etc/X11/xorg.conf.single >/dev/null 2>&1 then sudo cp /etc/X11/xorg.conf.dual /etc/X11/xorg.conf echo 'monitor: dual' else sudo cp /etc/X11/xorg.conf.single /etc/X11/xorg.conf echo 'monitor: single' fi
It is also possible to switch between different network configurations. The reason for me was that I was able to use LAN in the office and use WLAN at home. Just append this to your changeConfiguration.sh:
if diff /etc/network/interfaces /etc/network/interfaces.home >/dev/null 2>&1 then sudo ifdown eth0 sudo ifdown eth1 sudo cp /etc/network/interfaces.office /etc/network/interfaces sudo ifup eth0 sudo cp /etc/resolv.conf.office /etc/resolv.conf echo 'network: office' else sudo ifdown eth0 sudo ifdown eth1 sudo cp /etc/network/interfaces.home /etc/network/interfaces sudo ifup eth1 sudo cp /etc/resolv.conf.home /etc/resolv.conf echo 'network: home' fi
Now, how does this work? First, create configuration files for each setup in the appropriate folders. In the first example it is /etc/X11/xorg.conf.single and /etc/X11/xorg.conf.dual, in the second example it is /etc/network/interfaces.office, /etc/network/interfaces.home, /etc/resolv.conf.home and /etc/resolv.conf.office. Put your configuration into these files.
This is no catch-it-all-script, you have to switch to another terminal screen (e.g. Ctrl + Alt + F2) and call the script: sh changeConfiguration.sh. It will tell you if you are driving single- or dual-screen and which network configuration you’ll use. Restart your X-server after calling.