diff --git a/pmf-suspend b/pmf-suspend index 6b67416..afaa0e1 100644 --- a/pmf-suspend +++ b/pmf-suspend @@ -1,19 +1,61 @@ #!/bin/bash +# Help +if [[ $1 == "help" || $1 == "--help" ]]; then + echo -e "Usage: + pmf-suspend Suspend system + pmf-suspend [help|--help] Show this message + pmf-suspend 1 2 3 Timer will be set to 1s, 2m, 3h + pmf-suspend 0 30 Timer will be set to 30 mintues + +Info: + Author: Livila. + Version: 1.0 + + This program is used for when you want to suspend your computer with a timer. + As pm-suspend does not lock the screen, this will do that automatically when + the timer is finished. + + In order to suspend the system this program must be run as root."; +fi + # Check if the user is using sudo. if [[ $EUID -ne 0 ]]; then echo "This script must be run as root, use \"sudo pmf-suspend\" instead." 1>&2 exit 1 fi + +# Calulcate time +if [ "$3" != "" ]; then + hour=$(($3 * 3600)); +fi +if [ "$2" != "" ]; then + minute=$(($2 * 60)); +fi +if [ "$1" != "" ]; then + second=$(($1)); +fi + +# Print time and count down +countdown() { + total=$(( $hour + $minute + $second )) + while [ $total -gt 0 ] + do + sleep 1 + printf "\r%02d:%02d:%02d" $((total/3600)) $(( (total/60)%60)) $((total%60)) + total=$(( $total - 1 )) + wait + done + echo +} + # Set user user="stina" -# If the user entered anything after the command, assume it is a command for sleep. -if [ "$1" != "" ]; then - eval "sleep $1" +if [ $1 != "" ]; then + countdown fi - # Execute scripts # Lock screen