ShiftLock LED as HDDLED on Dell XPS 13

The following HowTo will show how to use the ShiftLock LED on the DELL XPS 13 as a HardDrive LED. You need a Linux distribution with systemd. The following dependencies need to be installed:

kbd
xorg-setxkbmap

The script (pcfreakled)

#!/bin/bash
# save this file as pcfreakled without extension
# and make it executable (chmod +x)

#check dependencies
command -v setxkbmap >/dev/null 2>&1 || { echo >&2 "Script requires setxkbmap but it is not installed.Aborting."; exit 1; }
command -v setleds   >/dev/null 2>&1 || { echo >&2 "Script requires setleds but it is not installed.Aborting."; exit 1; }

# console
CONSOLE=/dev/console

# disable caps lock key
# This can also be done within Gnome but here is also a good place
setxkbmap -option ctrl:nocaps  >/dev/null 2>&1

# Check interval seconds
CHECKINTERVAL=0.1

#indicator to use [caps, num, scroll]
INDICATOR=caps

getVmstat() {
#  cat /proc/vmstat|
   egrep "pgpgin|pgpgout" /proc/vmstat 
}
#turn led on
function led_on()
{
    setleds -L +${INDICATOR} < ${CONSOLE} >/dev/null 2>&1
}
#turn led off
function led_off()
{
    setleds -L -${INDICATOR} < ${CONSOLE} >/dev/null 2>&1
}
# initialise variables
NEW=$(getVmstat)
OLD=$(getVmstat)
## 
while [ 1 ] ; do
  sleep $CHECKINTERVAL # slowdown a bit
  # get status 
  NEW=$(getVmstat)
  #compare state
  if [ "$NEW" = "$OLD" ]; then  
    led_off ## no change, led off
  else
    led_on  ## change, led on
  fi
  OLD=$NEW  
done

The systemd daemon configuration file (pcfreakled.service)

[Unit]
Description=PCFreaks Dell XPS13 DriveLED

[Service]
Type=simple
ExecStart=/usr/lib/systemd/scripts/pcfreakled

[Install]
WantedBy=multi-user.target

Manual installatiion

Copying files

Copy pcfreakled to

/usr/lib/systemd/scripts/pcfreakled

and make it executable

sudo chmod +x /usr/lib/systemd/scripts/pcfreakled

Copy pcfreakled.service to

/usr/lib/systemd/system/pcfreakled.service

Enable the daemon

sudo systemctl enable pcfreakled.service

Start the daemon

sudo systemctl start pcfreakled.service

Check daemon status

sudo systemctl status pcfreakled.service

Make daemon autostart

sudo systemctl enable pcfreakled.service

Automatic installation

Use the following script

#!/bin/bash

# check if root
if [ "$(id -u)" != "0" ]; then
	echo "please run this script as root or with sudo"
	exit
fi

#very simple install/uninstall script for PCFreak HDD LED systemd service
myfile=./pcfreakled
myfiletarget=/usr/lib/systemd/scripts/pcfreakled
mydaemon=./pcfreakled.service
mydaemontarget=/usr/lib/systemd/system/pcfreakled.service
myservice=pcfreakled.service
myserviceshort=pcfreakled

case "$1" in
	install)
	echo "placing $myfile in $myfiletarget..."
	cp "$myfile" "$myfiletarget"
	echo "...done!"
	echo "placing $mydaemon in $mydaemontarget..."
	cp "$mydaemon" "$mydaemontarget"
	echo "...done!"
	systemctl daemon-reload
	echo "You can now enable/disable/start $myservice with systemctl command!"
	exit
	;;

	remove)
	echo "Trying to stop $myservice..."
	systemctl stop $myservice
	echo "Trying to disable $myservice..."
	systemctl disable $myservice
	echo "Trying to kill all remaining processes..."
	killall $myserviceshort
	echo "Removing $myfiletarget..."
	rm "$myfiletarget"
	echo "...done!"
	echo "Removing $mydaemontarget..."
	rm "$mydaemontarget"
	echo "...done!"
	echo "Uninstall complete!"
	exit
	;;

	*)
	echo "run with parameter install or remove"
	exit
	;;
esac

and make it executable

chmod +x ./setup

then execute

sudo ./setup install
<code>

for installation or

<code>
sudo ./setup remove

for uninstallation.

public/linux/xps13driveled.txt · Last modified: 2015/08/11 14:37 by pcfreak
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0