#!/bin/sh
exec 2>&1
einfo() { [ "${VERBOSE:-}" = no ] || echo "$@"; }
NETDOWN=yes
[ -f /etc/default/halt ] && . /etc/default/halt
. /lib/init/vars.sh 2>/dev/null || true
if [ "$INIT_HALT" = "" ]; then
	case "$HALT" in [Pp]*) INIT_HALT=POWEROFF ;; [Hh]*) INIT_HALT=HALT ;; *) INIT_HALT=POWEROFF ;; esac
fi
if [ "$INIT_HALT" = "POWEROFF" ] && [ -x /etc/init.d/ups-monitor ]; then
	/etc/init.d/ups-monitor poweroff || true
fi
hddown="-h"
grep -qs '^md.*active' /proc/mdstat 2>/dev/null && hddown=""
poweroff="-p"
[ "$INIT_HALT" = "HALT" ] && poweroff=""
netdown="-i"
[ "$NETDOWN" = "no" ] && netdown=""
einfo "Will now halt"
# Under s6-linux-init, prefer poweroff/halt wrappers if present.
if [ -x /sbin/halt ]; then
	/sbin/halt -d -f $netdown $poweroff $hddown || true
fi
exit 0
