Skip to content

Commit ea9827d

Browse files
authored
chore(shared-pnpm-store): apply bash best practices across scripts (#4)
1 parent d2fa472 commit ea9827d

10 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/shared-pnpm-store/install.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

5-
USERNAME=${USERNAME:-${_REMOTE_USER}}
5+
USERNAME=${USERNAME:-${_REMOTE_USER:-}}
66
FEATURE_ID="shared-pnpm-store"
77
STORE_DIR="/mnt/shared-pnpm-store"
88
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/${FEATURE_ID}/scripts"
99

1010
echo "Ensuring pnpm store directory ${STORE_DIR} exists..."
1111
mkdir -p "${STORE_DIR}"
1212

13-
if [ -n "${USERNAME}" ] && [ "${USERNAME}" != "root" ]; then
13+
if [[ -n "${USERNAME}" && "${USERNAME}" != "root" ]]; then
1414
echo "Setting owner of ${STORE_DIR} to ${USERNAME}..."
1515
chown -R "${USERNAME}:${USERNAME}" "${STORE_DIR}"
1616
else
1717
echo "No non-root user; leaving ${STORE_DIR} owned by root."
1818
fi
1919

2020
# Install lifecycle script (re-asserts ownership at container create time)
21-
if [ -f oncreate.sh ]; then
21+
if [[ -f oncreate.sh ]]; then
2222
echo "Installing oncreate.sh to ${LIFECYCLE_SCRIPTS_DIR}..."
2323
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
2424
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh"

src/shared-pnpm-store/oncreate.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

55
STORE_DIR="/mnt/shared-pnpm-store"
66

@@ -9,7 +9,7 @@ STORE_DIR="/mnt/shared-pnpm-store"
99
# ownership for the current non-root user on every container create so pnpm can
1010
# always write to the store, even if the volume was first created by root or a
1111
# different user.
12-
if [ "$(id -u)" != "0" ]; then
12+
if [[ "$(id -u)" != "0" ]]; then
1313
USERNAME="$(id -un)"
1414
echo "Setting owner of ${STORE_DIR} to ${USERNAME}..."
1515
sudo chown -R "${USERNAME}:${USERNAME}" "${STORE_DIR}"

test/shared-pnpm-store/_default.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# Default assertions, reused by scenarios that have pnpm installed.
66
# Not run directly as a scenario.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# fish feature installed alongside
66
./_default.sh

test/shared-pnpm-store/node_v2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# node feature v2 installs latest pnpm by default; this feature touches no
66
# pnpm global state, so the default assertions are sufficient.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# pnpm installed via the node feature
66
./_default.sh

test/shared-pnpm-store/root_user.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
source dev-container-features-test-lib
66

test/shared-pnpm-store/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# Optional: Import test library
66
source dev-container-features-test-lib
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# pnpm already present in the base image
66
./_default.sh
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -euo pipefail
44

55
# zsh configured as default shell
66
./_default.sh

0 commit comments

Comments
 (0)