Merge pull request #5 from claude-hdb/fix/os-release-clobbers-version
fix: source /etc/os-release in a subshell — it clobbers $VERSION
This commit is contained in:
commit
5e5b864a74
3 changed files with 16 additions and 6 deletions
|
|
@ -58,11 +58,13 @@ fi
|
||||||
# --- guards ------------------------------------------------------------------
|
# --- guards ------------------------------------------------------------------
|
||||||
[ "$(id -u)" -eq 0 ] || die "must run as root"
|
[ "$(id -u)" -eq 0 ] || die "must run as root"
|
||||||
if [ -r /etc/os-release ]; then
|
if [ -r /etc/os-release ]; then
|
||||||
|
# Sourced in a subshell: os-release defines VERSION, NAME, ID, etc. —
|
||||||
|
# sourcing it in the main shell silently clobbers same-named script vars.
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. /etc/os-release
|
OS_FAMILY="$(. /etc/os-release && printf '%s %s' "${ID:-}" "${ID_LIKE:-}")"
|
||||||
case "${ID:-} ${ID_LIKE:-}" in
|
case "$OS_FAMILY" in
|
||||||
*debian*) ;;
|
*debian*) ;;
|
||||||
*) warn "not a Debian-family system (ID=${ID:-unknown}); proceeding anyway" ;;
|
*) warn "not a Debian-family system (${OS_FAMILY:-unknown}); proceeding anyway" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
warn "cannot read /etc/os-release; proceeding anyway"
|
warn "cannot read /etc/os-release; proceeding anyway"
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,13 @@ VERSION="${VERSION#v}"
|
||||||
# --- guards ----------------------------------------------------------------
|
# --- guards ----------------------------------------------------------------
|
||||||
[ "$(id -u)" -eq 0 ] || die "must run as root"
|
[ "$(id -u)" -eq 0 ] || die "must run as root"
|
||||||
if [ -r /etc/os-release ]; then
|
if [ -r /etc/os-release ]; then
|
||||||
|
# Sourced in a subshell: os-release defines VERSION (e.g. "13 (trixie)"),
|
||||||
|
# which would clobber this script's $VERSION.
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. /etc/os-release
|
OS_FAMILY="$(. /etc/os-release && printf '%s %s' "${ID:-}" "${ID_LIKE:-}")"
|
||||||
case "${ID:-} ${ID_LIKE:-}" in
|
case "$OS_FAMILY" in
|
||||||
*debian*) ;;
|
*debian*) ;;
|
||||||
*) warn "not a Debian-family system (ID=${ID:-unknown}); proceeding anyway" ;;
|
*) warn "not a Debian-family system (${OS_FAMILY:-unknown}); proceeding anyway" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
warn "cannot read /etc/os-release; proceeding anyway"
|
warn "cannot read /etc/os-release; proceeding anyway"
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,12 @@ else
|
||||||
echo "skip: runner non-root refusal (running as root)"
|
echo "skip: runner non-root refusal (running as root)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Regression: /etc/os-release defines VERSION (e.g. "13 (trixie)" on Debian);
|
||||||
|
# sourcing it in the main shell clobbers a script's $VERSION and splices the
|
||||||
|
# OS string into download URLs. It must only ever be sourced in a subshell.
|
||||||
|
check "no main-shell os-release sourcing" 1 "" \
|
||||||
|
grep -rnE '^[[:space:]]*\.[[:space:]]+/etc/os-release' "$ROOT/commands"
|
||||||
|
|
||||||
echo "---"
|
echo "---"
|
||||||
echo "$PASS passed, $FAIL failed"
|
echo "$PASS passed, $FAIL failed"
|
||||||
[ "$FAIL" -eq 0 ]
|
[ "$FAIL" -eq 0 ]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue