]> git.friedersdorff.com Git - max/saltfiles.git/commitdiff
Modify the logic of lock script
authorMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 22 Jul 2019 09:24:42 +0000 (10:24 +0100)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 22 Jul 2019 09:24:42 +0000 (10:24 +0100)
Do not allow locking while smartcard is still plugged in

states/sway/files/config.jinja
states/sway/files/lock
states/sway/init.sls

index af3a8b29afc67e5c4e2155840efe24f4fb4405bf..e474512d580cbfecf26a1cacac89eeea83c7ca18 100644 (file)
@@ -106,7 +106,7 @@ mode "$ratpoison" {
 
     bindsym Shift+e exec 'swaymsg mode "default"; swaymsg exec bemenu-run'
 
-    bindsym $mod+l exec 'swaymsg mode "default"; "lock.{{ host }}"' 
+    bindsym $mod+l exec 'swaymsg mode "default"; "lock.nosmartcard"' 
     bindsym Escape mode "default"
 }
 
index 75498371adad556c7610e686b82b84d51c1508de..050e67a7c308afbd5cbe6e66c210f5641c14b32e 100644 (file)
@@ -1,22 +1,33 @@
 #!/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"
 
-if [ $(pgrep -c lock.{{ grains['host'] }}) -gt 1 ]; then
-       pkill -f "$NAG_MSG" 
-       $LOCK_CMD
+if [ $(pgrep -c lock.magnesium) -gt 1 ]; then
+       exit
 else
        gpg --card-status > /dev/null
        if [ $? -ne 2 ]; then
-               gpg --card-status
-               echo $?
-               swaynag -m "$NAG_MSG" --type warning
-       else
-               $LOCK_CMD
+               swaynag -m "$NAG_MSG" --type warning&
+
+               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
+       $LOCK_CMD
 fi
index 010484d2d4423b7b3b9d00b7058b788e52038532..4b04205df82767ce527b5c0cd62377d1bab0fe8d 100644 (file)
@@ -23,7 +23,7 @@ sway config:
 
 lock script:
   file.managed:
-    - name: {{ grains['homedir'] }}/.local/bin/lock.{{ grains['host'] }}
+    - name: {{ grains['homedir'] }}/.local/bin/lock.nosmartcard
     - source: {{ grains['stateroot'] }}/sway/files/lock
     - template: jinja
     - user: {{ grains['user'] }}