Last active
August 28, 2018 18:02
-
-
Save BlackthornYugen/a814f9fee7cf123eefbcddbff38696c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
FILTER_YUBIKEY='/Yubikey/{print;getline;getline;print;getline;print}' | |
EXPECTED_YUBI_MD5="1a067fac7f6915a0acd5a235876fd33e" # Hash of USB Device | |
LONG_POLL_TIME=3 # Poll time after locking | |
SHORT_POLL_TIME=1 # Poll time while waiting for yubikey to disconnect | |
ARMED=0 | |
DATESTRING=%Y-%m-%d\ %H:%M:%S.000 | |
do_screen_saver() { | |
echo "`date \"+${DATESTRING}\"` locking screen" | |
find /System/Library \ | |
-type d ! \ | |
-perm -o+r \ | |
-prune -o \ | |
-name "ScreenSaverEngine" \ | |
-exec {} \; \ | |
-quit | |
} | |
while [[ true ]]; do | |
ACTUAL_YUBI_MD5=`system_profiler SPUSBDataType | awk $FILTER_YUBIKEY | md5` | |
if [[ "${EXPECTED_YUBI_MD5}" != "${ACTUAL_YUBI_MD5}" ]]; then | |
if [[ "${ARMED}" -eq 1 ]]; then | |
ARMED=0 | |
do_screen_saver | |
fi | |
sleep $LONG_POLL_TIME | |
elif [[ "${ARMED}" -eq 0 ]]; then | |
echo "`date \"+${DATESTRING}\"` arming" | |
ARMED=1 | |
else | |
sleep $SHORT_POLL_TIME | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment