#!/usr/bin/perl -w
#############################
# powerdown event handler
# Mike Schilli, 2007
#############################
use strict;
use Sysadm::Install qw(:all);
use Log::Log4perl qw(:easy);

Log::Log4perl->easy_init({ 
  file =>
      ">>/tmp/powerdown.log",
  level => $DEBUG
});

my ($state, $softhard) =
  @ARGV;

LOGDIE
 "usage: $0 state SOFT|HARD"
 if !$softhard
 or $softhard !~ /SOFT|HARD/;

DEBUG
"Called $0 $state $softhard";

if ($state eq "OK") {
 DEBUG "Ignoring OK";
 exit 0;
}

if ($softhard eq "SOFT") {
 DEBUG "Ignoring soft mode";
 exit 0;
}

# Shut PC off
INFO "Shutting down";
tap("sudo", 
    "/usr/bin/poweroff");
