#!/bin/sh

RED='\033[0;31m'
NC='\033[0m'


test() {
	trap '' TERM INT
	echo "Trying shutdown and cancel afterwards.."
	sudo shutdown -h
	sleep 1
	echo "Canceling shutdown.."
	sudo shutdown -c
	trap - TERM INT
}

safemode() {
	sudo shutdown -h now
}


hostname=$(hostname)

echo
echo "Do you really want to ${RED}shutdown${NC} this system ($hostname)?"
while true; do
	read -p "Please type this systems hostname to confirm or \"test\": " userinput
	case $userinput in
		$hostname ) echo "Shutdown!"; sleep 1; safemode; break;;
		test ) test; break;;
		* ) echo "Please try agin!";;
	esac
done
