From 6f1ef34252de1f3bca78934c57b1346d9811555a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Tue, 23 Jun 2026 12:03:50 +0200 Subject: [PATCH] chore(shared-pnpm-store): apply bash best practices across scripts --- src/shared-pnpm-store/install.sh | 10 +++++----- src/shared-pnpm-store/oncreate.sh | 6 +++--- test/shared-pnpm-store/_default.sh | 2 +- test/shared-pnpm-store/fish_shell.sh | 2 +- test/shared-pnpm-store/node_v2.sh | 2 +- test/shared-pnpm-store/pnpm_from_feature.sh | 2 +- test/shared-pnpm-store/root_user.sh | 2 +- test/shared-pnpm-store/test.sh | 2 +- test/shared-pnpm-store/with_node.sh | 2 +- test/shared-pnpm-store/zsh_shell.sh | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/shared-pnpm-store/install.sh b/src/shared-pnpm-store/install.sh index ac4fc54..46aefc4 100755 --- a/src/shared-pnpm-store/install.sh +++ b/src/shared-pnpm-store/install.sh @@ -1,8 +1,8 @@ -#!/bin/sh +#!/usr/bin/env bash -set -e +set -euo pipefail -USERNAME=${USERNAME:-${_REMOTE_USER}} +USERNAME=${USERNAME:-${_REMOTE_USER:-}} FEATURE_ID="shared-pnpm-store" STORE_DIR="/mnt/shared-pnpm-store" LIFECYCLE_SCRIPTS_DIR="/usr/local/share/${FEATURE_ID}/scripts" @@ -10,7 +10,7 @@ LIFECYCLE_SCRIPTS_DIR="/usr/local/share/${FEATURE_ID}/scripts" echo "Ensuring pnpm store directory ${STORE_DIR} exists..." mkdir -p "${STORE_DIR}" -if [ -n "${USERNAME}" ] && [ "${USERNAME}" != "root" ]; then +if [[ -n "${USERNAME}" && "${USERNAME}" != "root" ]]; then echo "Setting owner of ${STORE_DIR} to ${USERNAME}..." chown -R "${USERNAME}:${USERNAME}" "${STORE_DIR}" else @@ -18,7 +18,7 @@ else fi # Install lifecycle script (re-asserts ownership at container create time) -if [ -f oncreate.sh ]; then +if [[ -f oncreate.sh ]]; then echo "Installing oncreate.sh to ${LIFECYCLE_SCRIPTS_DIR}..." mkdir -p "${LIFECYCLE_SCRIPTS_DIR}" cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" diff --git a/src/shared-pnpm-store/oncreate.sh b/src/shared-pnpm-store/oncreate.sh index 6cf3427..cbf830a 100755 --- a/src/shared-pnpm-store/oncreate.sh +++ b/src/shared-pnpm-store/oncreate.sh @@ -1,6 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash -set -e +set -euo pipefail STORE_DIR="/mnt/shared-pnpm-store" @@ -9,7 +9,7 @@ STORE_DIR="/mnt/shared-pnpm-store" # ownership for the current non-root user on every container create so pnpm can # always write to the store, even if the volume was first created by root or a # different user. -if [ "$(id -u)" != "0" ]; then +if [[ "$(id -u)" != "0" ]]; then USERNAME="$(id -un)" echo "Setting owner of ${STORE_DIR} to ${USERNAME}..." sudo chown -R "${USERNAME}:${USERNAME}" "${STORE_DIR}" diff --git a/test/shared-pnpm-store/_default.sh b/test/shared-pnpm-store/_default.sh index 180fcfd..285a99f 100644 --- a/test/shared-pnpm-store/_default.sh +++ b/test/shared-pnpm-store/_default.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # Default assertions, reused by scenarios that have pnpm installed. # Not run directly as a scenario. diff --git a/test/shared-pnpm-store/fish_shell.sh b/test/shared-pnpm-store/fish_shell.sh index b6fb97a..20d889d 100644 --- a/test/shared-pnpm-store/fish_shell.sh +++ b/test/shared-pnpm-store/fish_shell.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # fish feature installed alongside ./_default.sh diff --git a/test/shared-pnpm-store/node_v2.sh b/test/shared-pnpm-store/node_v2.sh index 79b7c40..5ad497f 100644 --- a/test/shared-pnpm-store/node_v2.sh +++ b/test/shared-pnpm-store/node_v2.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # node feature v2 installs latest pnpm by default; this feature touches no # pnpm global state, so the default assertions are sufficient. diff --git a/test/shared-pnpm-store/pnpm_from_feature.sh b/test/shared-pnpm-store/pnpm_from_feature.sh index c9f8a7a..6616734 100644 --- a/test/shared-pnpm-store/pnpm_from_feature.sh +++ b/test/shared-pnpm-store/pnpm_from_feature.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # pnpm installed via the node feature ./_default.sh diff --git a/test/shared-pnpm-store/root_user.sh b/test/shared-pnpm-store/root_user.sh index a454b75..2ca46ca 100644 --- a/test/shared-pnpm-store/root_user.sh +++ b/test/shared-pnpm-store/root_user.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail source dev-container-features-test-lib diff --git a/test/shared-pnpm-store/test.sh b/test/shared-pnpm-store/test.sh index ac4c408..a1bbef2 100644 --- a/test/shared-pnpm-store/test.sh +++ b/test/shared-pnpm-store/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # Optional: Import test library source dev-container-features-test-lib diff --git a/test/shared-pnpm-store/with_node.sh b/test/shared-pnpm-store/with_node.sh index 64d0720..52584ec 100644 --- a/test/shared-pnpm-store/with_node.sh +++ b/test/shared-pnpm-store/with_node.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # pnpm already present in the base image ./_default.sh diff --git a/test/shared-pnpm-store/zsh_shell.sh b/test/shared-pnpm-store/zsh_shell.sh index 55509e5..21bf165 100644 --- a/test/shared-pnpm-store/zsh_shell.sh +++ b/test/shared-pnpm-store/zsh_shell.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -euo pipefail # zsh configured as default shell ./_default.sh