#!/sbin/runscript # Gentoo users: add this script to 'boot' run level. # ================================================== # # Copyright (c) by Georg Lippold # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ChangeLog: # # 2006.03.03 - Georg Lippold: Found out that if you want the server to wake up # later the same day with the conffile, that it takes the next day instead of # the same day. Fixed that. # # 2006.03.02 - Georg Lippold: initial version WAKEUP=/usr/bin/nvram-wakeup CONFFILE=/etc/powerup depend() { need localmount before clock } start() { if [[ -x $WAKEUP ]] && [[ -s $CONFFILE ]] ; then ebegin "Setting startup time" TODAY="`date +%u`" TIMETODAY="`grep ^$TODAY $CONFFILE | tail -n 1 | awk '{print $2}'`" SECONDTODAY=`date +%s -d "$TIMETODAY"` if [[ `date +%s` -lt $SECONDTODAY ]] ; then $WAKEUP -s $SECONDTODAY eend 0 else TOMORROW="`date +%u -d tomorrow`" TIMETOMORROW="`grep ^$TOMORROW $CONFFILE | tail -n 1 | awk '{print $2}'`" SECONDTOMORROW=`date +%s -d "$TIMETOMORROW tomorrow"` $WAKEUP -s $SECONDTOMORROW eend 0 fi else eerror "Not setting new start date, $WAKEUP or $CONFFILE does not exist" eend 1 fi } stop() { if [[ -x $WAKEUP ]] && [[ -s $CONFFILE ]] ; then ebegin "Setting startup time" TODAY="`date +%u`" TIMETODAY="`grep ^$TODAY $CONFFILE | tail -n 1 | awk '{print $2}'`" SECONDTODAY=`date +%s -d "$TIMETODAY"` if [[ `date +%s` -lt $SECONDTODAY ]] ; then $WAKEUP -s $SECONDTODAY eend 0 else TOMORROW="`date +%u -d tomorrow`" TIMETOMORROW="`grep ^$TOMORROW $CONFFILE | tail -n 1 | awk '{print $2}'`" SECONDTOMORROW=`date +%s -d "$TIMETOMORROW tomorrow"` $WAKEUP -s $SECONDTOMORROW eend 0 fi else eerror "Not setting new start date, $WAKEUP or $CONFFILE does not exist" eend 1 fi }