Avoid unexpected shell expansion (#645) · devcontainers/features@9e75db9 · GitHub
Skip to content

Commit 9e75db9

Browse files
authored
Avoid unexpected shell expansion (#645)
* Avoid unexpected shell expansion * Add install Node with ZSH as default test * Fix LTS only work on >bionic * Bump Node feature version * Remove huge universal image on scenarios
1 parent f2594c5 commit 9e75db9

4 files changed

Lines changed: 37 additions & 23 deletions

File tree

‎src/node/devcontainer-feature.json‎

Lines changed: 2 additions & 2 deletions

‎src/node/install.sh‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
export NODE_VERSION="${VERSION:-"lts"}"
1111
export NVM_VERSION="${NVMVERSION:-"0.39.2"}"
12-
export NVM_DIR=${NVMINSTALLPATH:-"/usr/local/share/nvm"}
12+
export NVM_DIR="${NVMINSTALLPATH:-"/usr/local/share/nvm"}"
1313
INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}"
1414

1515
# Comma-separated list of node versions to be installed (with nvm)
@@ -118,10 +118,10 @@ set -e
118118
umask 0002
119119
# Do not update profile - we'll do this manually
120120
export PROFILE=/dev/null
121-
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
122-
source ${NVM_DIR}/nvm.sh
121+
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash
122+
source "${NVM_DIR}/nvm.sh"
123123
if [ "${NODE_VERSION}" != "" ]; then
124-
nvm alias default ${NODE_VERSION}
124+
nvm alias default "${NODE_VERSION}"
125125
fi
126126
EOF
127127
)"
@@ -149,9 +149,9 @@ usermod -a -G nvm ${USERNAME}
149149
umask 0002
150150
if [ ! -d "${NVM_DIR}" ]; then
151151
# Create nvm dir, and set sticky bit
152-
mkdir -p ${NVM_DIR}
153-
chown "${USERNAME}:nvm" ${NVM_DIR}
154-
chmod g+rws ${NVM_DIR}
152+
mkdir -p "${NVM_DIR}"
153+
chown "${USERNAME}:nvm" "${NVM_DIR}"
154+
chmod g+rws "${NVM_DIR}"
155155
su ${USERNAME} -c "${nvm_install_snippet}" 2>&1
156156
# Update rc files
157157
if [ "${UPDATE_RC}" = "true" ]; then
@@ -160,11 +160,11 @@ if [ ! -d "${NVM_DIR}" ]; then
160160
else
161161
echo "NVM already installed."
162162
if [ "${NODE_VERSION}" != "" ]; then
163-
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm install ${NODE_VERSION} && nvm alias default ${NODE_VERSION}"
163+
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm install '${NODE_VERSION}' && nvm alias default '${NODE_VERSION}'"
164164
fi
165165
fi
166166

167-
# Additional node versions to be installed but not be set as
167+
# Additional node versions to be installed but not be set as
168168
# default we can assume the nvm is the group owner of the nvm
169169
# directory and the sticky bit on directories so any installed
170170
# files will have will have the correct ownership (nvm)
@@ -173,12 +173,12 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
173173
IFS=","
174174
read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
175175
for ver in "${additional_versions[@]}"; do
176-
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm install ${ver}"
176+
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm install '${ver}'"
177177
done
178178

179179
# Ensure $NODE_VERSION is on the $PATH
180180
if [ "${NODE_VERSION}" != "" ]; then
181-
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm use default"
181+
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm use default"
182182
fi
183183
IFS=$OLDIFS
184184
fi
@@ -218,7 +218,7 @@ fi
218218

219219

220220
# Clean up
221-
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm clear-cache"
221+
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm clear-cache"
222222
rm -rf /var/lib/apt/lists/*
223223

224224
# Ensure privs are correct for installed node versions. Unfortunately the

‎test/node/scenarios.json‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717
}
1818
}
1919
},
20-
"version_none": {
21-
"image": "mcr.microsoft.com/devcontainers/base",
22-
"remoteUser": "vscode",
20+
"zsh_default": {
21+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
2322
"features": {
2423
"node": {
25-
"version": "none"
24+
"version": "lts"
25+
},
26+
"common-utils": {
27+
"configureZshAsDefaultShell": true
2628
}
2729
}
2830
},
29-
"install_node_on_universal_image": {
30-
"image": "mcr.microsoft.com/devcontainers/universal",
31-
"remoteUser": "codespace",
31+
"version_none": {
32+
"image": "mcr.microsoft.com/devcontainers/base",
33+
"remoteUser": "vscode",
3234
"features": {
3335
"node": {
34-
"version": "19.1.0"
36+
"version": "none"
3537
}
3638
}
3739
},
@@ -43,4 +45,4 @@
4345
}
4446
}
4547
}
46-
}
48+
}

‎test/node/zsh_default.sh‎

Lines changed: 12 additions & 0 deletions

0 commit comments

Comments
 (0)