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