From e7be8e2b4b403f780b1fd69a5a2a2cbbff978dcf Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Mon, 7 Sep 2026 01:25:38 +0000 Subject: [PATCH] fix(devcontainer): generate common locales and greet each new terminal --- .devcontainer/post-create.sh | 15 +++++++++++++++ .devcontainer/shell-init.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 .devcontainer/shell-init.sh diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 15c1750..6b77b98 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -62,6 +62,21 @@ php -r "exit(extension_loaded('gd') ? 0 : 1);" || { echo "gd extension failed to echo "==> Trusting this repo's mise.toml" mise trust +echo "==> Generating the English locales hosts commonly send over SSH" +# OpenSSH forwards the host's LANG and LC_*, and bash warns on every start +# when that locale is not generated here. This covers the usual English +# ones before the shell starts; shell-init.sh falls back for anything else. +sudo apt-get install -y locales > /dev/null +sudo sed -i -E 's/^# (en_(AU|CA|GB|IE|NZ|US)\.UTF-8 UTF-8)/\1/' /etc/locale.gen +sudo locale-gen > /dev/null + +echo "==> Installing the shell locale fallback and welcome" +# Sourced from ~/.bashrc rather than run once here, so every new terminal +# gets the locale fix and the summary, not only the creation log. +if ! grep -qF '.devcontainer/shell-init.sh' ~/.bashrc; then + printf '\n# Dev container shell setup: locale fallback and welcome.\nexport WORKSPACE_ROOT=%q\n[ -f "$WORKSPACE_ROOT/.devcontainer/shell-init.sh" ] && . "$WORKSPACE_ROOT/.devcontainer/shell-init.sh"\n' "$PWD" >> ~/.bashrc +fi + echo "==> Running npm install (triggers the full setup pipeline)" # --loglevel=error: the root devDependencies are lint tooling that # requires Node 22 (CI runs them there); installing them under the diff --git a/.devcontainer/shell-init.sh b/.devcontainer/shell-init.sh new file mode 100755 index 0000000..deeebf1 --- /dev/null +++ b/.devcontainer/shell-init.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Sourced by ~/.bashrc inside the dev container. post-create.sh installs the +# line that sources it, so a fresh container gets both halves below. + +# The host's locale arrives over SSH: OpenSSH sends LANG and LC_* by default, +# and DevPod's shell inherits them. When the value names a locale this image +# has not generated, every command warns "setlocale: cannot change locale" +# and manpath gives up. Fall back to the image's UTF-8 locale instead. +if [ -n "${LANG:-}" ] && ! locale -a 2>/dev/null | grep -qix "$(printf '%s' "$LANG" | sed 's/UTF-8$/utf8/')"; then + export LANG=C.UTF-8 + unset LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME +fi + +# The rest is for a person at a prompt. +case $- in *i*) ;; *) return 0 2>/dev/null || exit 0 ;; esac + +backend="not started" +if [ -f "${WORKSPACE_ROOT:-$PWD}/.env" ]; then + backend="$(sed -n 's/^BASE_URL=//p' "${WORKSPACE_ROOT:-$PWD}/.env" | head -1)" + backend="${backend:-not started}" +fi + +cat <