I use a file that can be sourced into the kiosk script to set a variable. eg:
KIOSK_URL=http://machine/path/
Then in the launching script we set a default value then source the local configuration file in the same way the init scripts in /etc/init.d
and /etc/default
work.
#!/bin/bash
KIOSK_URL=http://machine/default
[ -r /etc/default/kiosk ] && . /etc/default/kiosk
/usr/bin/chromium --kiosk --incognito --start-maximized $KIOSK_URL
So that checks to see if the file exists and is readable then sources it into the current script which overrides the default variable value.
If you want to stick with /home/pi/Desktop/URL
then change /etc/default/kiosk
but be aware the person editing the URL file can inject script commands in that case.
I actually use the following script as this allows the browser to be defined per-system as some of the kiosk displays we use have chromium, chromium-browser or ephiphany-browser. This allows a local configuration file to override the chromium default as we as select a specific url. This uses ratpoison
to get a tiling window manager so that the browser is maximised and unclutter
to remove the mouse pointer from the screen.
kiosk.sh
#!/bin/bash
#
# epiphany-browser is part of the Raspbian Jesse distribution but has less kiosk-friendly features
# than chromium. chromium uses slightly less CPU and memory for our Jenkins status screens too
# but is unavailable for Raspbian Jesse at the moment.
# Create an /etc/default/kiosk file and declare the url there
KIOSK_URL=http://spd-jenkins/view/StatusCore/
KIOSK_BROWSER=/usr/bin/chromium
KIOSK_ARGS='%s --kiosk --incognito --start-maximized'
[ -r /etc/default/kiosk ] && . /etc/default/kiosk
BROWSER_NAME=$(basename $KIOSK_BROWSER)
KIOSK_PARAMS=$(printf "$KIOSK_ARGS" "$KIOSK_URL")
if [ -x /usr/bin/xset ]
then
/usr/bin/xset s off
/usr/bin/xset -dpms
fi
/usr/bin/ratpoison &
[ -x /usr/bin/unclutter ] && /usr/bin/unclutter &
if [ "$BROWSER_NAME" = "epiphany-browser" ]
then
# Make it forget any previous tabs.
[ -e "$HOME/.config/epiphany/session-state.xml" ] && rm -f "$HOME/.config/epiphany/session-state.xml"
# Make the browser fullscreen by faking a F11 key after a suitable delay
xte 'sleep 15' 'key F11' 2>&1 > /dev/null &
fi
$KIOSK_BROWSER $KIOSK_PARAMS
if [ -x /usr/bin/xset ]
then
/usr/bin/xset s on
/usr/bin/xset +dpms
fi
Enabling on startup
To arrange for the kiosk mode display to automatically launch on startup it needs to be added into the X Display Manager which on Raspbian is lightdm. The following lightdm configuration requires a /kiosk/ user account and automatically starts a session as the kiosk user using the session definition in the kiosk.desktop file. This file just calls the script provided above which runs a window manager (ratpoison) and the browser in kiosk mode.
lightdm.config
[LightDM]
minimum-vt=7
seats=seat-0
[GuestAccount]
enabled=false
[SeatDefaults]
pam-service=lightdm-autologin
autologin-user=kiosk
autologin-user-timeout=0
user-session=kiosk
greeter-session=lightdm-gtk-greeter
greeter-hide-users=true
session-wrapper=/etc/X11/Xsession
xserver-command=X -pointer None -allowMouseOpenFail
The user-session=kiosk
line here is what causes it to load the session file from /usr/share/xsessions/kiosk.desktop
and run the program define in that file as the Exec
property.
autologin-user
should be set to a valid local account. I created it using sudo adduser --gecos "Kiosk User,,," --disabled-password kiosk
.
/usr/share/xsessions/kiosk.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Kiosk Mode
Comment=Chromium Kiosk Mode
Exec=/usr/local/bin/kiosk.sh
Type=Application
Power saving
Finally a useful power saving scheme if these are to be on permanently is to use the DPMS management to power off the screens outside office hours. The following script can be called from cron to control the display (depending on the hardware support)
dpms
#!/bin/bash
#
# This machine operates as a display and is on all day. This script
# disables the DPMS setting on the monitor so that the monitor itself
# will not power off after a period of inactivity. We call this from
# a cron job to turn the monitor off an night and over the weekends.
#
# Initially these settings are handled by the kiosh.sh script which
# disables the screen blanking screensaver capability in the X server and
# disables DPMS when we first start up.
DISPLAY=:0.0; export DISPLAY
COOKIE=/var/run/lightdm/root/\:0
function log()
{
logger -p local0.notice -t DPMS $*
}
function dpms_force()
{
xset dpms force $1 && log $1 || log FAILED to set $1
}
if [ $# != 1 ]
then
echo >&2 "usage: dpms on|standby|off"
exit 1
fi
[ -r $COOKIE ] && xauth merge $COOKIE
case "$1" in
on)
# Turn on and disable the DPMS to keep it on.
dpms_force on
xset s reset
xset -dpms
;;
off|standby|suspend)
# Allow to turn off and leave DPMS enabled.
dpms_force $1
;;
*)
echo >&2 "invalid dpms mode \"$1\": must be on, off, standby or suspend"
exit 1
;;
esac
Suggested /etc/crontab
entries (or create a /etc/cron.d/kiosk
file):
#
# Kiosk display power management
#
00 07 * * 1,2,3,4,5 root test -x /usr/local/bin/dpms && /usr/local/bin/dpms on
00 17 * * 1,2,3,4 root test -x /usr/local/bin/dpms && /usr/local/bin/dpms off
00 16 * * 5 root test -x /usr/local/bin/dpms && /usr/local/bin/dpms off