Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit d03324d

Browse files
authored
Avoid overwriting config files if already present in desktop script (#1103)
1 parent d58376c commit d03324d

File tree

4 files changed

+125
-69
lines changed

4 files changed

+125
-69
lines changed

script-library/container-features/src/feature-scripts.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ _VSC_INSTALL_MAVEN="maven-debian.sh ${_BUILD_ARG_MAVEN_VERSION:-latest}"
1717
_VSC_INSTALL_RUBY="ruby-debian.sh ${_BUILD_ARG_RUBY_VERSION:-latest}"
1818
_VSC_INSTALL_RUST="rust-debian.sh /usr/local/cargo /usr/local/rustup automatic true false ${_BUILD_ARG_RUST_VERSION:-latest} ${_BUILD_ARG_RUST_PROFILE:-minimal}"
1919
_VSC_INSTALL_POWERSHELL="powershell-debian.sh ${_BUILD_ARG_POWERSHELL_VERSION:-latest}"
20-
_VSC_INSTALL_DESKTOP_LITE=desktop-lite-debian.sh
20+
_VSC_INSTALL_DESKTOP_LITE="desktop-lite-debian.sh automatic ${_BUILD_ARG_DESKTOP_LITE_PASSWORD:-vscode} true ${_BUILD_ARG_DESKTOP_LITE_VNCPORT:-5901} ${_BUILD_ARG_DESKTOP_LITE_WEBPORT:-6080}"

script-library/container-features/src/features.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"ruby",
351351
"rust",
352352
"typescript-node",
353-
"Javascript-node",
353+
"javascript-node",
354354
"python-3",
355355
"python-3-anaconda",
356356
"python-3-miniconda",
@@ -457,6 +457,24 @@
457457
"enum": ["latest"],
458458
"default": "latest",
459459
"description": "Currently unused."
460+
},
461+
"password": {
462+
"type": "string",
463+
"proposal": ["vscode","codespaces","password"],
464+
"default": "vscode",
465+
"description": "Enter a password for desktop connections"
466+
},
467+
"webPort": {
468+
"type": "string",
469+
"proposal": ["6080"],
470+
"default": "6080",
471+
"description": "Enter a port for the desktop web client"
472+
},
473+
"vncPort": {
474+
"type": "string",
475+
"proposal": ["5901"],
476+
"default": "5901",
477+
"description": "Enter a port for the desktop VNC server"
460478
}
461479
},
462480
"init": true,

script-library/desktop-lite-debian.sh

Lines changed: 89 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/desktop-lite.md
88
# Maintainer: The VS Code and Codespaces Teams
99
#
10-
# Syntax: ./desktop-lite-debian.sh [non-root user] [vnc password] [install no vnc flag]
10+
# Syntax: ./desktop-lite-debian.sh [non-root user] [Desktop password] [Install web client flag] [VNC port] [Web Port]
1111

1212
USERNAME=${1:-"automatic"}
1313
VNC_PASSWORD=${2:-"vscode"}
1414
INSTALL_NOVNC=${3:-"true"}
15+
VNC_PORT="${4:-5901}"
16+
NOVNC_PORT="${5:-6080}"
1517

1618
NOVNC_VERSION=1.2.0
1719
WEBSOCKETIFY_VERSION=0.10.0
@@ -77,6 +79,71 @@ if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
7779
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
7880
USERNAME=root
7981
fi
82+
# Add default Fluxbox config files if none are already present
83+
fluxbox_apps="$(cat \
84+
<< 'EOF'
85+
[transient] (role=GtkFileChooserDialog)
86+
[Dimensions] {70% 70%}
87+
[Position] (CENTER) {0 0}
88+
[end]
89+
EOF
90+
)"
91+
92+
fluxbox_init="$(cat \
93+
<< 'EOF'
94+
session.configVersion: 13
95+
session.menuFile: ~/.fluxbox/menu
96+
session.keyFile: ~/.fluxbox/keys
97+
session.styleFile: /usr/share/fluxbox/styles/qnx-photon
98+
session.screen0.workspaces: 1
99+
session.screen0.workspacewarping: false
100+
session.screen0.toolbar.widthPercent: 100
101+
session.screen0.strftimeFormat: %a %l:%M %p
102+
session.screen0.toolbar.tools: RootMenu, clock, iconbar, systemtray
103+
session.screen0.workspaceNames: One,
104+
EOF
105+
)"
106+
107+
fluxbox_menu="$(cat \
108+
<< 'EOF'
109+
[begin] ( Application Menu )
110+
[exec] (File Manager) { nautilus ~ } <>
111+
[exec] (Text Editor) { mousepad } <>
112+
[exec] (Terminal) { tilix -w ~ -e $(readlink -f /proc/$$/exe) -il } <>
113+
[exec] (Web Browser) { x-www-browser --disable-dev-shm-usage } <>
114+
[submenu] (System) {}
115+
[exec] (Set Resolution) { tilix -t "Set Resolution" -e bash /usr/local/bin/set-resolution } <>
116+
[exec] (Edit Application Menu) { mousepad ~/.fluxbox/menu } <>
117+
[exec] (Passwords and Keys) { seahorse } <>
118+
[exec] (Top Processes) { tilix -t "Top" -e htop } <>
119+
[exec] (Disk Utilization) { tilix -t "Disk Utilization" -e ncdu / } <>
120+
[exec] (Editres) {editres} <>
121+
[exec] (Xfontsel) {xfontsel} <>
122+
[exec] (Xkill) {xkill} <>
123+
[exec] (Xrefresh) {xrefresh} <>
124+
[end]
125+
[config] (Configuration)
126+
[workspaces] (Workspaces)
127+
[end]
128+
EOF
129+
)"
130+
131+
# Copy config files if the don't already exist
132+
copy_fluxbox_config() {
133+
local target_dir="$1"
134+
mkdir -p "${target_dir}/.fluxbox"
135+
touch "${target_dir}/.Xmodmap"
136+
if [ ! -e "${target_dir}/.fluxbox/apps" ]; then
137+
echo "${fluxbox_apps}" > "${target_dir}/.fluxbox/apps"
138+
fi
139+
if [ ! -e "${target_dir}/.fluxbox/init" ]; then
140+
echo "${fluxbox_init}" > "${target_dir}/.fluxbox/init"
141+
fi
142+
if [ ! -e "${target_dir}/.fluxbox/menu" ]; then
143+
echo "${fluxbox_menu}" > "${target_dir}/.fluxbox/menu"
144+
fi
145+
}
146+
80147

81148
# Function to run apt-get if needed
82149
apt_get_update_if_needed()
@@ -163,11 +230,10 @@ if [ "${INSTALL_NOVNC}" = "true" ] && [ ! -d "/usr/local/novnc" ]; then
163230
fi
164231

165232
# Set up folders for scripts and init files
166-
mkdir -p /var/run/dbus /usr/local/etc/vscode-dev-containers/ /root/.fluxbox
233+
mkdir -p /var/run/dbus /usr/local/etc/vscode-dev-containers/
167234

168235
# Script to change resolution of desktop
169-
tee /usr/local/bin/set-resolution > /dev/null \
170-
<< EOF
236+
cat << EOF > /usr/local/bin/set-resolution
171237
#!/bin/bash
172238
RESOLUTION=\${1:-\${VNC_RESOLUTION:-1920x1080}}
173239
DPI=\${2:-\${VNC_DPI:-96}}
@@ -204,8 +270,7 @@ echo -e "\nSuccess!\n"
204270
EOF
205271

206272
# Container ENTRYPOINT script
207-
tee /usr/local/share/desktop-init.sh > /dev/null \
208-
<< EOF
273+
cat << EOF > /usr/local/share/desktop-init.sh
209274
#!/bin/bash
210275
211276
USERNAME=${USERNAME}
@@ -286,11 +351,11 @@ sudoIf chown root:\${USERNAME} /tmp/.X11-unix
286351
if [ "\$(echo "\${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=\${VNC_RESOLUTION}x16; fi
287352
screen_geometry="\${VNC_RESOLUTION%*x*}"
288353
screen_depth="\${VNC_RESOLUTION##*x}"
289-
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "tigervncserver \${DISPLAY} -geometry \${screen_geometry} -depth \${screen_depth} -rfbport \${VNC_PORT:-5901} -dpi \${VNC_DPI:-96} -localhost -desktop fluxbox -fg -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
354+
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "tigervncserver \${DISPLAY} -geometry \${screen_geometry} -depth \${screen_depth} -rfbport ${VNC_PORT} -dpi \${VNC_DPI:-96} -localhost -desktop fluxbox -fg -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
290355
291356
# Spin up noVNC if installed and not runnning.
292357
if [ -d "/usr/local/novnc" ] && [ "\$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
293-
keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen \${NOVNC_PORT:-6080} --vnc localhost:\${VNC_PORT:-5901}"
358+
keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen ${NOVNC_PORT} --vnc localhost:${VNC_PORT}"
294359
log "noVNC started."
295360
else
296361
log "noVNC is already running or not installed."
@@ -303,61 +368,26 @@ log "** SCRIPT EXIT **"
303368
EOF
304369

305370
echo "${VNC_PASSWORD}" | vncpasswd -f > /usr/local/etc/vscode-dev-containers/vnc-passwd
306-
touch /root/.Xmodmap
307371
chmod +x /usr/local/share/desktop-init.sh /usr/local/bin/set-resolution
308372

309-
tee /root/.fluxbox/apps > /dev/null \
310-
<<EOF
311-
[transient] (role=GtkFileChooserDialog)
312-
[Dimensions] {70% 70%}
313-
[Position] (CENTER) {0 0}
314-
[end]
315-
EOF
373+
# Set up fluxbox config
374+
copy_fluxbox_config "/root"
375+
if [ "${USERNAME}" != "root" ]; then
376+
copy_fluxbox_config "/home/${USERNAME}"
377+
chown -R ${USERNAME} /home/${USERNAME}/.Xmodmap /home/${USERNAME}/.fluxbox
378+
fi
316379

317-
tee /root/.fluxbox/init > /dev/null \
318-
<<EOF
319-
session.configVersion: 13
320-
session.menuFile: ~/.fluxbox/menu
321-
session.keyFile: ~/.fluxbox/keys
322-
session.styleFile: /usr/share/fluxbox/styles/qnx-photon
323-
session.screen0.workspaces: 1
324-
session.screen0.workspacewarping: false
325-
session.screen0.toolbar.widthPercent: 100
326-
session.screen0.strftimeFormat: %a %l:%M %p
327-
session.screen0.toolbar.tools: RootMenu, clock, iconbar, systemtray
328-
session.screen0.workspaceNames: One,
329-
EOF
380+
cat << EOF
330381
331-
tee /root/.fluxbox/menu > /dev/null \
332-
<<EOF
333-
[begin] ( Application Menu )
334-
[exec] (File Manager) { nautilus ~ } <>
335-
[exec] (Text Editor) { mousepad } <>
336-
[exec] (Terminal) { tilix -w ~ -e $(readlink -f /proc/$$/exe) -il } <>
337-
[exec] (Web Browser) { x-www-browser --disable-dev-shm-usage } <>
338-
[submenu] (System) {}
339-
[exec] (Set Resolution) { tilix -t "Set Resolution" -e bash /usr/local/bin/set-resolution } <>
340-
[exec] (Edit Application Menu) { mousepad ~/.fluxbox/menu } <>
341-
[exec] (Passwords and Keys) { seahorse } <>
342-
[exec] (Top Processes) { tilix -t "Top" -e htop } <>
343-
[exec] (Disk Utilization) { tilix -t "Disk Utilization" -e ncdu / } <>
344-
[exec] (Editres) {editres} <>
345-
[exec] (Xfontsel) {xfontsel} <>
346-
[exec] (Xkill) {xkill} <>
347-
[exec] (Xrefresh) {xrefresh} <>
348-
[end]
349-
[config] (Configuration)
350-
[workspaces] (Workspaces)
351-
[end]
352-
EOF
353382
354-
# Set up non-root user (if one exists)
355-
if [ "${USERNAME}" != "root" ]; then
356-
touch /home/${USERNAME}/.Xmodmap
357-
cp -R /root/.fluxbox /home/${USERNAME}
358-
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.Xmodmap /home/${USERNAME}/.fluxbox
359-
chown ${USERNAME}:root /usr/local/share/desktop-init.sh /usr/local/bin/set-resolution /usr/local/etc/vscode-dev-containers/vnc-passwd
360-
fi
383+
You now have a working desktop! Connect to in one of the following ways:
384+
385+
- Forward port ${NOVNC_PORT} and use a web browser start the noVNC client (recommended)
386+
- Forward port ${VNC_PORT} using VS Code client and connect using a VNC Viewer
387+
388+
In both cases, use the password "${VNC_PASSWORD}" when connecting
361389
362-
echo "Done!"
390+
(*) Done!
391+
392+
EOF
363393

script-library/docs/desktop-lite.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@
1313
## Syntax
1414

1515
```text
16-
./desktop-lite-debian.sh [Non-root user] [VNC password] [Install noVNC flag]
16+
./desktop-lite-debian.sh [Non-root user] [Desktop password] [Install web client flag] [VNC port] [Web port]
1717
```
1818

1919
Or as a feature:
2020

2121
```json
2222
"features": {
23-
"desktop-lite": "latest"
23+
"desktop-lite": {
24+
"password": "vscode",
25+
"webPort": "6080",
26+
"vncPort": "5901"
27+
}
2428
}
2529
```
2630

2731
|Argument| Feature option |Default|Description|
2832
|--------|----------------|-------|-----------|
2933
|Non-root user| | `automatic`| Specifies a user in the container other than root that will be using the desktop. A value of `automatic` will cause the script to check for a user called `vscode`, then `node`, `codespace`, and finally a user with a UID of `1000` before falling back to `root`. |
30-
|VNC password| | `vscode`| Password for connecting to the desktop.|
31-
|Install noVNC flag| | `true`| Flag (`true`/`false`) that specifies whether to enable web access to the desktop using [noVNC](https://novnc.com/info.html).|
34+
|Desktop password| `password` | `vscode`| Password for connecting to the desktop.|
35+
|Install web client flag| | `true`| Flag (`true`/`false`) that specifies whether to enable web access to the desktop using [noVNC](https://novnc.com/info.html).|
36+
|VNC Port| `vncPort` | `5901`| Port to host a VNC server that you can use to connect to the desktop using a VNC Viewer.|
37+
|Web port | `webPort` | `6080`| Port to host the [noVNC](https://novnc.com/info.html) web client that you can use to connect to the desktop from a browser.|
3238

3339
## Usage
3440

@@ -38,7 +44,11 @@ You can use this script for your primary dev container by adding it to the `feat
3844

3945
```json
4046
"features": {
41-
"desktop-lite": "latest"
47+
"desktop-lite": {
48+
"password": "vscode",
49+
"webPort": "6080",
50+
"vncPort": "5901"
51+
}
4252
}
4353
```
4454

@@ -71,7 +81,7 @@ If you have already built your development container, run the **Rebuild Containe
7181
3. And the following to `.devcontainer/devcontainer.json` if you are referencing an image or Dockerfile:
7282

7383
```json
74-
"runArgs": ["--init", "--security-opt", "seccomp=unconfined"],
84+
"runArgs": ["--init"],
7585
"forwardPorts": [6080, 5901],
7686
"overrideCommand": false
7787
```
@@ -81,8 +91,6 @@ If you have already built your development container, run the **Rebuild Containe
8191
```yaml
8292
your-service-here:
8393
init: true
84-
security_opt:
85-
- seccomp:unconfined
8694
```
8795

8896
The `runArgs` / Docker Compose setting allows the container to take advantage of an [init process](https://docs.docker.com/engine/reference/run/#specify-an-init-process) to handle application and process signals in a desktop environment.

0 commit comments

Comments
 (0)