#!/usr/bin/perl
#
# /usr/local/bin/down
#
# This file is used to spin down disks and place computer in sleep
# mode. It will also attempt to set invoke screensaver (because this
# usuallly means that you are leaving console). As it only sets screen
# saving to 1 minute and back again, it should not harm even if you
# don't. 
#
# This file expects to be setuid root. I hope there are no holes in
# here. If they are, report them to me
#                                 <pavel@atrey.karlin.mff.cuni.cz>. 
#
# Well, users are still able to do nasty things even if there are no
# holes - spinning disk down every second would probably do bad things
# (tm) to system. This thing is meant for laptops, where root is
# probably only user, but where he does not want to be logged-in as
# root all the time.
#
# Do _NOT_ interrupt this script. It might leave system in state
# without update running, which is probably not what you want.
#
# This file is rather site-dependend - this one for example expects
# that terminal blanking is set to 5 minutes and that you want disk to
# spin down after 15 minutes of inactivity.
#
$ENV{PATH}="/usr/bin:/usr/sbin:/bin:/sbin";
system "sleep 1";
system "setterm -blank 5";
system "killall update";
system "update -v";
system "/etc/rc/rc.spindown";
system "update -n 900 -a";
system "setterm -blank 1";
system "sleep 2m";
system "setterm -blank 5";
