Fix VERSION conflict with /etc/os-release

Rename script variable to SCRIPT_VERSION and source os-release in a
subshell to prevent its VERSION variable from colliding with readonly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 15:08:40 +03:00
co-authored by Claude Opus 4.5
parent fefdfdd80a
commit 326b91e57d
+7 -8
View File
@@ -6,7 +6,7 @@ set -euo pipefail
# Automatically enables BBR congestion control on Linux servers. # Automatically enables BBR congestion control on Linux servers.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
readonly VERSION="1.0.0" readonly SCRIPT_VERSION="1.0.0"
readonly SYSCTL_DROP="/etc/sysctl.d/99-bbr.conf" readonly SYSCTL_DROP="/etc/sysctl.d/99-bbr.conf"
readonly SYSCTL_MAIN="/etc/sysctl.conf" readonly SYSCTL_MAIN="/etc/sysctl.conf"
readonly MIN_KERNEL_MAJOR=4 readonly MIN_KERNEL_MAJOR=4
@@ -40,7 +40,7 @@ die() { log_error "$*"; exit 1; }
# ── Usage ────────────────────────────────────────────────────────────────── # ── Usage ──────────────────────────────────────────────────────────────────
usage() { usage() {
cat <<EOF cat <<EOF
${BOLD}bbr-setup ${VERSION}${RESET} — enable TCP BBR congestion control ${BOLD}bbr-setup ${SCRIPT_VERSION}${RESET} — enable TCP BBR congestion control
Usage: $(basename "$0") [OPTIONS] Usage: $(basename "$0") [OPTIONS]
@@ -65,7 +65,7 @@ parse_args() {
--check) CHECK_ONLY=true ;; --check) CHECK_ONLY=true ;;
--dry-run) DRY_RUN=true ;; --dry-run) DRY_RUN=true ;;
-h|--help) usage ;; -h|--help) usage ;;
-v|--version) echo "bbr-setup ${VERSION}"; exit 0 ;; -v|--version) echo "bbr-setup ${SCRIPT_VERSION}"; exit 0 ;;
*) die "Unknown option: $1. Use --help for usage." ;; *) die "Unknown option: $1. Use --help for usage." ;;
esac esac
shift shift
@@ -76,9 +76,8 @@ parse_args() {
detect_distro() { detect_distro() {
local distro="unknown" local distro="unknown"
if [[ -f /etc/os-release ]]; then if [[ -f /etc/os-release ]]; then
# shellcheck disable=SC1091 # Read in a subshell to avoid variable conflicts (e.g. VERSION)
. /etc/os-release distro=$(. /etc/os-release && echo "${ID}")
distro="${ID}"
elif [[ -f /etc/redhat-release ]]; then elif [[ -f /etc/redhat-release ]]; then
distro="rhel" distro="rhel"
elif [[ -f /etc/alpine-release ]]; then elif [[ -f /etc/alpine-release ]]; then
@@ -194,7 +193,7 @@ write_params() {
{ {
echo "" echo ""
echo "# TCP BBR — added by bbr-setup ${VERSION} on $(date '+%Y-%m-%d %H:%M:%S')" echo "# TCP BBR — added by bbr-setup ${SCRIPT_VERSION} on $(date '+%Y-%m-%d %H:%M:%S')"
$needs_qdisc && echo "net.core.default_qdisc = fq" $needs_qdisc && echo "net.core.default_qdisc = fq"
$needs_cc && echo "net.ipv4.tcp_congestion_control = bbr" $needs_cc && echo "net.ipv4.tcp_congestion_control = bbr"
} >> "$target" } >> "$target"
@@ -257,7 +256,7 @@ main() {
parse_args "$@" parse_args "$@"
echo "" echo ""
printf "${CYAN}${BOLD} TCP BBR Setup ${VERSION}${RESET}\n" printf "${CYAN}${BOLD} TCP BBR Setup ${SCRIPT_VERSION}${RESET}\n"
echo "" echo ""
# ── Root check ───────────────────────────────────────────────────── # ── Root check ─────────────────────────────────────────────────────