#!/bin/sh
# Copyright (c) 2000-2014 Synology Inc. All rights reserved.

SupportDualhead=`/bin/get_key_value /etc.defaults/synoinfo.conf support_dual_head`
SupportEncPwrCtl=`/bin/get_key_value /etc.defaults/synoinfo.conf support_enc_powerctrl_onoff`
REBOOT="reboot"
POWEROFF="poweroff"

if [ "-r" = $1 ]; then
	ACTION=$REBOOT
elif [ "-p" = $1 ]; then
	ACTION=$POWEROFF
fi

if [ "xyes" = "x$SupportDualhead" ]; then
	killall syno_aha_mgr_daemon
	killall syno_aha_comm_to_remote_daemon
	if [ "x$ACTION" = "x$REBOOT" ]; then
		# reboot
		/usr/sbin/chroot /dual_glibc /usr/syno/synoaha/bin/synoaha --reboot-prolong-expander-HB-timeout
	elif [ "x$ACTION" = "x$POWEROFF" ]; then
		# poweroff
		/usr/sbin/chroot /dual_glibc /usr/syno/bin/synoenc --poweroff_all
	fi
fi

if [ "xyes" != "x$SupportDualhead" -a "xyes" = "x$SupportEncPwrCtl" ]; then
	if [ "x$ACTION" = "x$POWEROFF" ]; then
		/usr/syno/bin/synoenc --poweroff_all
	fi
fi
