#!/bin/sh # setres -- sets screen resolution for the X11 window system by reading # settings from the kernel command line # # this script was written in a way that allows easy adaptation to # other tasks. it is designed to move different configfiles into # place dependant on settings supplied at boot-time via the kernel # command line (see `cat /proc/cmdline` and your bootloader config). # # === SETUP === # this script should be used as an initscript in /etc/init.d/ and # thus called by the system when entering the appropriate runlevels. # configure your system to run it in runlevel 5 *before* X11 is started. # # note : you can use the `update-rc.d`-script under debian(-based) systems # to set this up like this: `update-rc.d setres start 11 5`. # # === USAGE === # this script reads the envvar $USEDISPLAY which should be defined on # the kernel command line in the usual 'var=value' syntax. # hint : set this up permanently in your bootloader. an example line for # the grub configfile /boot/grub/menu.lst follows : # # kernel /boot/linux-2.6.18.2 root=/dev/hda1 USEDISPLAY=external # # written by spirit, see http://www.sp1r1t.org/contact/ # license : this this is public domain => no copyrights, no shit, no warranty # (do whatever you want but don't blame me for what you do.) # ##### user settings - please adapt to your needs ##### ## the modes we implement (possible contents of the environment varibable) MODEA="internal" MODEB="external" ## the config files you may want to be moved CONFIG_USEDBYSRV="/etc/X11/XF86Config-4" CONFIG_MODEA="/etc/X11/XF86Config-4.internal" CONFIG_MODEB="/etc/X11/XF86Config-4.external" CONFIG_DEFAULT="/etc/X11/XF86Config-4.internal" CONFIG_BACKUP="/etc/X11/XF86Config-4.backup-by-setres" ##### other settings - you should not need to change these ##### ## name of this application NAME="setres" ENVVAR_NAME="\$USEDISPLAY" ## paths to some applications we use LOGGER="/usr/bin/logger -p user.info -t $NAME" CP="/bin/cp" ECHO="/bin/echo" ##### here we go - don't ouch anything below this line unless you know what you're doing ##### ## react to (or at least pretend to do so) stuff initscripts should react to case "$1" in start|restart|reload|force-reload) ## check for required files $ECHO "$NAME: checking for required files..." if [ ! -f "$CONFIG_MODEA" ]; then $ECHO "$NAME: ERROR: $CONFIG_MODEA not found" && exit 0; fi if [ ! -f "$CONFIG_MODEB" ]; then $ECHO "$NAME: ERROR: $CONFIG_MODEB not found" && exit 0; fi if [ ! -f "$CONFIG_DEFAULT" ]; then $ECHO "$NAME: ERROR: $CONFIG_DEFAULT not found" && exit 0; fi $ECHO "$NAME: all files seem to be there." ## check contents of variable supplied to us via kernel command line $ECHO "$NAME: reading settings from environment variable $ENVVAR_NAME: $USEDISPLAY" case "$USEDISPLAY" in $MODEA) $CP $CONFIG_USEDBYSRV $CONFIG_BACKUP $CP $CONFIG_MODEA $CONFIG_USEDBYSRV $ECHO "$NAME: configuring your system for mode $MODEA" $LOGGER "$NAME: configuring your system for mode $MODEA" ;; $MODEB) $CP $CONFIG_USEDBYSRV $CONFIG_BACKUP $CP $CONFIG_MODEB $CONFIG_USEDBYSRV $ECHO "$NAME: configuring you system for mode $MODEB" $LOGGER "$NAME: configuring you system for mode $MODEB" ;; *) $CP $CONFIG_USEDBYSRV $CONFIG_BACKUP $CP $CONFIG_DEFAULT $CONFIG_USEDBYSRV $ECHO "$NAME: WARNING: nothing suitable found in environment variable $ENVVAR_NAME." $ECHO "$NAME: WARNING: configuring your system for mode default" $LOGGER "$NAME: WARNING: nothing suitable found in environment variable $ENVVAR_NAME." $LOGGER "$NAME: WARNING: configuring your system for mode default" ;; esac ;; stop) $ECHO "$NAME: nothing to stop here." ;; manual) case "$2" in $MODEA) $CP $CONFIG_USEDBYSRV $CONFIG_BACKUP $CP $CONFIG_MODEA $CONFIG_USEDBYSRV $ECHO "$NAME: manual mode: configuring your system for mode $MODEA" ;; $MODEB) $CP $CONFIG_USEDBYSRV $CONFIG_BACKUP $CP $CONFIG_MODEB $CONFIG_USEDBYSRV $ECHO "$NAME: manual mode: configuring your system for mode $MODEB" ;; *) $ECHO "$NAME: manual mode: usage: $NAME manual {$MODEA|$MODEB}'" ;; esac ;; *) $ECHO "$NAME: don't know what to do, sorry. remember : i'm an init-script!" $ECHO "$NAME: usage : '$NAME {start|restart|reload|force-reload|stop}'" $ECHO "$NAME: usually this is what you want : '$NAME start'" $ECHO "$NAME:" $ECHO "$NAME: to make me ignore the environment variable $ENVVAR_NAME and invoke" $ECHO "$NAME: me manually type : '$NAME manual {$MODEA|$MODEB}'" $ECHO "$NAME: open me in a text editor for more info." ;; esac $ECHO "$NAME: done, exiting." exit 1