-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·208 lines (181 loc) · 8.48 KB
/
entrypoint.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash -e
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [[ "${XPRA_ARGS}" =~ use-display=yes ]]; then
echo "Waiting for host X server at ${DISPLAY}"
until [[ -e /var/run/appconfig/xserver_ready ]]; do sleep 1; done
echo "Host X server is ready"
fi
# Workaround for vulkan initialization
# https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-390/+bug/1769857
[[ -c /dev/nvidiactl ]] && (cd /tmp && sudo LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DISPLAY=${DISPLAY} vulkaninfo >/dev/null || true)
# Write html5 client default settings
echo "INFO: writing HTML5 default-settings.txt"
if [[ -n "${XPRA_HTML5_DEFAULT_SETTINGS}" ]]; then
sudo rm -f /usr/share/xpra/www/default-settings.txt.*
echo "${XPRA_HTML5_DEFAULT_SETTINGS}" | sudo tee /usr/share/xpra/www/default-settings.txt
fi
# Copy clipboard direction so that it can be passed to the html5 client.
echo "clipboard_direction = ${XPRA_CLIPBOARD_DIRECTION:-"both"}" | sudo tee -a /usr/share/xpra/www/default-settings.txt
# Set default Selkies xpra-html5 settings.
[[ -z "${XPRA_HTML5_SETTING_video}" ]] && export XPRA_HTML5_SETTING_video="false"
[[ -z "${XPRA_HTML5_SETTING_encoding}" ]] && export XPRA_HTML5_SETTING_encoding="jpeg"
[[ -z "${XPRA_HTML5_SETTING_keyboard}" ]] && export XPRA_HTML5_SETTING_keyboard="false"
[[ -z "${XPRA_HTML5_SETTING_autohide}" ]] && export XPRA_HTML5_SETTING_autohide="true"
[[ -z "${XPRA_HTML5_SETTING_floating_menu}" ]] && export XPRA_HTML5_SETTING_floating_menu="true"
[[ -z "${XPRA_HTML5_SETTING_window_tray}" ]] && export XPRA_HTML5_SETTING_window_tray="true"
[[ -z "${XPRA_HTML5_SETTING_toolbar_position}" ]] && export XPRA_HTML5_SETTING_toolbar_position="top"
[[ -z "${XPRA_HTML5_SETTING_device_dpi_scaling}" ]] && export XPRA_HTML5_SETTING_device_dpi_scaling="true"
[[ -z "${XPRA_HTML5_SETTING_browser_native_notifications}" ]] && export XPRA_HTML5_SETTING_browser_native_notifications="false"
# Path prefix for xpra when behind nginx proxy.
[[ -z "${XPRA_HTML5_SETTING_path}" && -n "${XPRA_WS_PATH}" ]] && export XPRA_HTML5_SETTING_path="${XPRA_WS_PATH}"
# Write variables prefixed with XPRA_HTML5_SETTING_ to default-settings file
for v in "${!XPRA_HTML5_SETTING_@}"; do
setting_name=${v/XPRA_HTML5_SETTING_/}
setting_value=$(eval echo \$$v)
echo "$setting_name = $setting_value" | sudo tee -a /usr/share/xpra/www/default-settings.txt
done
# Add TCP module to Xpra pulseaudio server command to share pulse server with sidecars.
if [[ "${XPRA_ENABLE_AUDIO:-false}" == "true" ]]; then
sudo sed -i -e 's|^pulseaudio-command = pulseaudio|pulseaudio-command = pulseaudio "--load=module-native-protocol-tcp port=4713 auth-anonymous=1"|g' \
/etc/xpra/conf.d/60_server.conf
XPRA_ARGS="${XPRA_ARGS} --sound-source=pulsesrc --speaker-codec=opus+mka"
echo "sound = true" | sudo tee -a /usr/share/xpra/www/default-settings.txt
echo "audio_codec = opus" | sudo tee -a /usr/share/xpra/www/default-settings.txt
export GST_DEBUG=${GST_DEBUG:-"*:2"}
else
XPRA_ARGS="${XPRA_ARGS} --no-pulseaudio"
echo "sound = false" | sudo tee -a /usr/share/xpra/www/default-settings.txt
fi
# Make default-settings.txt entries unique
uniq /usr/share/xpra/www/default-settings.txt > /tmp/default-settings.txt && \
sudo mv /tmp/default-settings.txt /usr/share/xpra/www/default-settings.txt
sudo rm -f /usr/share/xpra/www/default-settings.txt.gz
if [[ -n "${XPRA_CONF}" ]]; then
echo "INFO: echo writing xpra conf to /etc/xpra/conf.d/99_appconfig.conf"
echo "${XPRA_CONF}" | sudo tee /etc/xpra/conf.d/99_appconfig.conf
fi
# Update PWA manifest.json with app info and route.
sudo sed -i \
-e "s|XPRA_PWA_APP_NAME|${XPRA_PWA_APP_NAME:-Xpra Desktop}|g" \
-e "s|XPRA_PWA_APP_PATH|${XPRA_PWA_APP_PATH:-xpra-desktop}|g" \
'/usr/share/xpra/www/manifest.json'
sudo sed -i \
-e "s|XPRA_PWA_DISPLAY|${XPRA_PWA_DISPLAY:-minimal-ui}|g" \
'/usr/share/xpra/www/manifest.json'
sudo sed -i \
-e "s|XPRA_PWA_CACHE|${XPRA_PWA_APP_PATH:-xpra-desktop}-xpra-pwa|g" \
'/usr/share/xpra/www/sw.js'
if [[ -n "${XPRA_PWA_ICON_URL}" ]]; then
echo "INFO: Converting icon to PWA standard"
DEST_FILE=/tmp/icon.png
if [[ "${XPRA_PWA_ICON_URL}" =~ "data:image/png;base64" ]]; then
echo "${XPRA_PWA_ICON_URL}" | cut -d ',' -f2 | base64 -d > ${DEST_FILE}
elif [[ "${XPRA_PWA_ICON_URL}" =~ "data:image/svg+xml;base64" ]]; then
DEST_FILE=/tmp/icon.svg
echo "${XPRA_PWA_ICON_URL}" | cut -d ',' -f2 | base64 -d > /tmp/icon.svg
else
curl -o ${DEST_FILE} -s -f -L "${XPRA_PWA_ICON_URL}" || true
fi
if [[ -e ${DEST_FILE} ]]; then
echo "INFO: Creating PWA icon sizes"
sudo convert -background none ${DEST_FILE} /usr/share/xpra/www/icon.png || true
rm -f ${DEST_FILE}
for size in 180x180 192x192 512x512; do
sudo convert -resize ${size} -background none -gravity center -extent ${size} /usr/share/xpra/www/icon.png /usr/share/xpra/www/icon-${size}.png || true
done
sudo ln -s /usr/share/xpra/www/icon-180x180.png /usr/share/xpra/www/apple-touch-icon.png || true
else
echo "WARN: failed to download PWA icon, PWA features may not be available: ${XPRA_PWA_ICON_URL}"
fi
fi
# Start dbus
sudo rm -rf /var/run/dbus
dbus-uuidgen | sudo tee /var/lib/dbus/machine-id
sudo mkdir -p /var/run/dbus
sudo dbus-daemon --system
echo "Starting CUPS"
sudo cupsd
sudo sed -i 's/^add-printer-options = -u .*/add-printer-options = -u allow:all/g' /etc/xpra/conf.d/16_printing.conf
until lpinfo -v | grep -q xpraforwarder; do sleep 1; done
echo "CUPS is ready"
echo "Starting Xpra"
sudo mkdir -p /var/log/xpra
sudo chmod 777 /var/log/xpra
function watchLogs() {
touch /var/log/xpra/xpra.log
tail -n+1 -F /var/log/xpra/xpra.log | while read line; do
ts=$(date)
echo "$line"
if [[ "${line}" =~ "startup complete" ]]; then
echo "INFO: Saw Xpra startup complete: ${line}"
echo "$ts" > /var/run/appconfig/.xpra-startup-complete
fi
if [[ "${line}" =~ "connection-established" ]]; then
echo "INFO: Saw Xpra client connected: ${line}"
echo "$ts" > /var/run/appconfig/.xpra-client-connected
fi
if [[ "${line}" =~ "client display size is" ]]; then
echo "INFO: Saw Xpra client display size change: ${line}"
echo ${line/*client display size is /} | cut -d' ' -f1 > /var/run/appconfig/xpra_display_size
fi
if [[ "${line}" =~ "client root window size is" ]]; then
echo "INFO: Saw Xpra client display size change: ${line}"
echo ${line/*client root window size is /} | cut -d' ' -f1 > /var/run/appconfig/xpra_display_size
fi
done
}
# Watch the xpra logs for key events and client resolution changes
watchLogs &
# Start nginx proxy
if [[ "${XPRA_DISABLE_PROXY:-false}" == "false" ]]; then
sudo sed -i "s|proxy_pass .*;|proxy_pass http://127.0.0.1:${XPRA_PORT:-8882};|g" /etc/nginx/conf.d/default.conf
sudo nginx
sudo tail -F /var/log/nginx/{access,error}.log &
fi
set -o pipefail
while true; do
echo "" > /var/log/xpra/xpra.log
rm -f /var/run/appconfig/xserver_ready
rm -f /var/run/appconfig/xpra_ready
rm -f /var/run/appconfig/.xpra-client-connected
xpra ${XPRA_START:-"start"} ${DISPLAY} \
--resize-display=${XPRA_RESIZE_DISPLAY:-"yes"} \
--user=app \
--bind-tcp=0.0.0.0:${XPRA_PORT:-8882} \
--html=on \
--daemon=yes \
--log-dir=/var/log/xpra \
--log-file=xpra.log \
--pidfile=/var/run/xpra/xpra.pid \
--bell=${XPRA_ENABLE_BELL:-"no"} \
--clipboard=${XPRA_ENABLE_CLIPBOARD:-"yes"} \
--clipboard-direction=${XPRA_CLIPBOARD_DIRECTION:-"both"} \
--file-transfer=${XPRA_FILE_TRANSFER:-"on"} \
--open-files=${XPRA_OPEN_FILES:-"on"} \
--printing=${XPRA_ENABLE_PRINTING:-"yes"} \
${XPRA_ARGS}
# Wait for Xpra client
echo "Waiting for Xpra client"
until [[ -f /var/run/appconfig/.xpra-startup-complete ]]; do sleep 1; done
until [[ -f /var/run/appconfig/.xpra-client-connected ]]; do sleep 1; done
echo "Xpra is ready"
xhost +
touch /var/run/appconfig/xserver_ready
touch /var/run/appconfig/xpra_ready
PID=$(cat /var/run/xpra/xpra.pid)
echo "Waiting for Xpra to exit, pid: $PID"
tail --pid=$PID -f /dev/null
sleep 1
done