Created
July 22, 2020 06:55
-
-
Save jtsagata/90f9c10331b7b0d111e45129036c489f to your computer and use it in GitHub Desktop.
Snooze.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#hour=$(yad --center --width="90" --height="50" --text-align="center" --entry --numeric --title="Ρύθμιση Χρονόμετρου" --text="Επιλέξτε ώρες για τερματισμό:" --entry-text="0") | |
#minute=$(yad --center --width="90" --height="50" --entry --numeric --title="Ρύθμιση Χρονόμετρου" --text="Επιλέξτε λεπτά για τερματισμό:" --entry-text="0") | |
function insertTime() | |
{ | |
frmdata=$(yad --center --width="260" --height="50" --title="Ρύθμιση Χρονομέτρου" \ | |
--text='<span foreground="green" font="16">Εισάγετε χρόνο για τερματισμό:</span>' \ | |
--button="Έντάξει" --button="Άκυρο" --form \ | |
--field=" Ώρες:":NUM "0" \ | |
--field=" Λεπτά:":NUM "0") | |
hours=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $1 }') | |
minutes=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $2 }') | |
time=$(($hours*3600 + $minutes*60)) | |
msg=$(date --date="now +$time seconds") | |
/usr/bin/notify-send -t 0 "Προσοχή!!" "Θα γίνει απενεργοποίηση την $msg" | |
date --date="now + $time seconds" | |
if [ $time -ge 0 ]; then | |
echo $minutes | |
sleep $time | |
doShutdown | |
else | |
echo "Ακυρώθηκε" | |
fi | |
} | |
function doShutdown() | |
{ | |
info=$(yad --center --width="260" --height="260" --image "dialog-question" --undecorated \ | |
--timeout="60" --timeout-indicator="top" --button="Αναβολή" --button="Άκυρο" \ | |
--title="ΠΡΟΣΟΧΗ!!" --text-align="center" --sticky --on-top --buttons-layout="center" \ | |
--text='<span foreground="red" font="24">ΑΠΕΝΕΡΓΟΠΟΙΗΣΗ ΥΠΟΛΟΓΙΣΤΗ | |
ΣΕ</span> | |
<span foreground="green" font="42">1</span><span foreground="red" font="24"> | |
ΛΕΠΤΟ!!</span>') | |
case $? in | |
70) | |
echo "timeout!!!" | |
systemctl poweroff | |
;; | |
1) | |
yad --timeout="3" --timeout-indicator="top" --center --width="240" --height="50" \ | |
--undecorated --text-align="center" --buttons-layout="edge" \ | |
--text='\n<span foreground="red" font="32">Η ενέργεια ακυρώθηκε!</span>' --button="Ok" | |
echo "canceled" | |
;; | |
0) | |
echo "αναβολή" | |
snooze | |
;; | |
252) | |
yad --timeout="3" --timeout-indicator="top" --center --width="240" --height="50" \ | |
--undecorated --text-align="center" --buttons-layout="edge" \ | |
--text='\n<span foreground="red" font="32">Η ενέργεια ακυρώθηκε!</span>' --button="Ok" | |
echo "escape pressed" | |
;; | |
esac | |
} | |
function snooze() | |
{ | |
snz=$(yad --center --width="120" --height="260" --list --radiolist --no-click \ | |
--button="Αναβολή" --button="Άκυρο" \ | |
--column "Επιλογή" --column "Λεπτά" TRUE "5" FALSE "15" FALSE "30" FALSE "45" FALSE \ | |
"60" FALSE "75" FALSE "90" FALSE "120") | |
answer=$(echo $snz | awk 'BEGIN {FS="|" } { print $2 }') | |
case $answer in | |
5) | |
t1=$((5 * 60)) | |
sleep $t1 | |
doShutdown | |
;; | |
15) | |
t2=$((15 * 60)) | |
sleep $t2 | |
doShutdown | |
;; | |
30) | |
t3=$((30 * 60)) | |
sleep $t3 | |
doShutdown | |
;; | |
45) | |
t4=$((45 * 60)) | |
sleep $t4 | |
doShutdown | |
;; | |
60) | |
t5=$((60 * 60)) | |
sleep $t5 | |
doShutdown | |
;; | |
75) | |
t6=$((75 * 60)) | |
sleep $t6 | |
doShutdown | |
;; | |
90) | |
t7=$((90 * 60)) | |
sleep $t7 | |
doShutdown | |
;; | |
120) | |
;; | |
1) | |
yad --timeout="3" --timeout-indicator="top" --center --width="240" --height="50" \ | |
--undecorated --text-align="center" --buttons-layout="edge" \ | |
--text='\n<span foreground="red" font="32">Η Αναβολή ακυρώθηκε!</span>' --button="Ok" | |
echo "snooze canceled" | |
doShutdown | |
;; | |
252) | |
yad --timeout="3" --timeout-indicator="top" --center --width="240" --height="50" \ | |
--undecorated --text-align="center" --buttons-layout="edge" \ | |
--text='\n<span foreground="red" font="32">Η Αναβολή ακυρώθηκε!</span>' --button="Ok" | |
echo "escape pressed, canceled" | |
;; | |
esac | |
} | |
insertTime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment