diff --git a/src/desktop-lite/devcontainer-feature.json b/src/desktop-lite/devcontainer-feature.json index 86eabbdad..ebc04ebad 100644 --- a/src/desktop-lite/devcontainer-feature.json +++ b/src/desktop-lite/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "desktop-lite", - "version": "1.2.2", + "version": "1.2.3", "name": "Light-weight Desktop", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/desktop-lite", "description": "Adds a lightweight Fluxbox based desktop to the container that can be accessed using a VNC viewer or the web. GUI-based commands executed from the built-in VS code terminal will open on the desktop automatically.", diff --git a/src/desktop-lite/install.sh b/src/desktop-lite/install.sh index 83f9635b4..5230425f0 100755 --- a/src/desktop-lite/install.sh +++ b/src/desktop-lite/install.sh @@ -293,7 +293,7 @@ echo -e "\nSuccess!\n" EOF # Container ENTRYPOINT script -cat << 'EOF' > /usr/local/share/desktop-init.sh +cat << EOF > /usr/local/share/desktop-init.sh #!/bin/bash user_name="${USERNAME}" @@ -309,67 +309,50 @@ export LANGUAGE="${LANGUAGE:-"en_US.UTF-8"}" # Execute the command it not already running startInBackgroundIfNotRunning() { - log "Starting $1." - echo -e "\n** $(date) **" | sudoIf tee -a /tmp/\$1.log > /dev/null - if ! pgrep -x $1 > /dev/null; then - keepRunningInBackground "$@" - while ! pgrep -x $1 > /dev/null; do + log "Starting \$1." + echo -e "\n** \$(date) **" | sudoIf tee -a /tmp/\$1.log > /dev/null + if ! pgrep -x \$1 > /dev/null; then + keepRunningInBackground "\$@" + while ! pgrep -x \$1 > /dev/null; do sleep 1 done - log "$1 started." + log "\$1 started." else - echo "$1 is already running." | sudoIf tee -a /tmp/\$1.log > /dev/null - log "$1 is already running." + echo "\$1 is already running." | sudoIf tee -a /tmp/\$1.log > /dev/null + log "\$1 is already running." fi } # Keep command running in background keepRunningInBackground() { - ($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) -} - -apt_get_update() -{ - if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then - echo "Running apt-get update..." - apt-get update -y - fi -} - -check_packages() { - if ! dpkg -s "$@" > /dev/null 2>&1; then - apt_get_update - apt-get -y install --no-install-recommends "$@" - fi + (\$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) } # Use sudo to run as root when required sudoIf() { - if [ "$(id -u)" -ne 0 ]; then - check_packages sudo - sudo "$@" + if [ "\$(id -u)" -ne 0 ]; then + sudo "\$@" else - "$@" + "\$@" fi } # Use sudo to run as non-root user if not already running sudoUserIf() { - if [ "$(id -u)" -eq 0 ] && [ "${user_name}" != "root" ]; then - check_packages sudo - sudo -u "${user_name}" "$@" + if [ "\$(id -u)" -eq 0 ] && [ "\${user_name}" != "root" ]; then + sudo -u \${user_name} "\$@" else - "$@" + "\$@" fi } # Log messages log() { - echo -e "[$(date)] $@" | sudoIf tee -a $LOG > /dev/null + echo -e "[\$(date)] \$@" | sudoIf tee -a \$LOG > /dev/null } log "** SCRIPT START **" @@ -388,22 +371,22 @@ done sudoIf rm -rf /tmp/.X11-unix /tmp/.X*-lock mkdir -p /tmp/.X11-unix sudoIf chmod 1777 /tmp/.X11-unix -sudoIf chown root:${group_name} /tmp/.X11-unix -if [ "$(echo "${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=${VNC_RESOLUTION}x16; fi -screen_geometry="${VNC_RESOLUTION%*x*}" -screen_depth="${VNC_RESOLUTION##*x}" +sudoIf chown root:\${group_name} /tmp/.X11-unix +if [ "\$(echo "\${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=\${VNC_RESOLUTION}x16; fi +screen_geometry="\${VNC_RESOLUTION%*x*}" +screen_depth="\${VNC_RESOLUTION##*x}" # Check if VNC_PASSWORD is set and use the appropriate command -common_options="tigervncserver ${DISPLAY} -geometry ${screen_geometry} -depth ${screen_depth} -rfbport ${VNC_PORT} -dpi ${VNC_DPI:-96} -localhost -desktop fluxbox -fg" +common_options="tigervncserver \${DISPLAY} -geometry \${screen_geometry} -depth \${screen_depth} -rfbport ${VNC_PORT} -dpi \${VNC_DPI:-96} -localhost -desktop fluxbox -fg" -if [ -n "${VNC_PASSWORD+x}" ]; then - startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd" +if [ -n "\${VNC_PASSWORD+x}" ]; then + startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "\${common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd" else - startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -SecurityTypes None" + startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "\${common_options} -SecurityTypes None" fi # Spin up noVNC if installed and not running. -if [ -d "/usr/local/novnc" ] && [ "$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then +if [ -d "/usr/local/novnc" ] && [ "\$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen ${NOVNC_PORT} --vnc localhost:${VNC_PORT}" log "noVNC started." else @@ -411,7 +394,7 @@ else fi # Run whatever was passed in -log "Executing \"$@\"." +log "Executing \"\$@\"." exec "$@" log "** SCRIPT EXIT **" EOF