Shutdown.sh

Aus VDR Wiki
Version vom 21. April 2006, 23:50 Uhr von 84.186.41.49 (Diskussion)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Vorschlag für ein einfaches Shutdown-Skript.

Datei
$PATH/shutdown.sh
#!/bin/bash
#
# shutdown.sh

# wake up method ('off','acpi','nvram','suspend')
WAKEUP_METHOD="off"

# read board configuration from specified configuration file (e.g: "/etc/nvram-wakeup.conf")
NVRAM_CONFIG=""

# specify the iw (infowriter) name. (e.g: gigabyte_5aa)
NVRAM_IWNAME=""

# try "nvram-wakeup --help"
NVRAM_OPT="--syslog"

# Which boot manager are you using, only for nvram? (grub/lilo)
BOOT_MANAGER="grub"

TIMER=$1
LILOCNF=/etc/lilo.conf
GRUBCNF=/boot/grub/menu.lst
ACPIALARM=/proc/acpi/alarm

case ${#TIMER}-${WAKEUP_METHOD:-off} in
     10-acpi)
	test -e $ACPIALARM
	case $? in
	     0) date -d "1970-01-01 UTC $((TIMER-120)) seconds" +"%Y-%m-%d %R:%S" > $ACPIALARM
		sudo poweroff
		exit 0
		;;
	     *) logger -t ${0##*/} "ARG -> missing $ACPIALARM"
		;;
	esac
	;;
     10-nvram)
	test -e /dev/nvram -a -e /dev/rtc -a -e /dev/mem
	case $? in
	     0) which nvram-wakeup >/dev/null 2>&1
		case $? in
		     0) IWNAME="${NVRAM_IWNAME/*[unknown, ]*}"
			sudo nvram-wakeup -s $TIMER $NVRAM_OPT ${NVRAM_CONFIG:+-C $NVRAM_CONFIG} ${IWNAME:+-I $IWNAME}
			case ${BOOT_MANAGER:-lilo} in
			     grub) REBOOT_LINE=`grep -s ^title "$GRUBCNF" | grep -i -n poweroff | { IFS=: read a b ; echo $a ; }`
				   test -n "$REBOOT_LINE"
				   case $? in
					0) which grub-set-default >/dev/null 2>&1
					   case $? in
						0) sudo grub-set-default $((REBOOT_LINE-1))
						   ;;
						*) echo -e "savedefault --default=$((REBOOT_LINE-1)) --once\nquit" | sudo grub --batch
						   ;;
					   esac
					   ;;
					*) logger -t ${0##*/} "ARG -> missing poweroff entry in $GRUBCNF"
					   ;;
				   esac
				   ;;
			     lilo) REBOOT_ENTRY=`grep -s -i label.*poweroff "$LILOCNF" | { IFS== read a b ; echo $b ; }`
				   test -n "$REBOOT_ENTRY"
				   case $? in
					0) sudo lilo -R $REBOOT_ENTRY
					   ;;
					*) logger -t ${0##*/} "ARG -> missing poweroff entry in $LILOCNF"
					   ;;
				   esac
				   ;;
			esac
			sudo shutdown -r now
			exit 0
			;;
		     *) logger -t ${0##*/} "ARG -> missing nvram-wakeup"
			;;
		esac
		;;
	     *) logger -t ${0##*/} "ARG -> missing /dev/nvram -o /dev/rtc -o /dev/mem"
		;;
	esac
	;;
     10-suspend)
	test -e $ACPIALARM -a -e /sys/power/state
	case $? in
	     0) date -d "1970-01-01 UTC $((TIMER-30)) seconds" +"%Y-%m-%d %R:%S" > $ACPIALARM
		echo mem > /sys/power/state
		sudo reboot
		exit 0
		;;
	     *) logger -t ${0##*/} "ARG -> missing $ACPIALARM -o /sys/power/state"
		;;
	esac
	;;
     10-off)
	logger -t ${0##*/} "MESG -> no wakeup method"
	;;
     1-*)
	logger -t ${0##*/} "MESG -> no timer"
	;;
esac

sudo shutdown -h now
exit $?


Ergänzung für LILO

Datei
/etc/lilo.conf
...

label  = PowerOff
image  = /boot/bzImage.poweroff


Ergänzung für GRUB

Datei
/boot/grub/menu.lst
...
title           PowerOff
root            (hd0,0)
kernel          /boot/bzImage.poweroff