Skip to content

Commit f92f7ba

Browse files
[common-utils]: Bug fix: Install zsh on an image previously built with "installZsh:false" (#649)
* [common-utils]: Bug fix: Installs zsh on an image built with installZsh:false * version bump * nit: fix merge conflicts * Version bump
1 parent 97eea5d commit f92f7ba

File tree

2 files changed

+147
-134
lines changed

2 files changed

+147
-134
lines changed

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "common-utils",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"name": "Common Utilities",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
66
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",

src/common-utils/main.sh

Lines changed: 146 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ install_debian_packages() {
2828
# Ensure apt is in non-interactive to avoid prompts
2929
export DEBIAN_FRONTEND=noninteractive
3030

31-
local package_list="apt-utils \
31+
local package_list=""
32+
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
33+
package_list="${package_list} \
34+
apt-utils \
3235
openssh-client \
3336
gnupg2 \
3437
dirmngr \
@@ -70,6 +73,34 @@ install_debian_packages() {
7073
manpages-dev \
7174
init-system-helpers"
7275

76+
# Include libssl1.1 if available
77+
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
78+
package_list="${package_list} libssl1.1"
79+
fi
80+
81+
# Include libssl3 if available
82+
if [[ ! -z $(apt-cache --names-only search ^libssl3$) ]]; then
83+
package_list="${package_list} libssl3"
84+
fi
85+
86+
# Include appropriate version of libssl1.0.x if available
87+
local libssl_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
88+
if [ "$(echo "$libssl_package" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
89+
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then
90+
# Debian 9
91+
package_list="${package_list} libssl1.0.2"
92+
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then
93+
# Ubuntu 18.04
94+
package_list="${package_list} libssl1.0.0"
95+
fi
96+
fi
97+
98+
# Include git if not already installed (may be more recent than distro version)
99+
if ! type git > /dev/null 2>&1; then
100+
package_list="${package_list} git"
101+
fi
102+
fi
103+
73104
# Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian
74105
if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then
75106
# Bring in variables from /etc/os-release like VERSION_CODENAME
@@ -88,33 +119,6 @@ install_debian_packages() {
88119
package_list="${package_list} manpages-posix manpages-posix-dev"
89120
fi
90121

91-
# Include libssl1.1 if available
92-
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
93-
package_list="${package_list} libssl1.1"
94-
fi
95-
96-
# Include libssl3 if available
97-
if [[ ! -z $(apt-cache --names-only search ^libssl3$) ]]; then
98-
package_list="${package_list} libssl3"
99-
fi
100-
101-
# Include appropriate version of libssl1.0.x if available
102-
local libssl_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
103-
if [ "$(echo "$libssl_package" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
104-
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then
105-
# Debian 9
106-
package_list="${package_list} libssl1.0.2"
107-
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then
108-
# Ubuntu 18.04
109-
package_list="${package_list} libssl1.0.0"
110-
fi
111-
fi
112-
113-
# Include git if not already installed (may be more recent than distro version)
114-
if ! type git > /dev/null 2>&1; then
115-
package_list="${package_list} git"
116-
fi
117-
118122
# Install the list of packages
119123
echo "Packages to verify are installed: ${package_list}"
120124
rm -rf /var/lib/apt/lists/*
@@ -139,80 +143,85 @@ install_debian_packages() {
139143
LOCALE_ALREADY_SET="true"
140144
fi
141145

146+
PACKAGES_ALREADY_INSTALLED="true"
147+
142148
# Clean up
143149
apt-get -y clean
144150
rm -rf /var/lib/apt/lists/*
145151
}
146152

147153
# RedHat / RockyLinux / CentOS / Fedora packages
148154
install_redhat_packages() {
149-
local package_list="\
150-
gawk \
151-
openssh-clients \
152-
gnupg2 \
153-
iproute \
154-
procps \
155-
lsof \
156-
net-tools \
157-
psmisc \
158-
wget \
159-
ca-certificates \
160-
rsync \
161-
unzip \
162-
zip \
163-
nano \
164-
vim-minimal \
165-
less \
166-
jq \
167-
openssl-libs \
168-
krb5-libs \
169-
libicu \
170-
zlib \
171-
sudo \
172-
sed \
173-
grep \
174-
which \
175-
man-db \
176-
strace"
177-
155+
local package_list=""
156+
local remove_epel="false"
178157
local install_cmd=dnf
179158
if ! type dnf > /dev/null 2>&1; then
180159
install_cmd=yum
181160
fi
182161

162+
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
163+
package_list="${package_list} \
164+
gawk \
165+
openssh-clients \
166+
gnupg2 \
167+
iproute \
168+
procps \
169+
lsof \
170+
net-tools \
171+
psmisc \
172+
wget \
173+
ca-certificates \
174+
rsync \
175+
unzip \
176+
zip \
177+
nano \
178+
vim-minimal \
179+
less \
180+
jq \
181+
openssl-libs \
182+
krb5-libs \
183+
libicu \
184+
zlib \
185+
sudo \
186+
sed \
187+
grep \
188+
which \
189+
man-db \
190+
strace"
191+
183192
# rockylinux:9 installs 'curl-minimal' which clashes with 'curl'
184193
# Install 'curl' for every OS except this rockylinux:9
185194
if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then
186195
package_list="${package_list} curl"
187196
fi
188197

189-
# Install OpenSSL 1.0 compat if needed
190-
if ${install_cmd} -q list compat-openssl10 >/dev/null 2>&1; then
191-
package_list="${package_list} compat-openssl10"
192-
fi
198+
# Install OpenSSL 1.0 compat if needed
199+
if ${install_cmd} -q list compat-openssl10 >/dev/null 2>&1; then
200+
package_list="${package_list} compat-openssl10"
201+
fi
193202

194-
# Install lsb_release if available
195-
if ${install_cmd} -q list redhat-lsb-core >/dev/null 2>&1; then
196-
package_list="${package_list} redhat-lsb-core"
197-
fi
203+
# Install lsb_release if available
204+
if ${install_cmd} -q list redhat-lsb-core >/dev/null 2>&1; then
205+
package_list="${package_list} redhat-lsb-core"
206+
fi
198207

199-
# Install git if not already installed (may be more recent than distro version)
200-
if ! type git > /dev/null 2>&1; then
201-
package_list="${package_list} git"
208+
# Install git if not already installed (may be more recent than distro version)
209+
if ! type git > /dev/null 2>&1; then
210+
package_list="${package_list} git"
211+
fi
212+
213+
# Install EPEL repository if needed (required to install 'jq' for CentOS)
214+
if ! ${install_cmd} -q list jq >/dev/null 2>&1; then
215+
${install_cmd} -y install epel-release
216+
remove_epel="true"
217+
fi
202218
fi
203219

204220
# Install zsh if needed
205221
if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then
206222
package_list="${package_list} zsh"
207223
fi
208224

209-
# Install EPEL repository if needed (required to install 'jq' for CentOS)
210-
local remove_epel="false"
211-
if ! ${install_cmd} -q list jq >/dev/null 2>&1; then
212-
${install_cmd} -y install epel-release
213-
remove_epel="true"
214-
fi
215-
216225
${install_cmd} -y install ${package_list}
217226

218227
# Get to latest versions of all packages
@@ -223,63 +232,70 @@ install_redhat_packages() {
223232
if [[ "${remove_epel}" = "true" ]]; then
224233
${install_cmd} -y remove epel-release
225234
fi
235+
236+
PACKAGES_ALREADY_INSTALLED="true"
226237
}
227238

228239
# Alpine Linux packages
229240
install_alpine_packages() {
230241
apk update
231-
apk add --no-cache \
232-
openssh-client \
233-
gnupg \
234-
procps \
235-
lsof \
236-
htop \
237-
net-tools \
238-
psmisc \
239-
curl \
240-
wget \
241-
rsync \
242-
ca-certificates \
243-
unzip \
244-
zip \
245-
nano \
246-
vim \
247-
less \
248-
jq \
249-
libgcc \
250-
libstdc++ \
251-
krb5-libs \
252-
libintl \
253-
libssl1.1 \
254-
lttng-ust \
255-
tzdata \
256-
userspace-rcu \
257-
zlib \
258-
sudo \
259-
coreutils \
260-
sed \
261-
grep \
262-
which \
263-
ncdu \
264-
shadow \
265-
strace
266242

267-
# Install man pages - package name varies between 3.12 and earlier versions
268-
if apk info man > /dev/null 2>&1; then
269-
apk add --no-cache man man-pages
270-
else
271-
apk add --no-cache mandoc man-pages
272-
fi
243+
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
244+
apk add --no-cache \
245+
openssh-client \
246+
gnupg \
247+
procps \
248+
lsof \
249+
htop \
250+
net-tools \
251+
psmisc \
252+
curl \
253+
wget \
254+
rsync \
255+
ca-certificates \
256+
unzip \
257+
zip \
258+
nano \
259+
vim \
260+
less \
261+
jq \
262+
libgcc \
263+
libstdc++ \
264+
krb5-libs \
265+
libintl \
266+
libssl1.1 \
267+
lttng-ust \
268+
tzdata \
269+
userspace-rcu \
270+
zlib \
271+
sudo \
272+
coreutils \
273+
sed \
274+
grep \
275+
which \
276+
ncdu \
277+
shadow \
278+
strace
279+
280+
# Install man pages - package name varies between 3.12 and earlier versions
281+
if apk info man > /dev/null 2>&1; then
282+
apk add --no-cache man man-pages
283+
else
284+
apk add --no-cache mandoc man-pages
285+
fi
273286

274-
# Install git if not already installed (may be more recent than distro version)
275-
if ! type git > /dev/null 2>&1; then
276-
apk add --no-cache git
287+
# Install git if not already installed (may be more recent than distro version)
288+
if ! type git > /dev/null 2>&1; then
289+
apk add --no-cache git
290+
fi
277291
fi
278292

279293
# Install zsh if needed
280294
if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then
281295
apk add --no-cache zsh
282296
fi
297+
298+
PACKAGES_ALREADY_INSTALLED="true"
283299
}
284300

285301
# ******************
@@ -318,20 +334,17 @@ else
318334
fi
319335

320336
# Install packages for appropriate OS
321-
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
322-
case "${ADJUSTED_ID}" in
323-
"debian")
324-
install_debian_packages
325-
;;
326-
"rhel")
327-
install_redhat_packages
328-
;;
329-
"alpine")
330-
install_alpine_packages
331-
;;
332-
esac
333-
PACKAGES_ALREADY_INSTALLED="true"
334-
fi
337+
case "${ADJUSTED_ID}" in
338+
"debian")
339+
install_debian_packages
340+
;;
341+
"rhel")
342+
install_redhat_packages
343+
;;
344+
"alpine")
345+
install_alpine_packages
346+
;;
347+
esac
335348

336349
# If in automatic mode, determine if a user already exists, if not use vscode
337350
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then

0 commit comments

Comments
 (0)