]> git.friedersdorff.com Git - max/saltfiles.git/blob - states/sway/files/lock
da6ab02feca309ea91cfd7168563fcf525a56a56
[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 {% if grains['host'] == 'magnesium' %}
9 LOCK_CMD+=" -i HDMI-A-2:~/Pictures/lockscreen_1080_1.png"
10 LOCK_CMD+=" -i HDMI-A-3:~/Pictures/lockscreen_1080_2.png"
11 {% elif grains['host'] == 'barium' %}
12 LOCK_CMD+=" -i eDP-1:~/Pictures/lockscreen_1080_1.png"
13 {% endif %}
14
15
16 if [ $(pgrep -c lock.magnesium) -gt 1 ]; then
17         exit
18 else
19         gpg --card-status > /dev/null
20         if [ $? -ne 2 ]; then
21                 swaynag -m "$NAG_MSG" --type warning&
22
23                 counter=0
24                 while [ $? -ne 2 ]; do
25                         if [ $counter -gt 20 ]; then
26                                 pkill -f "$NAG_MSG"
27                                 swaynag -m "$NOLOCK_MSG" --type error&
28                                 exit
29                         fi
30
31                         sleep 1
32                         counter=$(bc <<<"${counter}+1")
33                         gpg --card-status > /dev/null
34                 done
35                 pkill -f "$NAG_MSG"
36         fi
37         $LOCK_CMD
38 fi