From 224155d35c8fff28ba530bdd82181aca1d3496b9 Mon Sep 17 00:00:00 2001 From: gauravsaini04 <147703805+gauravsaini04@users.noreply.github.com> Date: Tue, 6 Feb 2024 23:52:41 +0000 Subject: [PATCH 1/5] [common-utils] - Bookworm - enabled nonFreePackages option for installing manpages-posix, manpages-posix-dev packages (non-free) --- src/common-utils/main.sh | 28 ++++++++++++++++------------ test/common-utils/bookworm.sh | 14 ++++++++++++++ test/common-utils/scenarios.json | 9 +++++++++ 3 files changed, 39 insertions(+), 12 deletions(-) create mode 100755 test/common-utils/bookworm.sh diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 0eec1ecb9..028338fa5 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -104,18 +104,22 @@ install_debian_packages() { # 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 + if [ ! -e "/etc/apt/sources.list" ]; then + sed -i -E "s/Components: main/components: main contrib non-free/" /etc/apt/sources.list.d/debian.sources + else + # 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 + fi; echo "Running apt-get update..." package_list="${package_list} manpages-posix manpages-posix-dev" fi diff --git a/test/common-utils/bookworm.sh b/test/common-utils/bookworm.sh new file mode 100755 index 000000000..159878603 --- /dev/null +++ b/test/common-utils/bookworm.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +. /etc/os-release +check "non-root user" test "$(whoami)" = "devcontainer" +check "distro" test "${VERSION_CODENAME}" = "bookworm" + +# Report result +reportResults \ No newline at end of file diff --git a/test/common-utils/scenarios.json b/test/common-utils/scenarios.json index 2e357bc2b..744f16dc1 100644 --- a/test/common-utils/scenarios.json +++ b/test/common-utils/scenarios.json @@ -34,6 +34,15 @@ "common-utils": {} } }, + "bookworm": { + "image": "debian:bookworm", + "remoteUser": "devcontainer", + "features": { + "common-utils": { + "nonFreePackages": "true" + } + } + }, "centos-7": { "image": "centos:7", "remoteUser": "devcontainer", From 3e9da3c7b9b4fb6f9d7d9de1e4270e2afc5b799a Mon Sep 17 00:00:00 2001 From: gauravsaini04 <147703805+gauravsaini04@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:54:57 +0000 Subject: [PATCH 2/5] change to correct the regular expression replacement with sed cmd --- src/common-utils/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 028338fa5..d531a8a9b 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -105,7 +105,7 @@ install_debian_packages() { # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then if [ ! -e "/etc/apt/sources.list" ]; then - sed -i -E "s/Components: main/components: main contrib non-free/" /etc/apt/sources.list.d/debian.sources + sed -i -E "s/Components: main/Components: main contrib non-free/g" /etc/apt/sources.list.d/debian.sources else # 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 From 8eeb65108ae1ea075360d2eea20f3d095c3600fb Mon Sep 17 00:00:00 2001 From: gauravsaini04 <147703805+gauravsaini04@users.noreply.github.com> Date: Thu, 8 Feb 2024 02:11:46 +0000 Subject: [PATCH 3/5] changes according to comments by Samruddhi --- src/common-utils/main.sh | 2 +- test/common-utils/bookworm.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index d531a8a9b..f302d440f 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -105,7 +105,7 @@ install_debian_packages() { # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then if [ ! -e "/etc/apt/sources.list" ]; then - sed -i -E "s/Components: main/Components: main contrib non-free/g" /etc/apt/sources.list.d/debian.sources + sed -i '/Suites: bookworm bookworm-updates/{N;s/Components: main/Components: main non-free non-free-firmware/}' /etc/apt/sources.list.d/debian.sources else # 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 diff --git a/test/common-utils/bookworm.sh b/test/common-utils/bookworm.sh index 159878603..db8628713 100755 --- a/test/common-utils/bookworm.sh +++ b/test/common-utils/bookworm.sh @@ -5,6 +5,37 @@ set -e # Optional: Import test library source dev-container-features-test-lib +FAILED=() +echoStderr() +{ + echo "$@" 1>&2 +} + +checkOSPackages() { + LABEL=$1 + shift + echo -e "\n🧪 Testing $LABEL" + if dpkg-query --show -f='${Package}: ${Version}\n' "$@"; then + echo "✅ Passed!" + return 0 + else + echoStderr "❌ $LABEL check failed." + FAILED+=("$LABEL") + return 1 + fi +} + +checkCommon() +{ + PACKAGE_LIST="manpages-posix \ + manpages-posix-dev" + + checkOSPackages "Installation of manpages-posix and manpages-posix-dev (non-free)" ${PACKAGE_LIST} +} + +# Check for manpages-posix, manpages-posix-dev non-free packages +checkCommon + # Definition specific tests . /etc/os-release check "non-root user" test "$(whoami)" = "devcontainer" From e5054dba652b09902ec43aa45bf05386a28a341c Mon Sep 17 00:00:00 2001 From: gauravsaini04 <147703805+gauravsaini04@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:05:40 +0000 Subject: [PATCH 4/5] Changes acc. to comments as on 08/02 --- src/common-utils/main.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index f302d440f..8b74830cc 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -104,8 +104,8 @@ install_debian_packages() { # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then - if [ ! -e "/etc/apt/sources.list" ]; then - sed -i '/Suites: bookworm bookworm-updates/{N;s/Components: main/Components: main non-free non-free-firmware/}' /etc/apt/sources.list.d/debian.sources + if [[ ! -e "/etc/apt/sources.list" ]] && [[ -e "/etc/apt/sources.list.d/debian.sources" ]]; then + sed -i '/^URIs: http:\/\/deb.debian.org\/debian$/ { N; N; s/Components: main/Components: main non-free non-free-firmware/ }' /etc/apt/sources.list.d/debian.sources else # 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 From 61553e73e6112926562c4debef091b1111f6053b Mon Sep 17 00:00:00 2001 From: gauravsaini04 <147703805+gauravsaini04@users.noreply.github.com> Date: Thu, 8 Feb 2024 22:02:04 +0000 Subject: [PATCH 5/5] Updated patch version based on comments --- src/common-utils/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index 44f9b32b4..a058864af 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "common-utils", - "version": "2.4.1", + "version": "2.4.2", "name": "Common Utilities", "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.",