@@ -3,7 +3,7 @@ shopt -s expand_aliases
33thisdir=" $( dirname " $0 " ) "
44
55# install needed packages and software for a build host
6- set -ex
6+ set -e
77if [ " $( id -u) " != " 0" ]; then
88 echo " $0 must be run as root"
99 exit 1
@@ -21,15 +21,15 @@ rm -rf cfengine-masterfiles*
2121
2222function cleanup()
2323{
24- set -ex
25- if command -v apt 2 > /dev/null; then
24+ set -e
25+ if command -v apt > /dev/null 2>&1 ; then
2626 # workaround for CFE-4544, remove scriptlets call systemctl even when systemctl is-system-running returns false
2727 rm /bin/systemctl
2828 ln -s /bin/echo /bin/systemctl
2929 apt remove -y cfengine-nova || true
30- elif command -v yum 2 > /dev/null; then
30+ elif command -v yum > /dev/null 2>&1 ; then
3131 yum erase -y cfengine-nova || true
32- elif command -v zypper 2 > /dev/null; then
32+ elif command -v zypper > /dev/null 2>&1 ; then
3333 zypper remove -y cfengine-nova || true
3434 else
3535 echo " No supported package manager to uninstall cfengine."
@@ -43,7 +43,7 @@ function cleanup()
4343 mv /var/log/CFE* /var/bak.cfengine/ || true
4444 mv /var/log/postgresql.log /var/bak.cfengine || true
4545
46- if command -v pkill; then
46+ if command -v pkill > /dev/null 2>&1 ; then
4747 pkill -9 cf-agent || true
4848 pkill -9 cf-serverd || true
4949 pkill -9 cf-monitord || true
@@ -82,13 +82,13 @@ echo "Using buildscripts commit:"
8282
8383echo " Install distribution upgrades and set software alias for platform"
8484if [ -f /etc/os-release ]; then
85- if grep rhel /etc/os-release; then
85+ if grep -q rhel /etc/os-release; then
8686 yum update --assumeyes
8787 alias software=' yum install --assumeyes'
88- elif grep debian /etc/os-release; then
88+ elif grep -q debian /etc/os-release; then
8989 DEBIAN_FRONTEND=noninteractive apt upgrade --yes && DEBIAN_FRONTEND=noninteractive apt autoremove --yes
9090 alias software=' DEBIAN_FRONTEND=noninteractive apt install --yes'
91- elif grep suse /etc/os-release; then
91+ elif grep -q suse /etc/os-release; then
9292 zypper -n update
9393 alias software=' zypper install -y'
9494 else
@@ -103,16 +103,16 @@ else
103103 exit 1
104104fi
105105
106- if command -v wget; then
106+ if command -v wget > /dev/null 2>&1 ; then
107107 alias urlget=wget
108- elif command -v curl; then
108+ elif command -v curl > /dev/null 2>&1 ; then
109109 alias urlget=' curl -O'
110110else
111111 echo " Error: need something to fetch URLs. Didn't find either wget or curl."
112112 exit 1
113113fi
114114
115- if grep 6.10 /etc/issue; then
115+ if grep -q 6.10 /etc/issue 2> /dev/null ; then
116116 # special case of centos-6, cf-remote depends on urllib3 which depends on openssl 1.1.1+ that is not available
117117 # generally we rely on cf-remote to install cfengine-nova and download masterfiles so here we must provide for both of those
118118 echo " Found CentOS 6.10 so installing via hard-coded package URL..."
@@ -125,19 +125,19 @@ if grep 6.10 /etc/issue; then
125125 urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.24.3/misc/cfengine-masterfiles-3.24.3-1.pkg.tar.gz
126126fi
127127
128- if grep -u ubuntu /etc/os-release; then
129- if grep -i version=\" 16 /etc/os-release; then
128+ if grep -q ubuntu /etc/os-release; then
129+ if grep -qi version=\" 16 /etc/os-release; then
130130 urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.21.8/agent/agent_ubuntu16_x86_64/cfengine-nova_3.21.8-1.ubuntu16_amd64.deb
131131 dpkg -i cfengine-nova_3.21.8-1.ubuntu16_amd64.deb
132132 urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.21.8/misc/cfengine-masterfiles-3.21.8-1.pkg.tar.gz
133133 fi
134134fi
135135
136- if grep suse /etc/os-release; then
136+ if grep -q suse /etc/os-release; then
137137 urlget https://cfengine-package-repos.s3.amazonaws.com/pub/gpg.key
138138 rpm --import gpg.key
139139
140- if grep -i version=\" 12 /etc/os-release; then
140+ if grep -qi version=\" 12 /etc/os-release; then
141141 echo " SUSE-12 found, cf-remote cannot be installed here so download directly similar to CentOS-6."
142142 if [ ! -x /var/cfengine/bin/cf-agent ]; then
143143 rm -rf cfengine-nova* rpm
@@ -149,7 +149,7 @@ if grep suse /etc/os-release; then
149149fi
150150
151151if [ ! -x /var/cfengine/cf-agent ]; then
152- if ! ls cfengine-masterfiles* tar.gz; then
152+ if ! ls cfengine-masterfiles* tar.gz > /dev/null 2>&1 ; then
153153 echo " Installing cf-remote for possible package install and masterfiles download"
154154 # try pipx first for debian as pip won't work.
155155 # If that fails to install CFEngine then try python3-pip for redhats.
@@ -159,13 +159,13 @@ if [ ! -x /var/cfengine/cf-agent ]; then
159159 PIP=pipx
160160 export PATH=$HOME /.local/bin:$PATH
161161 elif software python3-pip; then
162- if command -v pip; then
162+ if command -v pip > /dev/null 2>&1 ; then
163163 PIP=pip
164- elif command -v pip3; then
164+ elif command -v pip3 > /dev/null 2>&1 ; then
165165 PIP=pip3
166166 fi
167167 elif software python-pip; then
168- if command -v pip; then
168+ if command -v pip > /dev/null 2>&1 ; then
169169 PIP=pip
170170 fi
171171 else
@@ -174,20 +174,24 @@ if [ ! -x /var/cfengine/cf-agent ]; then
174174 fi
175175 export PATH=/usr/local/bin:$PATH # some pip/pipx use /usr/local/bin
176176
177- $PIP uninstall -y cf-remote || true # just in case a previous is there and would cause the install to fail
177+ if [ " $PIP " = " pipx" ]; then
178+ $PIP uninstall cf-remote || true # no -y option in pipx
179+ else
180+ $PIP uninstall -y cf-remote || true
181+ fi # just in case a previous is there and would cause the install to fail
178182 $PIP install cf-remote || true # if this fails we will try to install from source
179183 fi # no masterfiles downloaded
180184fi # no cf-agent installed
181185
182186echo " Checking for pre-installed CFEngine (chicken/egg problem)"
183187# We need a cf-agent to run build host setup policy and redhat-10-arm did not have a previous package to install.
184- if ! /var/cfengine/bin/cf-agent -V; then
188+ if ! /var/cfengine/bin/cf-agent -V 2> /dev/null ; then
185189 echo " No existing CFEngine install found, try cf-remote..."
186- if grep -i stretch /etc/os-release; then
190+ if grep -qi stretch /etc/os-release; then
187191 _VERSION=" --version 3.21.8" # 3.27.0 and 3.24.x do not have debian 9 (stretch)
188- elif grep -i bullseye /etc/os-release; then
192+ elif grep -qi bullseye /etc/os-release; then
189193 _VERSION=" --version 3.24.3" # 3.27.0 has only debian > 11 (bullseye)
190- elif grep suse /etc/os-release; then
194+ elif grep -q suse /etc/os-release; then
191195 # here we must use 3.24.2 instead of 3.24.3 because 3.24.3 has libcurl 4 which depends on unavailable OPENSSL_3.2.0
192196 _VERSION=" --version 3.24.2" # we removed suse platforms in 3.27.0
193197 else
@@ -209,9 +213,9 @@ if [ ! -x /var/cfengine/bin/cf-agent ]; then
209213fi
210214
211215# download masterfiles if not already present (such as in case of centos-6 above, hard-coded 3.24.3 download)
212- if ! ls cfengine-masterfiles* gz; then
216+ if ! ls cfengine-masterfiles* gz > /dev/null 2>&1 ; then
213217 # if we are using a CFEngine pre-installed (chicken/egg) image we would skip cf-remote install so need to download directly
214- if ! command -v cf-remote; then
218+ if ! command -v cf-remote > /dev/null 2>&1 ; then
215219 urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.27.0/misc/cfengine-masterfiles-3.27.0-1.pkg.tar.gz
216220 else
217221 cf-remote download masterfiles --output-dir .
0 commit comments