#!/bin/bash
#
# /etc/rc.shutdown
#

. /etc/rc.conf
. /etc/rc.d/functions

run_hook shutdown_start

# avoid staircase effect
/bin/stty onlcr

echo " "
printhl "Initiating Shutdown..."
echo " "

# avoid NIS hanging syslog-ng on shutdown by unsetting the domainname
[[ -x /bin/domainname ]] && /bin/domainname ""
[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown

kill_everything shutdown

# removing psmouse module to fix some reboot issues on newer laptops
/sbin/modprobe -r psmouse >/dev/null 2>&1

stat_busy "Deactivating Swap"
/sbin/swapoff -a
stat_done

stat_busy "Unmounting Filesystems"
/bin/umount -a -r -t noramfs,notmpfs,nosysfs,noproc,nodevtmpfs -O no_netdev
stat_done

run_hook shutdown_poweroff

# Power off or reboot
printsep
if [[ $RUNLEVEL = 0 ]]; then
  printhl "${C_H2}POWER OFF"
  /sbin/poweroff -d -f -h -i
else
  printhl "${C_H2}REBOOTING"
  # if kexec is installed and a kernel is loaded, use it
  [[ -x /sbin/kexec ]] && /sbin/kexec -e > /dev/null 2>&1
  /sbin/reboot -d -f -i
fi

# End of file
