From ddc84b2eb6413678e08917fd7b8f10236ba5f2e8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 2 Mar 2019 19:47:03 +0100 Subject: [PATCH] working demo --- README.md | 22 ++++++++++++++++++++++ install.sh | 21 +++++++++++++++++++++ src/xlock | 37 +++++++++++++++++++++++++++++++++++++ systemd/xlock@.path | 9 +++++++++ systemd/xlock@.service | 12 ++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 README.md create mode 100755 install.sh create mode 100644 src/xlock create mode 100644 systemd/xlock@.path create mode 100644 systemd/xlock@.service diff --git a/README.md b/README.md new file mode 100644 index 0000000..39dc558 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# xlock screen locker + +`xlock` really does nothing, it uses and wraps [`i3lock`]() into [systemd]() to allow a seamless screen lock. You have as a background the screenshot of your current screen, the mouse pointer works, nothing can happen. You just have to type your password, press enter and here you go. + + +Your friends and coworkers can be attempted, they won't succeed ! + + +### Installation + +run `./install.sh` ; you need sudo permissions. + +### How to use +A lock file is created at '/tmp/.unlocked'. To lock your screen, simply delete this file. After the install the service 'xlock@.path' with `` being your username during install. To start it `systemctl start xlock@user.path`, at the install it is enabled by default, so launched at boot. + +To add a key binding or to automate your script lock, simply delete the `/tmp/.unlocked` file. + + + +### Security issues + +Killin the `i3lock` process does not remove the locker. \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..fab964f --- /dev/null +++ b/install.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +user=`whoami` +local_d="$(realpath `dirname $0`)"; +bin_d="/usr/sbin/"; +systemd_d="/usr/lib/systemd/system"; + +# copy lock script +printf "(1) copying xlock executable\n"; +sudo cp "$local_d/src/xlock" "$bin_d/xlock"; +sudo chmod +x "$bin_d/xlock"; + +# copy systemd files +printf "(2) copying systemd units\n"; +sudo cp $local_d/systemd/* "$systemd_d"; + +# enable path +printf "(3) enabling systemd watcher\n"; +sudo systemctl enable "xlock@$user.path" > /dev/null 2>&1; + +printf "\n . install sucessful\n" \ No newline at end of file diff --git a/src/xlock b/src/xlock new file mode 100644 index 0000000..5954ed0 --- /dev/null +++ b/src/xlock @@ -0,0 +1,37 @@ +#!/bin/bash +screenshot_f="/tmp/.lock.screenshot.png"; +unlock_f="/tmp/.unlocked"; + +# if lock file -> exit +if [ -f "$unlock_f" ]; then + exit 0; +fi; + + +# take screenshot (if not exists) +if [ ! -f $screenshot_f ]; then + scrot $screenshot_f; +fi; + +# lock w/ screenshot +i3lock -n -u -p default -e -i $screenshot_f; +# -n : no fork (does not work with systemd eitherway) +# -u : do not display lock indicator +# -p default : do not hide mouse pointer +# -e : ignore empty passwords + +# if 'i3lock' has been killed or has error +if [ "$?" -ne 0 ]; then + + + # re-lock + exec $0; + exit 0; +fi; + +# create lock file +touch $unlock_f; +chmod o=rwx $unlock_f; + +# remove screenshot +rm -f $screenshot_f; \ No newline at end of file diff --git a/systemd/xlock@.path b/systemd/xlock@.path new file mode 100644 index 0000000..bf3101c --- /dev/null +++ b/systemd/xlock@.path @@ -0,0 +1,9 @@ +[Unit] +Description=Locker lock file watcher + +[Path] +PathModified=/tmp +Unit=xlock@%i.service + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/systemd/xlock@.service b/systemd/xlock@.service new file mode 100644 index 0000000..e49399f --- /dev/null +++ b/systemd/xlock@.service @@ -0,0 +1,12 @@ +[Unit] +Description=Locker daemon + +[Service] +Type=oneshot +RemainAfterExit=false +User=%i +Group=%i + +Environment="DISPLAY=:0" +Environment="XAUTHORITY=/home/%i/.Xauthority" +ExecStart=/usr/sbin/xlock \ No newline at end of file