@@ -293,7 +293,7 @@ echo -e "\nSuccess!\n"
293293EOF
294294
295295# Container ENTRYPOINT script
296- cat << ' EOF ' > /usr/local/share/desktop-init.sh
296+ cat << EOF > /usr/local/share/desktop-init.sh
297297#!/bin/bash
298298
299299user_name="${USERNAME} "
@@ -309,67 +309,50 @@ export LANGUAGE="${LANGUAGE:-"en_US.UTF-8"}"
309309# Execute the command it not already running
310310startInBackgroundIfNotRunning()
311311{
312- log "Starting $1."
313- echo -e "\n** $(date) **" | sudoIf tee -a /tmp/\$1.log > /dev/null
314- if ! pgrep -x $1 > /dev/null; then
315- keepRunningInBackground "$@"
316- while ! pgrep -x $1 > /dev/null; do
312+ log "Starting \ $ 1."
313+ echo -e "\n** \ $ (date) **" | sudoIf tee -a /tmp/\$ 1.log > /dev/null
314+ if ! pgrep -x \ $ 1 > /dev/null; then
315+ keepRunningInBackground "\ $ @"
316+ while ! pgrep -x \ $ 1 > /dev/null; do
317317 sleep 1
318318 done
319- log "$1 started."
319+ log "\ $ 1 started."
320320 else
321- echo "$1 is already running." | sudoIf tee -a /tmp/\$1.log > /dev/null
322- log "$1 is already running."
321+ echo "\ $ 1 is already running." | sudoIf tee -a /tmp/\$ 1.log > /dev/null
322+ log "\ $ 1 is already running."
323323 fi
324324}
325325
326326# Keep command running in background
327327keepRunningInBackground()
328328{
329- ($2 bash -c "while :; do echo [\\$(date)] Process started.; $3; echo [\\$(date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/\$1.log > /dev/null & echo "\$!" | sudoIf tee /tmp/\$1.pid > /dev/null)
330- }
331-
332- apt_get_update()
333- {
334- if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
335- echo "Running apt-get update..."
336- apt-get update -y
337- fi
338- }
339-
340- check_packages() {
341- if ! dpkg -s "$@" > /dev/null 2>&1; then
342- apt_get_update
343- apt-get -y install --no-install-recommends "$@"
344- fi
329+ (\$ 2 bash -c "while :; do echo [\\\$ (date)] Process started.; \$ 3; echo [\\\$ (date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/\$ 1.log > /dev/null & echo "\$ !" | sudoIf tee /tmp/\$ 1.pid > /dev/null)
345330}
346331
347332# Use sudo to run as root when required
348333sudoIf()
349334{
350- if [ "$(id -u)" -ne 0 ]; then
351- check_packages sudo
352- sudo "$@"
335+ if [ "\$ (id -u)" -ne 0 ]; then
336+ sudo "\$ @"
353337 else
354- "$@"
338+ "\ $ @"
355339 fi
356340}
357341
358342# Use sudo to run as non-root user if not already running
359343sudoUserIf()
360344{
361- if [ "$(id -u)" -eq 0 ] && [ "${user_name}" != "root" ]; then
362- check_packages sudo
363- sudo -u "${user_name}" "$@"
345+ if [ "\$ (id -u)" -eq 0 ] && [ "\$ {user_name}" != "root" ]; then
346+ sudo -u \$ {user_name} "\$ @"
364347 else
365- "$@"
348+ "\ $ @"
366349 fi
367350}
368351
369352# Log messages
370353log()
371354{
372- echo -e "[$(date)] $@" | sudoIf tee -a $LOG > /dev/null
355+ echo -e "[\ $ (date)] \ $ @" | sudoIf tee -a \ $ LOG > /dev/null
373356}
374357
375358log "** SCRIPT START **"
@@ -388,30 +371,30 @@ done
388371sudoIf rm -rf /tmp/.X11-unix /tmp/.X*-lock
389372mkdir -p /tmp/.X11-unix
390373sudoIf chmod 1777 /tmp/.X11-unix
391- sudoIf chown root:${group_name} /tmp/.X11-unix
392- if [ "$(echo "${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=${VNC_RESOLUTION}x16; fi
393- screen_geometry="${VNC_RESOLUTION%*x*}"
394- screen_depth="${VNC_RESOLUTION##*x}"
374+ sudoIf chown root:\ $ {group_name} /tmp/.X11-unix
375+ if [ "\ $ (echo "\ $ {VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=\ $ {VNC_RESOLUTION}x16; fi
376+ screen_geometry="\ $ {VNC_RESOLUTION%*x*}"
377+ screen_depth="\ $ {VNC_RESOLUTION##*x}"
395378
396379# Check if VNC_PASSWORD is set and use the appropriate command
397- common_options="tigervncserver ${DISPLAY} -geometry ${screen_geometry} -depth ${screen_depth} -rfbport ${VNC_PORT} -dpi ${VNC_DPI:-96} -localhost -desktop fluxbox -fg"
380+ common_options="tigervncserver \ $ {DISPLAY} -geometry \ $ {screen_geometry} -depth \ $ {screen_depth} -rfbport ${VNC_PORT} -dpi \ $ {VNC_DPI:-96} -localhost -desktop fluxbox -fg"
398381
399- if [ -n "${VNC_PASSWORD+x}" ]; then
400- startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
382+ if [ -n "\ $ {VNC_PASSWORD+x}" ]; then
383+ startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "\ $ {common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
401384else
402- startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -SecurityTypes None"
385+ startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "\ $ {common_options} -SecurityTypes None"
403386fi
404387
405388# Spin up noVNC if installed and not running.
406- if [ -d "/usr/local/novnc" ] && [ "$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
389+ if [ -d "/usr/local/novnc" ] && [ "\ $ (ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
407390 keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen ${NOVNC_PORT} --vnc localhost:${VNC_PORT} "
408391 log "noVNC started."
409392else
410393 log "noVNC is already running or not installed."
411394fi
412395
413396# Run whatever was passed in
414- log "Executing \"$@\"."
397+ log "Executing \"\ $ @\"."
415398exec "$@ "
416399log "** SCRIPT EXIT **"
417400EOF
0 commit comments