diff --git a/pmf-suspend b/pmf-suspend index 1f8aabb..a914a63 100644 --- a/pmf-suspend +++ b/pmf-suspend @@ -1,10 +1,24 @@ #!/bin/bash +# Run a simulation of the program. Does not lock nor suspend the system. +SIMULATION=0 + +# Set params used +PARAM_1=$1 +PARAM_2=$2 +PARAM_3=$3 +PARAM_4=$4 + +# Set user +COMPUTER_USER="stina" + # Help if [[ $1 == "help" || $1 == "--help" ]]; then echo -e "Usage: - pmf-suspend Suspend and lock the screen directly - pmf-suspend [help|--help] Show this message + pmf-suspend [--help|--simulation|[0-9|0-9|0-9]] + pmf-suspend Suspend system + pmf-suspend help|--help Show this message + pmf-suspend --simulation Run a simulation of the program, execute nothing. pmf-suspend 1 2 3 Timer will be set to 1s, 2m, 3h pmf-suspend 0 30 Timer will be set to 30 mintues @@ -22,24 +36,34 @@ "; exit 1 +elif [[ $1 == "simulation" || $1 == "--simulation" ]]; then + echo "Running a simulation..."; + PARAM_1=$PARAM_2 + PARAM_2=$PARAM_3 + PARAM_3=$PARAM_4 + SIMULATION=1 fi -# Check if the user is using sudo. +# Check if the user is root. if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root, use \"sudo pmf-suspend\" instead." 1>&2 - exit 1 + # Check if the user is running a simulation + if [ $SIMULATION == 1 ]; then + echo "Usually this script must be run as root, but this is a simulation." 1>&2 + else + echo "This script must be run as root, use \"sudo pmf-suspend\" instead." 1>&2 + exit 1 + fi fi - # Calulcate time -if [ "$3" != "" ]; then - hour=$(($3 * 3600)); +if [ "$PARAM_3" != "" ]; then + hour=$(($PARAM_3 * 3600)); fi -if [ "$2" != "" ]; then - minute=$(($2 * 60)); +if [ "$PARAM_2" != "" ]; then + minute=$(($PARAM_2 * 60)); fi -if [ "$1" != "" ]; then - second=$(($1)); +if [ "$PARAM_1" != "" ]; then + second=$(($PARAM_1)); fi # Print time and count down @@ -58,17 +82,19 @@ echo } -# Set user -user="stina" - -if [ $1 != "" ]; then +if [ $PARAM_1 != "" ]; then runCountdown fi +# If the user is running a simulation then don't execute any scripts. +if [ $SIMULATION == 1 ]; then + exit 1 +fi + # Execute scripts # Lock screen -sudo -u $user gnome-screensaver-command --lock +sudo -u $COMPUTER_USER gnome-screensaver-command --lock # Suspend computer sudo pm-suspend