Adjustments to support workstation mode
This commit is contained in:
21
distfiles/usr/local/bin/cloneuser
Executable file
21
distfiles/usr/local/bin/cloneuser
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# cloneuser
|
||||
|
||||
SRC=$1
|
||||
DEST=$2
|
||||
|
||||
SRC_GROUPS=`id -Gn ${SRC}`
|
||||
SRC_SHELL=$(awk -F : -v name=${SRC} '(name == $1) { print $7 }' /etc/passwd)
|
||||
RAND_PW=`date +%s | sha256sum | base64 | head -c 32 ; echo`
|
||||
|
||||
echo "Creating user $DEST"
|
||||
useradd --shell ${SRC_SHELL} --password ${RAND_PW} --create-home ${DEST}
|
||||
for grp in ${SRC_GROUPS};do
|
||||
if [ "$grp" != "$SRC" ]; then
|
||||
echo "Adding user $DEST to group $grp."
|
||||
usermod -a -G $grp ${DEST}
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
7
distfiles/usr/local/bin/kiosk_cleanup
Executable file
7
distfiles/usr/local/bin/kiosk_cleanup
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
# kiosk_cleanup
|
||||
|
||||
rm -rf $HOME/.{config,cache}/chromium/
|
||||
rm -rf /dev/shm/target.pdf
|
||||
pkill xmessage
|
||||
|
||||
27
distfiles/usr/local/bin/kiosk_viewhtml
Executable file
27
distfiles/usr/local/bin/kiosk_viewhtml
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# kiosk_viewhtml
|
||||
|
||||
if [ "$1" = "" ]
|
||||
then
|
||||
"usage: kiosk_viewhtml <url> <config file path>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
url="$1"
|
||||
conf_file="$2"
|
||||
|
||||
source $conf_file
|
||||
if [[ "$EUID" == "0" || $(who|cut -d" " -f1) == "kioskuser" ]]
|
||||
then
|
||||
# Use standalone args
|
||||
chromargs="--test-type --ignore-certificate-errors --kiosk --no-first-run --check-for-update-interval=1 --simulate-upgrade --incognito"
|
||||
else
|
||||
# Use workstation args
|
||||
chromargs="--test-type --ignore-certificate-errors --start-fullscreen --no-first-run --check-for-update-interval=1 --simulate-upgrade --incognito"
|
||||
fi
|
||||
if ! chromium $chromargs $url
|
||||
then
|
||||
kiosk_cleanup.sh
|
||||
xmessage -buttons "Ok:1" -center "Failed to retrieve web page."
|
||||
exit 1
|
||||
fi
|
||||
29
distfiles/usr/local/bin/kiosk_viewpdf
Executable file
29
distfiles/usr/local/bin/kiosk_viewpdf
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
# kiosk_viewpdf
|
||||
|
||||
if [ "$1" = "" ]
|
||||
then
|
||||
"usage: kiosk_viewpdf <url> <config file path>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
url="$1"
|
||||
conf_file="$2"
|
||||
|
||||
source $conf_file
|
||||
|
||||
if echo "$url" | grep -q '^file:'
|
||||
then
|
||||
filepath=$(echo "$server_url"|cut -d"/" -f2-)
|
||||
xpdf -fullscreen -cont -z width $filepath
|
||||
else
|
||||
if ! wget -q -O /dev/shm/target.pdf $url
|
||||
then
|
||||
kiosk_cleanup.sh
|
||||
xmessage -buttons "Ok:1" -center "Failed to retrieve pdf file."
|
||||
exit 1
|
||||
else
|
||||
xpdf -fullscreen -cont -z width /dev/shm/target.pdf
|
||||
fi
|
||||
fi
|
||||
|
||||
221
distfiles/usr/local/bin/openkiosk
Executable file
221
distfiles/usr/local/bin/openkiosk
Executable file
@@ -0,0 +1,221 @@
|
||||
#!/bin/bash
|
||||
# openkiosk
|
||||
|
||||
if [[ "$EUID" == "0" || $(who|cut -d" " -f1) == "kioskuser" ]]
|
||||
then
|
||||
conf_file="/etc/openkiosk/openkiosk.conf"
|
||||
run_type="standalone"
|
||||
else
|
||||
if [[ ! -e "$HOME/.config/openkiosk/openkiosk.conf" ]]
|
||||
then
|
||||
mkdir -p $HOME/.config/openkiosk
|
||||
cp /etc/openkiosk/openkiosk.conf $HOME/.config/openkiosk/
|
||||
fi
|
||||
conf_file="$HOME/.config/openkiosk/openkiosk.conf"
|
||||
run_type="workstation"
|
||||
fi
|
||||
if [[ ! -e "$conf_file" ]]
|
||||
then
|
||||
echo "Couldn't find config file. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source $conf_file
|
||||
|
||||
|
||||
function set_commands() {
|
||||
source $conf_file
|
||||
if [[ $TGT_URL == "test" ]]
|
||||
then
|
||||
# Enter test mode
|
||||
APP_CMD="xterm"
|
||||
ALIVE_STRING="xterm"
|
||||
KILL_CMD="pkill xterm"
|
||||
CLEANUP_CMD="sleep 1"
|
||||
debuglog "Entering test mode"
|
||||
elif echo "$TGT_URL" | grep -q '\.pdf$'
|
||||
then
|
||||
# The URL is a pdf file
|
||||
APP_CMD="kiosk_viewpdf $TGT_URL $conf_file"
|
||||
ALIVE_STRING="xpdf"
|
||||
KILL_CMD="pkill xpdf"
|
||||
CLEANUP_CMD="kiosk_cleanup"
|
||||
debuglog "URL is a pdf file. Command is $APP_CMD"
|
||||
else
|
||||
# Assume the URL returns HTML
|
||||
APP_CMD="kiosk_viewhtml $TGT_URL $conf_file"
|
||||
ALIVE_STRING="chromium"
|
||||
KILL_CMD="pkill chromium"
|
||||
CLEANUP_CMD="kiosk_cleanup"
|
||||
debuglog "URL is an HTML file. Command is $APP_CMD"
|
||||
fi
|
||||
}
|
||||
|
||||
function check_conf() {
|
||||
debuglog "Checking configuration file for changes."
|
||||
new_conf_md5=$(md5sum $conf_file|cut -d " " -f1)
|
||||
debuglog "New config file checksum: $new_conf_md5"
|
||||
curr_conf_md5=$(cat /dev/shm/curr_conf_md5.txt)
|
||||
debuglog "Current config file checksum: $curr_conf_md5"
|
||||
diff <(echo $new_conf_md5) <(echo $curr_conf_md5) >/dev/null 2>&1
|
||||
if [[ "$?" == "1" ]]
|
||||
then
|
||||
debuglog "Config file has changed!"
|
||||
echo $new_conf_md5 > /dev/shm/curr_conf_md5.txt
|
||||
debuglog "Killing application"
|
||||
krestart=true
|
||||
$KILL_CMD
|
||||
$CLEANUP_CMD
|
||||
return 1
|
||||
else
|
||||
krestart=false
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function check_url() {
|
||||
debuglog "Checking URL for changes"
|
||||
if [[ $TGT_URL == "test" ]]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
if echo "$TGT_URL"|grep -q '^http'
|
||||
then
|
||||
new_url_md5=$(wget -q -o /dev/null -O - $TGT_URL|md5sum|cut -d " " -f1)
|
||||
elif echo "$TGT_URL"|grep -q '^file'
|
||||
then
|
||||
filepath=$(echo "$TGT_URL"|cut -d":" -f2-)
|
||||
new_url_md5=$(md5sum $filepath|cut -d " " -f1)
|
||||
else
|
||||
new_url_md5=""
|
||||
fi
|
||||
debuglog "New URL checksum: $new_url_md5"
|
||||
curr_url_md5=$(cat /dev/shm/curr_url_md5.txt)
|
||||
debuglog "Current URL checksum: $curr_url_md5"
|
||||
diff <(echo $new_url_md5) <(echo $curr_url_md5) >/dev/null 2>&1
|
||||
if [[ "$?" == "1" ]]
|
||||
then
|
||||
debuglog "URL has changed!"
|
||||
echo $new_url_md5>/dev/shm/curr_url_md5.txt
|
||||
debuglog "Killing application"
|
||||
krestart=true
|
||||
$KILL_CMD
|
||||
$CLEANUP_CMD
|
||||
return 1
|
||||
else
|
||||
krestart=false
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function debuglog() {
|
||||
if [[ "$DEBUG" == "1" ]]
|
||||
then
|
||||
if [[ "$run_type" == "standalone" ]]
|
||||
then
|
||||
logfile_path="/var/log/openkiosk.log"
|
||||
else
|
||||
logfile_path="$HOME/openkiosk.log"
|
||||
fi
|
||||
if [[ ! -e "$logfile_path" ]]
|
||||
then
|
||||
echo "openkiosk log started : "$(date +%Y-%m-%d %H:%M:%S) > $logfile_path
|
||||
fi
|
||||
echo $(date +%H:%M:%S) "$1">>$logfile_path
|
||||
fi
|
||||
}
|
||||
|
||||
function set_blank_params() {
|
||||
if [[ "$INHIBIT_BLANK" == "1" ]]
|
||||
then
|
||||
xset s off
|
||||
xset -dpms
|
||||
else
|
||||
xset s off
|
||||
xset +dpms
|
||||
xset dpms $DSP_STBY_SEC $DSP_SUSP_SEC $DSP_OFF_SEC
|
||||
fi
|
||||
}
|
||||
|
||||
function set_rot_params() {
|
||||
output_name=$(xrandr --listactivemonitors|grep 0:|rev|cut -d " " -f1|rev)
|
||||
xrandr --output $output_name --rotate "normal"
|
||||
sleep 1
|
||||
xrandr --output $output_name --rotate $ROTATION
|
||||
}
|
||||
|
||||
set_commands
|
||||
if [[ "$run_type" == "standalone" ]]
|
||||
then
|
||||
openbox-session &
|
||||
fi
|
||||
sleep 1
|
||||
set_blank_params
|
||||
pkill xpdf
|
||||
pkill chromium
|
||||
pkill xterm
|
||||
kiosk_cleanup
|
||||
|
||||
# start application
|
||||
|
||||
$APP_CMD &
|
||||
sleep 3
|
||||
|
||||
if echo "$TGT_URL"|grep -q '^http'
|
||||
then
|
||||
new_url_md5=$(wget -q -o /dev/null -O - $TGT_URL|md5sum|cut -d " " -f1)
|
||||
elif echo "$TGT_URL"|grep -q '^file'
|
||||
then
|
||||
filepath=$(echo "$TGT_URL"|cut -d":" -f2-)
|
||||
new_url_md5=$(md5sum $filepath|cut -d " " -f1)
|
||||
else
|
||||
new_url_md5=""
|
||||
fi
|
||||
echo $new_url_md5>/dev/shm/curr_url_md5.txt
|
||||
new_conf_md5=$(md5sum $conf_file|cut -d " " -f1)
|
||||
echo $new_conf_md5 > /dev/shm/curr_conf_md5.txt
|
||||
|
||||
while true
|
||||
do
|
||||
|
||||
debuglog "Monitoring for URL and config file changes..."
|
||||
# Pull in changes in the configuration file
|
||||
debuglog "Reading config file"
|
||||
source $conf_file
|
||||
|
||||
if ! pgrep $ALIVE_STRING
|
||||
then
|
||||
# relaunch application if it terminates
|
||||
if $krestart
|
||||
then
|
||||
debuglog "Restarting with command $APP_CMD"
|
||||
$APP_CMD &
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$POLL_INTERVAL" == "0" ]]
|
||||
then
|
||||
sleep 1
|
||||
debuglog "Polling not enabled"
|
||||
if ! check_conf
|
||||
then
|
||||
set_blank_params
|
||||
set_rot_params
|
||||
set_commands
|
||||
fi
|
||||
else
|
||||
sleep $POLL_INTERVAL
|
||||
debuglog "Polling enabled"
|
||||
if ! check_conf
|
||||
then
|
||||
set_blank_params
|
||||
set_rot_params
|
||||
set_commands
|
||||
fi
|
||||
check_url
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user