2010-05-17

sudo in Debian squeeze

Debian squeeze creates an advanced config file for sudo package. File contains the following lines:

%sudo ALL=(ALL) ALL
#includedir /etc/sudoers.d


The first one allows all users from sudo group to do everything they want and the second one demonstrates a way to create a flexible sudo configuration.

2010-05-12

Unattended shutdown

My notebook seems to have a hardware defect. It might self power on after being powered off for some time.
This bug quickly degrades the battery making me recharge it too often. To prevent the system from discharging the battery I've wrote the following startup script:

#!/bin/sh

### BEGIN INIT INFO
# Provides: haltIfNousers
# Required-Start:
# Required-Stop:
# Should-Start: gdm
# Default-Start: 2 3
# Default-Stop: 4 5
# Short-Description: Execute the halt command.
# Description:
### END INIT INFO

#Powers off the system if no user is logged in in 30 seconds

BLOCK_FILE=/tmp/haltIfNousers

case "$1" in
start)
$0 wait &
;;
wait)
touch "$BLOCK_FILE"
sleep 30
[ -e "$BLOCK_FILE" ] || exit 0
if ! who|grep '.*' -q ; then
echo $0: No users are logged in. Halting now.
shutdown -h now
exit 0
fi
rm -f "$BLOCK_FILE"
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
rm -f "$BLOCK_FILE"
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac


This script checks if a user is logged on in 30 seconds after system boot and if he is not, shuts the system down.

Commented lines at the top of the script are Debian LSB header that drives its new dependecy based boot system. This header requests starting the script after gdb making measured time interval for user to login more precise.