Created
March 2, 2019 05:46
-
-
Save premiso/902051c7c9de15dce7c6f48ae3356617 to your computer and use it in GitHub Desktop.
Lock Workstation before Suspending on Linux Mint 18.04
This file contains hidden or 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
| # /var/lib/polkit-1/localauthority/50-local.d/50-enable-suspend-on-lockscreen.pkla | |
| [Allow suspending in lockscreen] | |
| Identity=unix-group:users | |
| Action=org.freedesktop.login1.suspend | |
| ResultAny=yes | |
| ResultInactive=yes | |
| ResultActive=yes | |
| [Allow setting wall message in lockscreen] | |
| Identity=unix-group:users | |
| Action=org.freedesktop.login1.set-wall-message | |
| ResultAny=yes | |
| ResultInactive=yes | |
| ResultActive=yes |
This file contains hidden or 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
| #!/bin/bash | |
| # | |
| # After being pissed at systemd not locking the fucking screen prior | |
| # to suspending and not having any clear method (aside from xss, which I didn't like) | |
| # I decided to find another solution so I can have my monitor locked when resumed | |
| # with an added bonus this delays the inevitable by 5 minutes. | |
| # | |
| # @todo: extend the script bat power / plugged in and choosing different scenarios depending. | |
| # | |
| # In order for this to work a few items need done. One the file at /etc/UPower/UPower.conf needs IgnoreLid=true | |
| # the reason is we are taking control of the lid action, so this will prevent systemd capturing it and | |
| # doing it;s own desired fuckery we don't want. | |
| # | |
| # next, set ctrl+alt+l (or your prefered shortcut) to this script, I placed it in /usr/bin: | |
| # /usr/bin/LockStation.sh lock | |
| # | |
| # Next we need to add our user to the users group: | |
| # sudo usermod -aG user "YOURUSERHERE" | |
| # | |
| # Next is we need to modify the polkit, for my polkit version (>1.6 i believe) I needed to create a file and | |
| # add this to that file located at (note need root to create): | |
| # /var/lib/polkit-1/localauthority/50-local.d/50-enable-suspend-on-lockscreen.pkla | |
| # | |
| # This effectively allows us to suspend and send wall message as a non-admin user in the users group | |
| # which our user is from the sudo command above (see extra file with the name) | |
| # | |
| # And now restart our system and our script should work | |
| #Sets the path where the script lives (remember to chmod +x) | |
| SCRIPTPATH="/usr/local/bin/LockStation.sh" | |
| # Check if we are locking the system ( Ctrl+Alt+L ) | |
| if [ "$@" == "lock" ] | |
| then | |
| CMDLOCK="$SCRIPTPATH SLICKCHK" | |
| # After 5 minutes check is slick greeter is on if not kill it, if slick-greeter is active BAIL | |
| # After 6 minutes, if the locker did not kick in, just kill it | |
| xautolock -time 5 -locker "$CMDLOCK" -killtime 6 -killer "$SCRIPTPATH KILL" & | |
| # Lock | |
| light-locker-command --lock | |
| elif [ "$@" == "SLICKCHK" ] | |
| then | |
| # this is called by the xautolock | |
| # Search for slick-greeter as my system uses that for the lock screen | |
| # @todo fix for your greater, adding the [ ] around the initial letter | |
| # removes it's own result from grep, ensuring there can be none on the results | |
| SLICK=`ps aux | grep [s]lick-greeter` | |
| # If slick-greeter is empty, the autolock has been X minutes, find it and kill it | |
| if [ -n $SLICK ] | |
| then | |
| #Kills the xautolock and exits, we are finished here. | |
| ALOCK=`pgrep [x]autolock` | |
| kill -9 $ALOCK | |
| exit 0 | |
| fi | |
| # If the slick greeter was found and it has been 5 minutes, lets just hibernate. | |
| # @todo added battery check, only suspend on battery? | |
| if on_ac_power; | |
| then | |
| exit 0 | |
| # No action taken due to AC power, add custom item here? Maybe after like 10 checks (50 minutes) sleep on AC power? | |
| # I prefer blank due to I maybe running a process, so prefer to let it do it | |
| else | |
| systemctl suspend | |
| fi | |
| elif [ "$@" == "KILL" ] | |
| then | |
| ALOCK=`pgrep [x]autolock` | |
| kill -9 $ALOCK | |
| fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment