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:
+10
-10
@@ -414,7 +414,7 @@ class Nginx(Generator):
|
||||
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing nginx..."')
|
||||
out.append('$PKG_INSTALL nginx openssl curl')
|
||||
out.append('PKG_INSTALL nginx openssl curl')
|
||||
out.append('mkdir -p /etc/nginx/conf.d /var/www/html /etc/nginx/ssl')
|
||||
out.append('')
|
||||
# main nginx.conf (only override the worker_processes line if not 'auto')
|
||||
@@ -540,7 +540,7 @@ class HAProxy(Generator):
|
||||
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing haproxy..."')
|
||||
out.append('$PKG_INSTALL haproxy')
|
||||
out.append('PKG_INSTALL haproxy')
|
||||
out.append('cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak.$(date +%s) || true')
|
||||
out.append('mkdir -p /etc/haproxy')
|
||||
out.append('')
|
||||
@@ -623,7 +623,7 @@ class Keepalived(Generator):
|
||||
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing keepalived..."')
|
||||
out.append('$PKG_INSTALL keepalived')
|
||||
out.append('PKG_INSTALL keepalived')
|
||||
out.append('')
|
||||
out.append('cat > /etc/keepalived/keepalived.conf <<CONF_EOF\n'
|
||||
'global_defs {\n'
|
||||
@@ -709,7 +709,7 @@ class Redis(Generator):
|
||||
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing redis..."')
|
||||
out.append('$PKG_INSTALL redis-server')
|
||||
out.append('PKG_INSTALL redis-server')
|
||||
out.append('')
|
||||
out.append('cat > /etc/redis/redis.conf <<CFG_EOF\n'
|
||||
'bind ' + bind + '\n'
|
||||
@@ -819,7 +819,7 @@ class Tomcat(Generator):
|
||||
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing Java + Tomcat..."')
|
||||
out.append('command -v java >/dev/null || $PKG_INSTALL java-11-openjdk-devel java-11-openjdk || $PKG_INSTALL default-jdk')
|
||||
out.append('command -v java >/dev/null || PKG_INSTALL java-11-openjdk-devel java-11-openjdk || PKG_INSTALL default-jdk')
|
||||
out.append('useradd -r -s /bin/false ' + user + ' 2>/dev/null || true')
|
||||
out.append('cd /opt')
|
||||
out.append('curl -fsSL -o tomcat.tar.gz "' + url + '"')
|
||||
@@ -896,18 +896,18 @@ class Docker(Generator):
|
||||
out.append('log "Installing Docker..."')
|
||||
out.append('case "$PKG" in\n'
|
||||
' apt-get)\n'
|
||||
' $PKG_INSTALL ca-certificates curl gnupg lsb-release\n'
|
||||
' PKG_INSTALL ca-certificates curl gnupg lsb-release\n'
|
||||
' install -m 0755 -d /etc/apt/keyrings\n'
|
||||
' curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg\n'
|
||||
' chmod a+r /etc/apt/keyrings/docker.gpg\n'
|
||||
' echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list\n'
|
||||
' apt-get update\n'
|
||||
' $PKG_INSTALL docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n'
|
||||
' PKG_INSTALL docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n'
|
||||
' ;;\n'
|
||||
' yum|dnf)\n'
|
||||
' $PKG_INSTALL yum-utils\n'
|
||||
' PKG_INSTALL yum-utils\n'
|
||||
' yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo || dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo\n'
|
||||
' $PKG_INSTALL docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n'
|
||||
' PKG_INSTALL docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n'
|
||||
' ;;\n'
|
||||
'esac')
|
||||
out.append('systemctl enable --now docker')
|
||||
@@ -1031,7 +1031,7 @@ class Zookeeper(Generator):
|
||||
|
||||
out = [bash_header(self.title)]
|
||||
out.append('log "Installing Java + ZooKeeper..."')
|
||||
out.append('command -v java >/dev/null || $PKG_INSTALL java-11-openjdk-devel java-11-openjdk || $PKG_INSTALL default-jdk')
|
||||
out.append('command -v java >/dev/null || PKG_INSTALL java-11-openjdk-devel java-11-openjdk || PKG_INSTALL default-jdk')
|
||||
out.append('useradd -r -s /bin/false zookeeper 2>/dev/null || true')
|
||||
out.append('cd /opt')
|
||||
out.append('curl -fsSL -o zk.tar.gz https://archive.apache.org/dist/zookeeper/zookeeper-' + ver + '/apache-zookeeper-' + ver + '-bin.tar.gz')
|
||||
|
||||
Reference in New Issue
Block a user