HTPC Big Launcher

IT HTPC

Are you, like me, running a SFF Linux box in your living room, connected to the TV and using it as a HTPC?
A full-featured DE is not fit for purpose. Instead, you need a simple UI that is light on resources and can be easily controlled with a remote from the comfort of your couch.
I am using flex-launcher as Big Launcher UI, with lightweight Openbox WM and Ubuntu 22.04 LTS as OS.

Create a dedicated user

We will first create a new user dedicated to the HTPC. It will autologin to the Openbox at boot and we don't want it to have super-user privileges nor access to more than required.
We will assume your super-user is john. We will create a new user johnhtpc.

Create group first

This will force GID and UID to be in sync. This may seem overkill, but make things easier to manage in the long run. User john and its group johnhtpc probably use the value 1000. If there are no other user on your system, 1001 should be available.

Check if UID and GID 1001 are available:

grep 1001 /etc/passwd
grep 1001 /etc/group

The above commands should return nothing. If they do, try with 1002, 1003, etc., or even 1101...

Create group johnhtpc with GID 1001:

sudo groupadd -g 1001 johnhtpc

Create user

Create user john with UID 1001 and assign its primary group:

sudo useradd --create-home --gid 1001 --groups johnhtpc --uid 1001 --shell /bin/bash johnhtpc

Make user john member of group johnhtpc:

sudo usermod -a -G johnhtpc john

Reboot or login/logout is required for the above change to apply

keyboard-air-mouse-remote

Remote control

Get yourself a keyboard / air-mouse remote for 12 bucks on Amazon.

Disable some buttons

Download and compile latest release of keyd from https://github.com/rvaiya/keyd/releases/latest:

cd /tmp && wget -qO- https://github.com/rvaiya/keyd/archive/refs/tags/v2.4.3.tar.gz | tar xvz
cd keyd* && make && sudo make install
sudo systemctl enable keyd && sudo systemctl start keyd

Identify keys:

sudo keyd monitor

Configure:

sudo touch /etc/keyd/default.conf
nohup gedit admin:///etc/keyd/default.conf &!
>>[ids]
>>248a:8367 #YFish WiFi remote/keyboard/mouse
>>
>>[main]
>>config = noop
>>
>># Prevent opening of thunderbird, do nothing instead
>>mail = noop
>>f2 = noop
>>
>># Prevent opening of firefox, do nothing instead
>>www = noop
>>
>># Homepage is untouched, xbindkeys will start a command
>>homepage = homepage

Check configuration:

sudo journalctl -eu keyd

Set custom action for Home button

For this we will use xbindkeys:

sudo apt install xbindkeys

First, identify the button for which you wish to modify its action:

sudo apt install evtest
sudo evtest

Configure:

sudo -u johnhtpc -g johnhtpc mkdir /home/johnhtpc/xbindkeys
nano /home/johnhtpc/xbindkeys/.xbindkeysrc
>>#Homepage
>>"/home/johnhtpc/scripts/john-htpc-launcher.sh flex-launcher"
>>    m:0x10 + c:180
>>    Mod2 + XF86HomePage

Set up Kodi

See dedicated article: Kodi

Set up YouTube for TV

See dedicated article: Youtube for TV

Set up EZVIZ camera stream

See dedicated article: EZVIZ camera stream

Flex Launcher

Install:

cd /tmp
wget https://github.com/complexlogic/flex-launcher/releases/download/v2.1/flex-launcher_2.1_amd64.deb
sudo apt install ./flex-launcher_2.1_amd64.deb

Configure:

sudo -u johnhtpc -g johnhtpc cp -r /usr/share/flex-launcher /home/johnhtpc/.config
sed -i "s|/usr/share/flex-launcher|/home/johnhtpc/.config/flex-launcher|g" /home/johnhtpc/.config/flex-launcher/config.ini
sudo -u johnhtpc -g johnhtpc nano /home/johnhtpc/.config/flex-launcher/config.ini
[...]
[Main]
Entry1=Kodi;/home/johnhtpc/flex-launcher/assets/icons/kodi.png;/home/johnhtpc/scripts/djzu-htpc-launcher.sh kodi
Entry2=YouTube;/home/johnhtpc/flex-launcher/assets/icons/youtube.png;/home/johnhtpc/scripts/djzu-htpc-launcher.sh yt
Entry3=BabyCam;/home/johnhtpc/flex-launcher/assets/icons/webcam.png;/home/johnhtpc/scripts/djzu-htpc-launcher.sh ezviz

Write launcher script:

sudo -u johnhtpc -g johnhtpc mkdir /home/johnhtpc/scripts
sudo -u johnhtpc -g johnhtpc nano /home/johnhtpc/scripts/john-htpc-launcher.sh
>>#!/bin/bash
>># DjZU
>># Script launched either via KDEconnect app on smartphone or WiFi remote button mapped with xbindkeys
>># Will either focus an already running app or launch it
>>
>># Array of apps
>>declare -A apps=(
>>[flex-launcher]="/usr/bin/flex-launcher -c /home/johnhtpc/flex-launcher/config.ini"
>>[kodi]="/usr/lib/x86_64-linux-gnu/kodi/kodi.bin"
>>[ezviz]="/usr/bin/ffplay -loglevel quiet -fs rtsp://admin:[email protected]:554"
>>[yt]="firefox --profile /home/johnhtpc/.mozilla/firefox/a1bc2def.kiosk --kiosk --new-instance https://www.youtube.com/tv"
>>)
>>
>># Warn of input error and exit
>>if [[ "$1" == "" ]]; then
>>    echo "Please provide app name as argument"
>>    echo "Exiting"
>>    exit 1
>>fi
>>if [[ "${apps[$1]}" == "" ]]; then
>>    echo "App in argument has no associated command"
>>    echo "Exiting"
>>    exit 2
>>fi
>>
>># Terminate apps if requested
>>if [[ "$1" == "none" ]]; then
>>    echo "Will terminate apps"
>>    # Iterate through apps list
>>    for app in "${apps[@]}"; do
>>        # Skip if flex-launcher
>>        [ "$app" ==  "${apps[flex-launcher]}" ] && continue 
>>        # Terminate all matching processes
>>        ps -fu $USER | grep -E "${app%% *}( |$)" | grep -v grep | awk '{print $2}' | xargs -r -n1 /bin/bash -c 'kill "$@" >& /dev/null; timeout 120 tail --pid="$@" -f /dev/null; kill -KILL "$@" >& /dev/null;' '' 
>>        # '%% *' will only keep the first substring before the first space, i.e the command without arguments
>>        # Force kill after 120 seconds timeout
>>    done
>>    exit 0
>>else
>>    # Welcome audio notification
>>    paplay /usr/share/sounds/Oxygen-Im-User-Auth.ogg
>>fi
>>
>># Terminate any other app
>>"$0" none
>>
>># Find window ID
>>wid="$(xdotool search --limit 1 --class $1)"
>>
>>if [ -z "$wid" ]; then    # Requested app is not running yet
>>    # Launch app if its window is not found
>>    echo "Will launch app $1"
>>    setsid ${apps[$1]} >& /dev/null < /dev/null &
>>else
>>    # Focus app if its window is found
>>    echo "Will focus app $1 with window ID $wid"
>>    xdotool windowactivate "$wid" &!
>>fi
>>
>>exit 0

Openbox

Install

sudo apt install openbox

Configure Openbox to autostart flex-launcher

Copy shipped files:

sudo -u johnhtpc -g johnhtpc mkdir -p /home/johnhtpc/.config/openbox
sudo -u johnhtpc -g johnhtpc cp -a /etc/xdg/openbox/ /home/johnhtpc/.config/

Add flex-launcher as last so it is on top of other windows and has focus:

sudo -u johnhtpc -g johnhtpc nano /home/johnhtpc/.config/openbox/autostart
>>(xbindkeys -f /home/johnhtpc/xbindkeys/.xbindkeysrc) &
>>(/home/johnhtpc/scripts/john-htpc-launcher.sh flex-launcher) &

Autologin

sudo nano /etc/lightdm/lightdm.conf
>>autologin-user=johnhtpc

Hide mouse

Install unclutter to hide the mouse cursor after a given number of seconds if you don't use it:

sudo apt install unclutter

Below is what we get. Sit back, take a drink and enjoy!

flex-launcher

Add a comment

Next Post Previous Post