fix(bash_header): PKG_INSTALL string → function + export DEBIAN_FRONTEND

The previous definition assigned a multi-word string to PKG_INSTALL:
  PKG_INSTALL="DEBIAN_FRONTEND=noninteractive apt-get install -y"
Downstream generators expand it as '$PKG_INSTALL pkg…', which bash
parses as 'DEBIAN_FRONTEND=noninteractive apt-get install -y pkg…'
— the leading assignment is treated as a command name, producing
'DEBIAN_FRONTEND=noninteractive: command not found' (e.g. docker.sh
line 40). The DEBIAN_FRONTEND variable was also never set, so apt
could fall into interactive mode for tzdata / debconf prompts.

Fix: turn PKG_INSTALL into a shell function and export
DEBIAN_FRONTEND separately. All ~50 call sites keep the existing
$PKG_INSTALL pkg… syntax unchanged.

Verified: bash -n OK; mock Ubuntu 22.04 run exits 0 with no
'command not found'; mock apt-get receives the correct args.
All 44 generators still render successfully.
This commit is contained in:
Your Name
2026-08-07 13:14:14 +08:00
parent 0b2ab34ac2
commit bee37565e1
+18 -5
View File
@@ -137,14 +137,27 @@ die() {{ echo "${{LOG_PREFIX}} ERROR: $*" >&2 ; exit 1 ; }}
DISTRO_ID="${{ID:-unknown}}" DISTRO_ID="${{ID:-unknown}}"
DISTRO_LIKE="${{ID_LIKE:-}}" DISTRO_LIKE="${{ID_LIKE:-}}"
case "$DISTRO_ID" in case "$DISTRO_ID" in
ubuntu|debian) PKG="apt-get"; PKG_INSTALL="DEBIAN_FRONTEND=noninteractive apt-get install -y" ;; ubuntu|debian)
centos|rhel|rocky|almalinux|ol) PKG="yum"; PKG_INSTALL="yum install -y" ;; PKG="apt-get"
fedora) PKG="dnf"; PKG_INSTALL="dnf install -y" ;; export DEBIAN_FRONTEND=noninteractive
PKG_INSTALL() {{ DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"; }}
;;
centos|rhel|rocky|almalinux|ol)
PKG="yum"
PKG_INSTALL() {{ yum install -y "$@"; }}
;;
fedora)
PKG="dnf"
PKG_INSTALL() {{ dnf install -y "$@"; }}
;;
*) *)
if echo "$DISTRO_LIKE" | grep -qiE "rhel|centos|fedora"; then if echo "$DISTRO_LIKE" | grep -qiE "rhel|centos|fedora"; then
PKG="yum"; PKG_INSTALL="yum install -y" PKG="yum"
PKG_INSTALL() {{ yum install -y "$@"; }}
elif echo "$DISTRO_LIKE" | grep -qi "debian"; then elif echo "$DISTRO_LIKE" | grep -qi "debian"; then
PKG="apt-get"; PKG_INSTALL="DEBIAN_FRONTEND=noninteractive apt-get install -y" PKG="apt-get"
export DEBIAN_FRONTEND=noninteractive
PKG_INSTALL() {{ DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"; }}
else else
die "Unsupported distribution: $DISTRO_ID" die "Unsupported distribution: $DISTRO_ID"
fi fi