#
# Awk program to insert the necessary nut script in
# to a halt script.
#
# Thefted from apcupsd by Jon Nelson <jnelson@securepipe.com>
#
# Stuff left over from a previous apcupsd, remove it
/^# See if this is a powerfail situation\./ {
   do {
      getline 
   }  while (length($0) != 0) 
}
# We insert our code just before this line
/^# Now halt or reboot\./ {
   print ". /etc/sysconfig/nut"
   print "# See if this is a powerfail situation.                               # ***ups***"
   print "if [ -f /etc/killpower ]; then                                        # ***ups***"
   print "  rm -f /etc/killpower"
   print "   echo                                                               # ***ups***"
   print "   echo \"NUT will now power off the UPS\"                            # ***ups***"
   print "   echo                                                               # ***ups***"
   print "   /bin/$MODEL -k $DEVICE                                         # ***ups***"
   print "   echo                                                               # ***ups***"
   print "   echo \"Please ensure that the UPS has powered off before rebooting\" # ***ups***"
   print "   echo \"Otherwise, the UPS may cut the power during the reboot!!!\"   # ***ups***"
   print "   echo                                                               # ***ups***"
   print "   sleep 2d                                                           # ***ups***"
   print "   exit 0                                                             # ***ups***"
   print "fi                                                                    # ***ups***"
   print ""
}
# everything else is duplicated
{ print }
