-
Notifications
You must be signed in to change notification settings - Fork 0
/
textlabel.sh
executable file
·141 lines (125 loc) · 2.95 KB
/
textlabel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /bin/sh
#
# open digital textlabel in chromium on Linux or default browser on macOS
#
# Copyright (c) 2021 ZKM | Hertz-Lab
# Dan Wilcox <dan.wilcox@zkm.de>
#
# BSD Simplified License.
# For information on usage and redistribution, and for a DISCLAIMER OF ALL
# WARRANTIES, see the file, "LICENSE.txt," in this distribution.
#
# This code has been developed at ZKM | Hertz-Lab as part of „The Intelligent
# Museum“ generously funded by the German Federal Cultural Foundation.
##### variables
CHROME=/usr/bin/chromium-browser
HOST=localhost
WEBPORT=8080
WSPORT=8081
DIR=museum-label/textlabel
# platform specifics
case "$(uname -s)" in
Linux*) PLATFORM=linux ;;
Darwin*) PLATFORM=darwin ;;
CYGWIN*) PLATFORM=windows ;;
MINGW*) PLATFORM=windows ;;
*) PLATFORM=unknown ;;
esac
##### functions
# check argument and exit with error if not set
# $1 argument name in error print
# $2 argument
check_arg() {
local arg=$2
local failed=false
if [ "$arg" = "" ] ; then
failed=true
elif [ "${arg%${arg-?}}"x = '-x' ] ; then
failed=true
fi
if [ "$failed" = true ] ; then
echo "$1 option requires an argument"
exit 1
fi
}
##### parse command line arguments
USAGE="$(basename $0) [OPTIONS] COMMAND [CLIENT]"
HELP="USAGE: $USAGE
run digital textlabel in chromium on Linux or default browser on macOS,
assumes webserver and websocket are running on the same host
Options:
-h,--help display this help message
--host STR webserver and websocket host address
ie. ws://####:8081 default: $HOST
--webport INT webserver port
ie. http://localhost:###, default: $WEBPORT
--wsport INT websocket host port
ie. ws://localhost:####, default: $WSPORT
Commands:
start start digital text label
stop stop digital text label
status returns 0 if chromium is running or 1 if not:
textlabel.sh status && echo \"running\"
"
while [ "$1" != "" ] ; do
case $1 in
-h|--help)
echo "$HELP"
exit 0
;;
--host)
shift 1
HOST="$1"
;;
--webport)
shift 1
check_arg "--webport" $1
WEBPORT=$1
;;
--wsport)
shift 1
check_arg "--wsport" $1
WSPORT=$1
;;
*)
break
;;
esac
shift 1
done
CMD=$1
if [ "$CMD" = "" ] ; then
echo "$USAGE"
echo "command required"
exit 1
fi
##### main
URL="http://${HOST}:${WEBPORT}/${DIR}/?host=${HOST}&port=${WSPORT}"
if [ $PLATFORM = darwin ] ; then
# open in default browser on macOS
case $CMD in
start)
open $URL
;;
stop)
;;
status)
exit 0
;;
esac
else
# open in Chromium on Linux
case $CMD in
start)
$CHROME --kiosk --noerrdialogs --disable-restore-session-state --use-gl=egl \
$URL 2> /dev/null
;;
stop)
pkill -o chromium
;;
status)
if pgrep chromium >/dev/null ; then exit 0 ; fi
exit 1
;;
esac
fi