Update docker-entrypoint.sh
This commit is contained in:
+149
-37
@@ -2,92 +2,204 @@
|
|||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
readonly LOG_PREFIX="[wine-desktop]"
|
readonly LOG_PREFIX="[wine-desktop]"
|
||||||
|
|
||||||
DISPLAY="${DISPLAY:-:0}"
|
DISPLAY="${DISPLAY:-:0}"
|
||||||
export DISPLAY
|
|
||||||
DISPLAY_WIDTH="${DISPLAY_WIDTH:-1280}"
|
DISPLAY_WIDTH="${DISPLAY_WIDTH:-1280}"
|
||||||
DISPLAY_HEIGHT="${DISPLAY_HEIGHT:-720}"
|
DISPLAY_HEIGHT="${DISPLAY_HEIGHT:-720}"
|
||||||
DISPLAY_DEPTH="${DISPLAY_DEPTH:-24}"
|
DISPLAY_DEPTH="${DISPLAY_DEPTH:-24}"
|
||||||
|
|
||||||
VNC_PORT="${VNC_PORT:-5900}"
|
VNC_PORT="${VNC_PORT:-5900}"
|
||||||
NOVNC_PORT="${NOVNC_PORT:-6080}"
|
NOVNC_PORT="${NOVNC_PORT:-6080}"
|
||||||
|
|
||||||
|
ENABLE_VNC="${ENABLE_VNC:-true}"
|
||||||
|
ENABLE_NOVNC="${ENABLE_NOVNC:-true}"
|
||||||
|
|
||||||
WINEPREFIX="${WINEPREFIX:-/home/container/.wine}"
|
WINEPREFIX="${WINEPREFIX:-/home/container/.wine}"
|
||||||
export DISPLAY DISPLAY_WIDTH DISPLAY_HEIGHT DISPLAY_DEPTH VNC_PORT NOVNC_PORT WINEPREFIX
|
|
||||||
|
export \
|
||||||
|
DISPLAY \
|
||||||
|
DISPLAY_WIDTH \
|
||||||
|
DISPLAY_HEIGHT \
|
||||||
|
DISPLAY_DEPTH \
|
||||||
|
VNC_PORT \
|
||||||
|
NOVNC_PORT \
|
||||||
|
ENABLE_VNC \
|
||||||
|
ENABLE_NOVNC \
|
||||||
|
WINEPREFIX
|
||||||
|
|
||||||
children=()
|
children=()
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
trap - EXIT INT TERM
|
trap - EXIT INT TERM
|
||||||
|
|
||||||
for pid in "${children[@]:-}"; do
|
for pid in "${children[@]:-}"; do
|
||||||
kill "$pid" 2>/dev/null || true
|
[[ -n "${pid:-}" ]] && kill "$pid" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup EXIT INT TERM
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
log() { echo "${LOG_PREFIX} $*"; }
|
log() {
|
||||||
|
echo "${LOG_PREFIX} $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# X Server
|
||||||
|
#
|
||||||
if ! xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
|
if ! xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
|
||||||
log "Starting Xvfb on ${DISPLAY} (${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}x${DISPLAY_DEPTH})"
|
log "Starting Xvfb on ${DISPLAY} (${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}x${DISPLAY_DEPTH})"
|
||||||
Xvfb "$DISPLAY" -screen 0 "${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}x${DISPLAY_DEPTH}" -ac +extension GLX +render -noreset &
|
|
||||||
|
Xvfb \
|
||||||
|
"$DISPLAY" \
|
||||||
|
-screen 0 "${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}x${DISPLAY_DEPTH}" \
|
||||||
|
-ac \
|
||||||
|
+extension GLX \
|
||||||
|
+render \
|
||||||
|
-noreset &
|
||||||
|
|
||||||
children+=("$!")
|
children+=("$!")
|
||||||
|
|
||||||
for _ in {1..50}; do
|
for _ in {1..50}; do
|
||||||
xdpyinfo -display "$DISPLAY" >/dev/null 2>&1 && break
|
if xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
|
if ! xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
|
||||||
log "X server did not become ready"
|
log "X server failed to start."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Runtime
|
||||||
|
#
|
||||||
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp/runtime-${USER:-container}}"
|
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp/runtime-${USER:-container}}"
|
||||||
mkdir -p "$XDG_RUNTIME_DIR"
|
mkdir -p "$XDG_RUNTIME_DIR"
|
||||||
chmod 0700 "$XDG_RUNTIME_DIR"
|
chmod 700 "$XDG_RUNTIME_DIR"
|
||||||
|
|
||||||
|
#
|
||||||
|
# D-Bus
|
||||||
|
#
|
||||||
if command -v dbus-launch >/dev/null 2>&1; then
|
if command -v dbus-launch >/dev/null 2>&1; then
|
||||||
eval "$(dbus-launch --sh-syntax)"
|
eval "$(dbus-launch --sh-syntax)"
|
||||||
children+=("${DBUS_SESSION_BUS_PID:-}")
|
[[ -n "${DBUS_SESSION_BUS_PID:-}" ]] && children+=("$DBUS_SESSION_BUS_PID")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# PulseAudio
|
||||||
|
#
|
||||||
if command -v pulseaudio >/dev/null 2>&1 && ! pgrep -x pulseaudio >/dev/null 2>&1; then
|
if command -v pulseaudio >/dev/null 2>&1 && ! pgrep -x pulseaudio >/dev/null 2>&1; then
|
||||||
log "Starting PulseAudio"
|
log "Starting PulseAudio"
|
||||||
pulseaudio --system --daemonize=yes --disallow-exit --exit-idle-time=-1 >/tmp/wine-desktop-pulseaudio.log 2>&1 || \
|
|
||||||
log "PulseAudio could not start; applications may run without audio"
|
pulseaudio \
|
||||||
|
--system \
|
||||||
|
--daemonize=yes \
|
||||||
|
--disallow-exit \
|
||||||
|
--exit-idle-time=-1 \
|
||||||
|
>/tmp/wine-desktop-pulseaudio.log 2>&1 \
|
||||||
|
|| log "PulseAudio could not start; continuing without audio."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# XFCE
|
||||||
|
#
|
||||||
if ! pgrep -x xfce4-session >/dev/null 2>&1; then
|
if ! pgrep -x xfce4-session >/dev/null 2>&1; then
|
||||||
log "Starting XFCE desktop"
|
log "Starting XFCE"
|
||||||
|
|
||||||
startxfce4 >/tmp/wine-desktop-xfce.log 2>&1 &
|
startxfce4 >/tmp/wine-desktop-xfce.log 2>&1 &
|
||||||
children+=("$!")
|
children+=("$!")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vnc_args=(-display "$DISPLAY" -rfbport "$VNC_PORT" -forever -shared -nopw)
|
#
|
||||||
if [[ -n "${VNC_PASSWORD:-}" ]]; then
|
# x11vnc
|
||||||
password_file="${WINEPREFIX}/.vncpasswd"
|
#
|
||||||
mkdir -p "$WINEPREFIX"
|
case "${ENABLE_VNC,,}" in
|
||||||
x11vnc -storepasswd "$VNC_PASSWORD" "$password_file" >/dev/null
|
true|1|yes|on)
|
||||||
chmod 0600 "$password_file"
|
|
||||||
vnc_args=(-display "$DISPLAY" -rfbport "$VNC_PORT" -forever -shared -rfbauth "$password_file")
|
|
||||||
fi
|
|
||||||
log "Starting x11vnc on TCP ${VNC_PORT}"
|
|
||||||
x11vnc "${vnc_args[@]}" >/tmp/wine-desktop-x11vnc.log 2>&1 &
|
|
||||||
children+=("$!")
|
|
||||||
|
|
||||||
novnc_web="/usr/share/novnc"
|
vnc_args=(
|
||||||
[[ -d "$novnc_web" ]] || novnc_web="/usr/share/novnc/utils"
|
-display "$DISPLAY"
|
||||||
log "Starting noVNC on TCP ${NOVNC_PORT}"
|
-rfbport "$VNC_PORT"
|
||||||
websockify --web="$novnc_web" "${NOVNC_PORT}" "localhost:${VNC_PORT}" >/tmp/wine-desktop-novnc.log 2>&1 &
|
-forever
|
||||||
children+=("$!")
|
-shared
|
||||||
|
-nopw
|
||||||
|
)
|
||||||
|
|
||||||
|
if [[ -n "${VNC_PASSWORD:-}" ]]; then
|
||||||
|
password_file="${WINEPREFIX}/.vncpasswd"
|
||||||
|
|
||||||
|
mkdir -p "$WINEPREFIX"
|
||||||
|
|
||||||
|
x11vnc -storepasswd "$VNC_PASSWORD" "$password_file" >/dev/null
|
||||||
|
chmod 600 "$password_file"
|
||||||
|
|
||||||
|
vnc_args=(
|
||||||
|
-display "$DISPLAY"
|
||||||
|
-rfbport "$VNC_PORT"
|
||||||
|
-forever
|
||||||
|
-shared
|
||||||
|
-rfbauth "$password_file"
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Starting x11vnc on TCP ${VNC_PORT}"
|
||||||
|
|
||||||
|
x11vnc "${vnc_args[@]}" \
|
||||||
|
>/tmp/wine-desktop-x11vnc.log 2>&1 &
|
||||||
|
|
||||||
|
children+=("$!")
|
||||||
|
|
||||||
|
#
|
||||||
|
# noVNC
|
||||||
|
#
|
||||||
|
case "${ENABLE_NOVNC,,}" in
|
||||||
|
true|1|yes|on)
|
||||||
|
|
||||||
|
novnc_web="/usr/share/novnc"
|
||||||
|
[[ -d "$novnc_web" ]] || novnc_web="/usr/share/novnc/utils"
|
||||||
|
|
||||||
|
log "Starting noVNC on TCP ${NOVNC_PORT}"
|
||||||
|
|
||||||
|
websockify \
|
||||||
|
--web="$novnc_web" \
|
||||||
|
"${NOVNC_PORT}" \
|
||||||
|
"localhost:${VNC_PORT}" \
|
||||||
|
>/tmp/wine-desktop-novnc.log 2>&1 &
|
||||||
|
|
||||||
|
children+=("$!")
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
log "noVNC disabled."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
log "VNC disabled (noVNC automatically disabled)."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
#
|
||||||
|
# Wine Prefix
|
||||||
|
#
|
||||||
mkdir -p "$WINEPREFIX"
|
mkdir -p "$WINEPREFIX"
|
||||||
|
|
||||||
if [[ ! -f "$WINEPREFIX/system.reg" ]]; then
|
if [[ ! -f "$WINEPREFIX/system.reg" ]]; then
|
||||||
log "Initializing Wine prefix at ${WINEPREFIX}"
|
log "Initializing Wine prefix..."
|
||||||
wineboot --init >/tmp/wine-desktop-wineboot.log 2>&1 || {
|
|
||||||
log "Wine prefix initialization failed; see /tmp/wine-desktop-wineboot.log"
|
if ! wineboot --init >/tmp/wine-desktop-wineboot.log 2>&1; then
|
||||||
|
log "Wine prefix initialization failed."
|
||||||
|
log "See: /tmp/wine-desktop-wineboot.log"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# The inherited command remains the official yolk command, normally:
|
log "Wine Desktop is ready."
|
||||||
# /bin/bash /entrypoint.sh. This preserves its update, winetricks, startup,
|
|
||||||
# and signal behavior while tini remains PID 1.
|
#
|
||||||
log "Starting inherited Wine command: $*"
|
# Execute inherited yolk entrypoint
|
||||||
exec "$@"
|
#
|
||||||
|
log "Starting inherited command: $*"
|
||||||
|
exec "$@"
|
||||||
Reference in New Issue
Block a user