]> git.friedersdorff.com Git - max/saltfiles.git/blob - states/sway/files/lock
Modify the logic of lock script
[max/saltfiles.git] / states / sway / files / lock
1 #!/bin/sh
2
3 NAG_MSG="Smartcard is still plugged in, not locking! \
4 Remove now to lock."
5 NOLOCK_MSG="Smartcard was not removed, did not lock!"
6
7 LOCK_CMD="swaylock "
8 LOCK_CMD+=" -i HDMI-A-2:~/Pictures/lockscreen_1080_1.png"
9 LOCK_CMD+=" -i HDMI-A-3:~/Pictures/lockscreen_1080_2.png"
10
11 if [ $(pgrep -c lock.magnesium) -gt 1 ]; then
12         exit
13 else
14         gpg --card-status > /dev/null
15         if [ $? -ne 2 ]; then
16                 swaynag -m "$NAG_MSG" --type warning&
17
18                 counter=0
19                 while [ $? -ne 2 ]; do
20                         if [ $counter -gt 20 ]; then
21                                 pkill -f "$NAG_MSG"
22                                 swaynag -m "$NOLOCK_MSG" --type error&
23                                 exit
24                         fi
25
26                         sleep 1
27                         counter=$(bc <<<"${counter}+1")
28                         gpg --card-status > /dev/null
29                 done
30                 pkill -f "$NAG_MSG"
31         fi
32         $LOCK_CMD
33 fi