-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsaveItAllD2
executable file
·48 lines (41 loc) · 1.47 KB
/
saveItAllD2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
INTERVAL="30m"
mutex() {
local file=$1 pid pids
exec 9>>"$file"
{ pids=$(fuser -f "$file"); } 2>&- 9>&-
for pid in $pids; do
[[ $pid = $$ ]] && continue
exec 9>&-
return 1 # Locked by a pid.
done
}
mutex /tmp/saveItAllD.lock || { echo "saveItAllD is already running." >&2; exit 1; }
while :
do
echo "Waiting $INTERVAL..."
sleep $INTERVAL
(x=0;while :; do x=`expr $x + 1`; echo $x; sleep 0.1s; done) | zenity --progress --auto-close --text="It has been $INTERVAL since you last saved your data.\nWe recommend that you save data now to prevent any possible data loss.\nData will automatically be saved in a few seconds.\n\nClick Cancel now if you do not wish to save data." --title="Save Data"
if [ "$?" = "0" ]; then
echo "Showing saving notification..."
exec 3> >(zenity --notification --text='Saving, please wait... (Do NOT power down your computer!)' --title="Saving data..." 2>/dev/null)
echo $! > /tmp/zen.pid
sync
kill `cat /tmp/zen.pid 2>/dev/null` 2>/dev/null
rm -f /tmp/zen.pid
sleep 5s
echo "Showing completion notification..."
exec 3> >(zenity --notification --text='Data has been successfully saved! This will close in 5 seconds.' --title='Data saved!' 2>/dev/null)
echo $! > /tmp/zen.pid
p=0
while :; do
echo " => Closing in "`expr 5 - $p`" seconds..."
p=`expr $p + 1`
sleep 1s
if [ "$p" = "6" ];then
kill `cat /tmp/zen.pid 2>/dev/null` 2>/dev/null;
break
fi
done
fi
done