Back to my homepagegerman
Did this site help you?
Average rating (Scripts):
2.87/3 (47 votes)

Stefan's Script Collection

...useful scripts I collected

Here you can find various scripts I consider useful; feel free to use them with your own system.

lidlock.sh

The Script Lidlock.sh locks your X-Session using "xlock" or "xscreensaver" when the lid of the notebook is closed. If you are on battery power, the script will just blank your screen, while it will enable the fancy savers when you are on AC. The configuration is taken from Debian GNU/Linux "Sarge", just add a line (marked red) to call lidlock.sh with all parameters. Lidlock.sh checks for a user running X11 on your notebook, then tries to locate a running Xscreensaver-Daemon. If you are running Xscreensaver, lidlock.sh disables the graphical savers (you wouldn't see them anyway with your notebook closed) and locks your screen. If you reopen your notebook, the script will reenable the funky screensavers, so you will be greeted by Xscreensaver in all its glory without graphical savers having wasted your precious battery while your lid was closed.

#!/bin/sh
#
#
# by Stefan Tomanek stefan@pico.ruhr.de
#
# Call this script from your acpi setup

LINE="$(who | egrep '^\w+[[:space:]]+:[[:digit:]]+[[:space:]]+')"
USER="$(echo $LINE | awk '{print $1}')"
DISPLAY="$(echo $LINE | awk '{print $2}')"
if grep "closed" /proc/acpi/button/lid/$2/state ; then
	if [ "$LINE" != ""  ]; then
		# Are we running xscreensaver?
		if pgrep -U $USER -x xscreensaver; then
		    # Disable all graphical savers and lock display
		    su $USER -c "xscreensaver-command -display $DISPLAY -throttle"
		    su $USER -c "xscreensaver-command -display $DISPLAY -lock"
		else
		    # We are not running xscreensaver, we'll use xlock
		    
		    # if we only have battery power, just blank the
		    # screen to save energy
		    MODE="-mode blank"
		    # Check whether we are on AC
		    if grep on-line /proc/acpi/ac_adapter/*/state; then
			    # We have permanent power, enable funky savers
			    MODE=""
		    fi
		    su $USER -c "xlock $MODE -display $DISPLAY"
		fi
	fi
else
    # The lid just opened
    # Are we running xscreensaver?
    # We can enable the nice savers now
    if pgrep -U $USER -x xscreensaver; then
	su $USER -c "xscreensaver-command -display $DISPLAY -unthrottle"
    fi
fi
(last modified: Tuesday, 05-Jul-2005 22:00:38 CEST)
/etc/acpi/events/lm_lid
event=button[ /]lid
action=/etc/acpi/actions/lm_lid.sh %e
/etc/acpi/actions/lm_lid.sh
#!/bin/bash

/etc/acpi/lidlock.sh $*

[...]

switch-xconfig.sh

The script switch-xconfig.sh switches between different X11 configurations. It simply links the file /etc/X11/XF86Config-4 against one of the real configuration files. You can integrate it into your boot scripts, and supply the parameter xconfig=NAME at the lilo or grub command line. Call the script with "bootparam" as first argument, and it will prepare the desired configuration.

#!/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

wifichoice.sh

Wifichoice automatically selects the right network profile for your wlan card. For more information - and of course the script - see my Debian networking page.