DEV Community

Cover image for Enable your Linux Machine to show login (SDDM) with Aerial Theme when motion is detected
Brisbane Web Developer
Brisbane Web Developer

Posted on • Updated on

Enable your Linux Machine to show login (SDDM) with Aerial Theme when motion is detected

Summary

  • I have a spare iMac 2012 and it has been working with Debian in external SDD because the internal hard drive stopped working with recent MacOS.

  • The iMac acts as server and it is facing to the bathroom. Now, when I am in the bathroom, I cannot check the time unless I bring a mobile device.

  • So I decided to make the server show the time with some nice things when I am in the bathroom. And to make the project bit challenging, I also decied to turn on the monitor only if I went to the bathroom so that it is usually turned off.

  • This could be done in a different way as you make the server autologin at first, but I just decided to do in this way for now.

Notice

Since this is for Linux environment, you would need to spend your own time to investigate to make the follwoings work for your situation, but it would work regadless if you can apply the steps fundamentally.

Steps

Install Programs

mkdir -p /usr/local/src/3ximus/aerial-sddm-theme

cd /usr/local/src/3ximus/aerial-sddm-theme

git clone https://github.com/3ximus/aerial-sddm-theme.git .

cd /usr/share/sddm/themes

ln -s /usr/local/src/3ximus/aerial-sddm-theme

aptitude install motion unclutter-xfixes
Enter fullscreen mode Exit fullscreen mode
  • Open the setting Login Screen (SDDM) in KDE Plasma

  • Select Aerial HD Video

Amend Files

/etc/motion/motion.conf
==========

# I guess I did not have to do this, but just in case
target_dir /dev/null

movie_output off
webcontrol_port 0
webcontrol_localhost on

# Reduce CPU Usage
width 640
height 480

#
# Turn on monitor when someone passed by
#
# Execute your own script so that you do not need
# to restart SDDM during the investigation in case
# you need to do that for your environment:
#
# - This way avoids you to have to "service sddm restart"
#   and then wait until your monitor gets turned off
#
# - The last "logger" sends the output from
#   "poke-monitor" to "/var/log/messages"
#   so that you can debug easier
#
on_motion_detected '/usr/local/bin/poke-monitor 2>&1 | logger'
Enter fullscreen mode Exit fullscreen mode
/usr/share/sddm/scripts/Xsetup
========

# Hide mouse cursor
/usr/bin/unclutter -idle 1 -root &

# Remove lock file if exists
# Refer the comment for "/usr/local/bin/poke-monitor"
# for more details
lockfile=/var/lock/poke-monitor
if [ -f "$lockfile" ];
then
  rm -f $lockfile
fi

# Kill the script in case it is running/waiting
killall poke-monitor

# Disable systemd service for motion if running
# (It does not work otherwise)
isMotionServiceRunning=$(systemctl status motion.service | egrep "Active.+running")
if [ -n "$isMotionServiceRunning" ];
then
  systemctl stop motion.service
  systemctl disable motion.service
fi

# Run motion
/usr/bin/motion &
Enter fullscreen mode Exit fullscreen mode
/usr/local/bin/poke-monitor
========
#!/bin/bash

# You may need to amend this file to suit to your environment
# For example, I use KDE Plasma and how this script checks
# if GUI is used, relies on that situation

# This event occurs a lot so it tries to avoid processing
# while it is processing by using the lock file

lockfile=/var/lock/poke-monitor

if [ -f "$lockfile" ];
then
  exit
fi

finish () {
  sleep 60
  rm -f $lockfile
}

touch $lockfile
sync; sync

# Not to process if someone is using GUI
loggedin=`w | egrep "tty.+startplasma"`

if [ -n "$loggedin" ];
then
  echo "GUI is used"
  finish
  exit
fi

echo "Turning on monitor"

# This shows the screen having some output from kernel
# kill -TERM `pidof sddm` &> /dev/null

xset dpms force off
sleep 1
xset dpms force on

# Avoid processing within the next short period of time
# because the monitor would be still turned on
finish
Enter fullscreen mode Exit fullscreen mode

Optional - Increase the font size of clock etc

cd /usr/local/src/3ximus/aerial-sddm-theme
git checkout -b custom
cp /usr/lib/x86_64-linux-gnu/qt5/qml/SddmComponents/Clock.qml components/CustomClock.qml

#
# Muck around these files
#
# - /usr/local/src/3ximus/aerial-sddm-theme/theme.conf
#
# - /usr/local/src/3ximus/aerial-sddm-theme/components/CustomClock.qml
#
# - /usr/local/src/3ximus/aerial-sddm-theme/Main.qml
Enter fullscreen mode Exit fullscreen mode

Things I did not have to apply

  • During the investigation I found these things.

  • Leaving the notes in case I need to refer for something else to do.

Allow the user motion to restart SDDM

/etc/sudoers.d/sddm-sudoers
==========
Cmnd_Alias RESTARTSERVER_SDDM = /usr/bin/systemctl restart sddm.service
motion ALL=(ALL) NOPASSWD: RESTARTSERVER_SDDM
Defaults!RESTARTSERVER_SDDM !requiretty
Enter fullscreen mode Exit fullscreen mode

Make Motion to restart SDDM in Daemon Mode

/etc/default/motion
==========
start_motion_daemon=yes
Enter fullscreen mode Exit fullscreen mode
/etc/motion/motion.conf
==========

daemon on

on_motion_detected 'sudo systemctl restart sddm.service'
Enter fullscreen mode Exit fullscreen mode

References

Top comments (0)