GitBucket
4.20.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
Jonathan
/
pmf-suspend
Browse code
Added simulation ended text.
master
1 parent
31dc07c
commit
440f4b8db7d997b893ddc9ffaffec46d3f67f76b
Jonathan Ström
authored
on 20 Mar 2017
Patch
Showing
1 changed file
pmf-suspend
Ignore Space
Show notes
View
pmf-suspend
#!/bin/bash # Set user to lock COMPUTER_USER="stina" # 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 # Help if [[ $1 == "help" || $1 == "--help" || $1 == "" ]]; then echo -e "Usage: pmf-suspend now|help|simulation|0-9[ 0-9[ 0-9]] pmf-suspend now Lock the screen and suspend system. pmf-suspend simulation Run a simulation of the program, execute nothing. 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 Use this program when you want to suspend your computer with a timer. As pm-suspend itself does not lock the screen on the latest versions. This will do that automatically when the timer is finished. The command pmf-suspend stands for Power Manager (Fix) suspend. In order to suspend the system this program must be run as root. You need to change the 'COMPUTER_USER' variable in this script in order to be able to lock your computer while running as root. "; 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 root. if [[ $EUID -ne 0 ]]; then # 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 [ "$PARAM_3" != "" ]; then hour=$(($PARAM_3 * 3600)); fi if [ "$PARAM_2" != "" ]; then minute=$(($PARAM_2 * 60)); fi if [ "$PARAM_1" != "" ]; then second=$(($PARAM_1)); fi # Print time and count down suspendText="Suspending computer in: " runCountdown() { total=$(( $hour + $minute + $second )) while [ $total -gt 0 ] do sleep 1 & printf "\r$suspendText%02d:%02d:%02d" $((total/3600)) $(((total/60)%60)) $((total%60)) total=$(( $total - 1 )) wait done # Setting timer to 00:00:00 when it is finished printf "\r$suspendText%02d:%02d:%02d" 00 00 00 echo } if [ $PARAM_1 != "now" ]; then runCountdown fi # If the user is running a simulation then don't execute any scripts. if [ $SIMULATION == 1 ]; then echo "Locking screen..."; echo "Suspending computer..."; echo "Simulation finished."; exit 1 fi # Execute scripts # Lock screen sudo -u $COMPUTER_USER gnome-screensaver-command --lock # Suspend computer sudo pm-suspend
#!/bin/bash # Set user to lock COMPUTER_USER="stina" # 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 # Help if [[ $1 == "help" || $1 == "--help" || $1 == "" ]]; then echo -e "Usage: pmf-suspend now|help|simulation|0-9[ 0-9[ 0-9]] pmf-suspend now Lock the screen and suspend system. pmf-suspend simulation Run a simulation of the program, execute nothing. 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 Use this program when you want to suspend your computer with a timer. As pm-suspend itself does not lock the screen on the latest versions. This will do that automatically when the timer is finished. The command pmf-suspend stands for Power Manager (Fix) suspend. In order to suspend the system this program must be run as root. You need to change the 'COMPUTER_USER' variable in this script in order to be able to lock your computer while running as root. "; 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 root. if [[ $EUID -ne 0 ]]; then # 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 [ "$PARAM_3" != "" ]; then hour=$(($PARAM_3 * 3600)); fi if [ "$PARAM_2" != "" ]; then minute=$(($PARAM_2 * 60)); fi if [ "$PARAM_1" != "" ]; then second=$(($PARAM_1)); fi # Print time and count down suspendText="Suspending computer in: " runCountdown() { total=$(( $hour + $minute + $second )) while [ $total -gt 0 ] do sleep 1 & printf "\r$suspendText%02d:%02d:%02d" $((total/3600)) $(( (total/60)%60)) $((total%60)) total=$(( $total - 1 )) wait done # Setting timer to 00:00:00 when it is finished printf "\r$suspendText%02d:%02d:%02d" 00 00 00 echo } if [ $PARAM_1 != "now" ]; then runCountdown fi # If the user is running a simulation then don't execute any scripts. if [ $SIMULATION == 1 ]; then echo "Locking screen..."; echo "Suspending computer..."; exit 1 fi # Execute scripts # Lock screen sudo -u $COMPUTER_USER gnome-screensaver-command --lock # Suspend computer sudo pm-suspend
Show line notes below