]> git.friedersdorff.com Git - max/saltfiles.git/blob - states/sway/files/lock
936b955c261c5eaa930b13763ebf0979433f984d
[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="systemctl suspend"
8
9 if [ $(pgrep -c lock.magnesium) -gt 1 ]; then
10         exit
11 else
12         gpg --card-status > /dev/null
13         if [ $? -ne 2 ]; then
14                 swaynag -m "$NAG_MSG" --type warning&
15
16                 counter=0
17                 while [ $? -ne 2 ]; do
18                         if [ $counter -gt 20 ]; then
19                                 pkill -f "$NAG_MSG"
20                                 swaynag -m "$NOLOCK_MSG" --type error&
21                                 exit
22                         fi
23
24                         sleep 1
25                         counter=$(bc <<<"${counter}+1")
26                         gpg --card-status > /dev/null
27                 done
28                 pkill -f "$NAG_MSG"
29         fi
30         $LOCK_CMD
31 fi