Unverified Commit f92f7ba7 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

[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
parent 97eea5de
{ {
"id": "common-utils", "id": "common-utils",
"version": "2.1.2", "version": "2.1.3",
"name": "Common Utilities", "name": "Common Utilities",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.", "description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
......
...@@ -28,7 +28,10 @@ install_debian_packages() { ...@@ -28,7 +28,10 @@ install_debian_packages() {
# Ensure apt is in non-interactive to avoid prompts # Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
local package_list="apt-utils \ local package_list=""
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
package_list="${package_list} \
apt-utils \
openssh-client \ openssh-client \
gnupg2 \ gnupg2 \
dirmngr \ dirmngr \
...@@ -70,24 +73,6 @@ install_debian_packages() { ...@@ -70,24 +73,6 @@ install_debian_packages() {
manpages-dev \ manpages-dev \
init-system-helpers" init-system-helpers"
# Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian
if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then
# Bring in variables from /etc/os-release like VERSION_CODENAME
sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list
sed -i -E "s/deb-src http:\/\/(deb|httredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list
sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list
sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list
# Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html
sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list
echo "Running apt-get update..."
package_list="${package_list} manpages-posix manpages-posix-dev"
fi
# Include libssl1.1 if available # Include libssl1.1 if available
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
package_list="${package_list} libssl1.1" package_list="${package_list} libssl1.1"
...@@ -114,6 +99,25 @@ install_debian_packages() { ...@@ -114,6 +99,25 @@ install_debian_packages() {
if ! type git > /dev/null 2>&1; then if ! type git > /dev/null 2>&1; then
package_list="${package_list} git" package_list="${package_list} git"
fi fi
fi
# Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian
if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then
# Bring in variables from /etc/os-release like VERSION_CODENAME
sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list
sed -i -E "s/deb-src http:\/\/(deb|httredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list
sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list
sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list
# Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html
sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list
echo "Running apt-get update..."
package_list="${package_list} manpages-posix manpages-posix-dev"
fi
# Install the list of packages # Install the list of packages
echo "Packages to verify are installed: ${package_list}" echo "Packages to verify are installed: ${package_list}"
...@@ -139,6 +143,8 @@ install_debian_packages() { ...@@ -139,6 +143,8 @@ install_debian_packages() {
LOCALE_ALREADY_SET="true" LOCALE_ALREADY_SET="true"
fi fi
PACKAGES_ALREADY_INSTALLED="true"
# Clean up # Clean up
apt-get -y clean apt-get -y clean
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
...@@ -146,7 +152,15 @@ install_debian_packages() { ...@@ -146,7 +152,15 @@ install_debian_packages() {
# RedHat / RockyLinux / CentOS / Fedora packages # RedHat / RockyLinux / CentOS / Fedora packages
install_redhat_packages() { install_redhat_packages() {
local package_list="\ local package_list=""
local remove_epel="false"
local install_cmd=dnf
if ! type dnf > /dev/null 2>&1; then
install_cmd=yum
fi
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
package_list="${package_list} \
gawk \ gawk \
openssh-clients \ openssh-clients \
gnupg2 \ gnupg2 \
...@@ -175,11 +189,6 @@ install_redhat_packages() { ...@@ -175,11 +189,6 @@ install_redhat_packages() {
man-db \ man-db \
strace" strace"
local install_cmd=dnf
if ! type dnf > /dev/null 2>&1; then
install_cmd=yum
fi
# rockylinux:9 installs 'curl-minimal' which clashes with 'curl' # rockylinux:9 installs 'curl-minimal' which clashes with 'curl'
# Install 'curl' for every OS except this rockylinux:9 # Install 'curl' for every OS except this rockylinux:9
if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then
...@@ -201,17 +210,17 @@ install_redhat_packages() { ...@@ -201,17 +210,17 @@ install_redhat_packages() {
package_list="${package_list} git" package_list="${package_list} git"
fi fi
# Install zsh if needed
if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then
package_list="${package_list} zsh"
fi
# Install EPEL repository if needed (required to install 'jq' for CentOS) # Install EPEL repository if needed (required to install 'jq' for CentOS)
local remove_epel="false"
if ! ${install_cmd} -q list jq >/dev/null 2>&1; then if ! ${install_cmd} -q list jq >/dev/null 2>&1; then
${install_cmd} -y install epel-release ${install_cmd} -y install epel-release
remove_epel="true" remove_epel="true"
fi fi
fi
# Install zsh if needed
if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then
package_list="${package_list} zsh"
fi
${install_cmd} -y install ${package_list} ${install_cmd} -y install ${package_list}
...@@ -223,11 +232,15 @@ install_redhat_packages() { ...@@ -223,11 +232,15 @@ install_redhat_packages() {
if [[ "${remove_epel}" = "true" ]]; then if [[ "${remove_epel}" = "true" ]]; then
${install_cmd} -y remove epel-release ${install_cmd} -y remove epel-release
fi fi
PACKAGES_ALREADY_INSTALLED="true"
} }
# Alpine Linux packages # Alpine Linux packages
install_alpine_packages() { install_alpine_packages() {
apk update apk update
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
apk add --no-cache \ apk add --no-cache \
openssh-client \ openssh-client \
gnupg \ gnupg \
...@@ -275,11 +288,14 @@ install_alpine_packages() { ...@@ -275,11 +288,14 @@ install_alpine_packages() {
if ! type git > /dev/null 2>&1; then if ! type git > /dev/null 2>&1; then
apk add --no-cache git apk add --no-cache git
fi fi
fi
# Install zsh if needed # Install zsh if needed
if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then
apk add --no-cache zsh apk add --no-cache zsh
fi fi
PACKAGES_ALREADY_INSTALLED="true"
} }
# ****************** # ******************
...@@ -318,8 +334,7 @@ else ...@@ -318,8 +334,7 @@ else
fi fi
# Install packages for appropriate OS # Install packages for appropriate OS
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then case "${ADJUSTED_ID}" in
case "${ADJUSTED_ID}" in
"debian") "debian")
install_debian_packages install_debian_packages
;; ;;
...@@ -329,9 +344,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then ...@@ -329,9 +344,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
"alpine") "alpine")
install_alpine_packages install_alpine_packages
;; ;;
esac esac
PACKAGES_ALREADY_INSTALLED="true"
fi
# If in automatic mode, determine if a user already exists, if not use vscode # If in automatic mode, determine if a user already exists, if not use vscode
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment