#!/bin/bash
#
#Server-Manager: o_reboot (System Command: Countdown reboot) [Power: 700]
#
#Version: 0.0.6
#Date:    2022.03.09
#Unix:    Debian 11
#Author:  P.Klapp
#Company: Omoti UG (haftungsbeschränkt)
#Website: https://omoti.de
#
#Path:    /Commands/


#Version
    version=$(sed -n '5p' ${0})
    version=${version#*\ }

#Temporary file
    tmp='/srv/omoti/tmp/o_reboot.tmp'

#Parameters
    count=${1} #Count (int)
    count=${count:="5"}

#Functions
#Dependencies
    if ! [ `echo "$count" | grep -E ^[[:digit:]]+$` ]; then
        count="5"
    fi

#Variables
#Main
    echo
    while [ ${count} != "0" ]; do
        echo -ne "Server reboot in\033[36m ${count}s\033[0m \r"
        sleep 1s
        ((count--))
    done
    o_log -i "Server reboot"
    reboot