Skip to content

Commit f5f489f

Browse files
[Desktop-lite] - VNC_RESOLUTION unreadable fix - issue #945 fix (#1024)
* [Desktop-lite] - VNC_RESOLUTION unreadable fix - issue #945 * bump to patch version done * changes as suggested * changes - removing escaped variables for init to go smoothly * misc change * few more escaped vars - making them unescaped * misc changes * changes for sudo - command not found error in few test cases
1 parent 1751858 commit f5f489f

File tree

2 files changed

+46
-29
lines changed

2 files changed

+46
-29
lines changed

src/desktop-lite/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "desktop-lite",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"name": "Light-weight Desktop",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/desktop-lite",
66
"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.",

src/desktop-lite/install.sh

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ echo -e "\nSuccess!\n"
293293
EOF
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
299299
user_name="${USERNAME}"
@@ -309,50 +309,67 @@ export LANGUAGE="${LANGUAGE:-"en_US.UTF-8"}"
309309
# Execute the command it not already running
310310
startInBackgroundIfNotRunning()
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
327327
keepRunningInBackground()
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)
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
330345
}
331346
332347
# Use sudo to run as root when required
333348
sudoIf()
334349
{
335-
if [ "\$(id -u)" -ne 0 ]; then
336-
sudo "\$@"
350+
if [ "$(id -u)" -ne 0 ]; then
351+
check_packages sudo
352+
sudo "$@"
337353
else
338-
"\$@"
354+
"$@"
339355
fi
340356
}
341357
342358
# Use sudo to run as non-root user if not already running
343359
sudoUserIf()
344360
{
345-
if [ "\$(id -u)" -eq 0 ] && [ "\${user_name}" != "root" ]; then
346-
sudo -u \${user_name} "\$@"
361+
if [ "$(id -u)" -eq 0 ] && [ "${user_name}" != "root" ]; then
362+
check_packages sudo
363+
sudo -u "${user_name}" "$@"
347364
else
348-
"\$@"
365+
"$@"
349366
fi
350367
}
351368
352369
# Log messages
353370
log()
354371
{
355-
echo -e "[\$(date)] \$@" | sudoIf tee -a \$LOG > /dev/null
372+
echo -e "[$(date)] $@" | sudoIf tee -a $LOG > /dev/null
356373
}
357374
358375
log "** SCRIPT START **"
@@ -371,31 +388,31 @@ done
371388
sudoIf rm -rf /tmp/.X11-unix /tmp/.X*-lock
372389
mkdir -p /tmp/.X11-unix
373390
sudoIf chmod 1777 /tmp/.X11-unix
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}"
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}"
378395
379396
# Check if VNC_PASSWORD is set and use the appropriate command
380-
common_options="tigervncserver \${DISPLAY} -geometry \${screen_geometry} -depth \${screen_depth} -rfbport ${VNC_PORT} -dpi \${VNC_DPI:-96} -localhost -desktop fluxbox -fg"
397+
common_options="tigervncserver ${DISPLAY} -geometry ${screen_geometry} -depth ${screen_depth} -rfbport ${VNC_PORT} -dpi ${VNC_DPI:-96} -localhost -desktop fluxbox -fg"
381398
382-
if [ -n "\${VNC_PASSWORD+x}" ]; then
383-
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "\${common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
399+
if [ -n "${VNC_PASSWORD+x}" ]; then
400+
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
384401
else
385-
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "\${common_options} -SecurityTypes None"
402+
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -SecurityTypes None"
386403
fi
387404
388405
# Spin up noVNC if installed and not running.
389-
if [ -d "/usr/local/novnc" ] && [ "\$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
406+
if [ -d "/usr/local/novnc" ] && [ "$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
390407
keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen ${NOVNC_PORT} --vnc localhost:${VNC_PORT}"
391408
log "noVNC started."
392409
else
393410
log "noVNC is already running or not installed."
394411
fi
395412
396413
# Run whatever was passed in
397-
log "Executing \"\$@\"."
398-
exec "\$@"
414+
log "Executing "\$@\"."
415+
exec "$@"
399416
log "** SCRIPT EXIT **"
400417
EOF
401418

0 commit comments

Comments
 (0)