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