fix(generators): call PKG_INSTALL without '$' under 'set -u'
In bash with 'set -u', an undefined variable triggers an unbound-variable
error. Functions don't satisfy '$FUNCNAME' expansion under set -u, so
the previous fix that kept '$PKG_INSTALL pkg...' as the call syntax
broke every call site:
docker.sh: line 53: PKG_INSTALL: unbound variable
Fix: drop the leading '$' in all 47 call sites across 6 generator
files. 'PKG_INSTALL pkg...' is a normal command/function lookup and
behaves identically under set -u or not.
Verified: web UI served docker.sh now has 'PKG_INSTALL' (no $);
'bash -n' passes; smoke run with stubbed PATH hits real line-53 call
site, mock apt-get receives correct args, exit 0, no unbound variable.
Sampled 6 other generators also syntax-OK with $PKG_INSTALL count 0.
This commit is contained in:
@@ -49,7 +49,7 @@ class Firewall(Generator):
|
||||
fw = []
|
||||
fw.append('case "$DISTRO_ID" in')
|
||||
fw.append(' ubuntu|debian)')
|
||||
fw.append(' $PKG_INSTALL ufw')
|
||||
fw.append(' PKG_INSTALL ufw')
|
||||
fw.append(' ufw --force reset')
|
||||
fw.append(' ufw default ' + ('deny' if deny_in else 'allow') + ' incoming')
|
||||
fw.append(' ufw default ' + ('allow' if allow_out else 'deny') + ' outgoing')
|
||||
@@ -64,7 +64,7 @@ class Firewall(Generator):
|
||||
fw.append(' ufw --force enable')
|
||||
fw.append(' ;;')
|
||||
fw.append(' centos|rhel|rocky|almalinux|ol|fedora)')
|
||||
fw.append(' $PKG_INSTALL firewalld')
|
||||
fw.append(' PKG_INSTALL firewalld')
|
||||
fw.append(' systemctl enable --now firewalld')
|
||||
for p_ in ports:
|
||||
fw.append(f' firewall-cmd --permanent --add-port={p_}/tcp')
|
||||
@@ -78,7 +78,7 @@ class Firewall(Generator):
|
||||
fw.append(' ;;')
|
||||
fw.append(' *)')
|
||||
fw.append(' warn "Auto-firewall not supported on $DISTRO_ID, falling back to iptables"')
|
||||
fw.append(' $PKG_INSTALL iptables-persistent || $PKG_INSTALL iptables-services')
|
||||
fw.append(' PKG_INSTALL iptables-persistent || PKG_INSTALL iptables-services')
|
||||
fw.append(' iptables -P INPUT ' + ('DROP' if deny_in else 'ACCEPT'))
|
||||
fw.append(' iptables -A INPUT -i lo -j ACCEPT')
|
||||
fw.append(' iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT')
|
||||
@@ -149,7 +149,7 @@ class Chrony(Generator):
|
||||
allow = p.get("allow_subnet", "192.168.0.0/16").strip()
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing chrony..."')
|
||||
out.append('$PKG_INSTALL chrony')
|
||||
out.append('PKG_INSTALL chrony')
|
||||
out.append('cp /etc/chrony/chrony.conf /etc/chrony/chrony.conf.bak.$(date +%s) || true')
|
||||
out.append('cat > /etc/chrony/chrony.conf <<CFG_EOF\n'
|
||||
'pool ntp.ubuntu.org maxsources 4\n'
|
||||
|
||||
Reference in New Issue
Block a user