#!/bin/sh
#
# switch-xconfig.sh
#
# Switches between different x11 configurations
# (e.g. radeon or fglrx drier)
#
# Call with config name as first option:
# Save configurations under "/etc/X11/XF86Config.NAME"
#
# When called with "bootparam", it will read the
# x11 configuration profile from the boot prompt
#
# Stefan Tomanek
# stefan@pico.ruhr.de

# Your X11 config file
# (a symlink to the real file)
BASECONFIG="/etc/X11/XF86Config-4"

# Kernel parameter supplied at boot prompt
# e.g. "xconfig=radeon"
OPT="xconfig"

# Parameter
CONFIG="$1";

if [ "$CONFIG" == "" ]; then
	echo "Available configurations:"
	ls $BASECONFIG.* | cut -d. -f 2-
elif [ "$CONFIG" == "bootparam" ]; then
	# Retrieve boot parameter
	KPARAM="$(grep "$OPT" /proc/cmdline | sed 's/^.*'$OPT'=\([^ ]*\).*$/\1/g')"
	if [ "$KPARAM" != "" ]; then
		$0 $KPARAM
	fi
else
	if [ -L "$BASECONFIG" ]; then
		if [ -e "$BASECONFIG.$CONFIG" ]; then
			echo "Linking $BASECONFIG.$CONFIG to $BASECONFIG"
			ln -sf $BASECONFIG.$CONFIG $BASECONFIG
		else
			echo "Config $BASECONFIG.$CONFIG not found"
		fi
	else
		echo "$BASECONFIG is not a symlink!"
	fi

fi

