]> git.friedersdorff.com Git - max/saltfiles.git/blobdiff - states/sway/files/lock
Simplify lock script
[max/saltfiles.git] / states / sway / files / lock
index 75498371adad556c7610e686b82b84d51c1508de..230369e613ccb98a329665b305372b820a0623f2 100644 (file)
@@ -1,22 +1,25 @@
 #!/bin/sh
 
 NAG_MSG="Smartcard is still plugged in, not locking! \
-Lock again to force locking."
+Remove now to lock."
+NOLOCK_MSG="Smartcard was not removed, did not lock!"
 
-LOCK_CMD="swaylock "
-LOCK_CMD+=" -i HDMI-A-2:~/Pictures/lockscreen_1080_1.png"
-LOCK_CMD+=" -i HDMI-A-3:~/Pictures/lockscreen_1080_2.png"
+gpg --card-status > /dev/null
+if [ $? -ne 2 ]; then
+       swaynag -m "$NAG_MSG" --type warning&
 
-if [ $(pgrep -c lock.{{ grains['host'] }}) -gt 1 ]; then
-       pkill -f "$NAG_MSG" 
-       $LOCK_CMD
-else
-       gpg --card-status > /dev/null
-       if [ $? -ne 2 ]; then
-               gpg --card-status
-               echo $?
-               swaynag -m "$NAG_MSG" --type warning
-       else
-               $LOCK_CMD
-       fi
+       counter=0
+       while [ $? -ne 2 ]; do
+               if [ $counter -gt 20 ]; then
+                       pkill -f "$NAG_MSG"
+                       swaynag -m "$NOLOCK_MSG" --type error&
+                       exit
+               fi
+
+               sleep 1
+               counter=$(bc <<<"${counter}+1")
+               gpg --card-status > /dev/null
+       done
+       pkill -f "$NAG_MSG"
 fi
+pkill -u ${UID} swayidle --signal USR1