Skip to content

Commit e70167f

Browse files
larsewiclaude
andcommitted
Reduce provisioning noise in setup-cfengine-build-host.sh
Remove set -x to avoid printing every command during provisioning. Add -q to grep calls used only for control flow and redirect command -v / ls output to /dev/null to suppress confusing messages from conditional checks. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e99c289 commit e70167f

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

ci/setup-cfengine-build-host.sh

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ shopt -s expand_aliases
33
thisdir="$(dirname "$0")"
44

55
# install needed packages and software for a build host
6-
set -ex
6+
set -e
77
if [ "$(id -u)" != "0" ]; then
88
echo "$0 must be run as root"
99
exit 1
@@ -21,15 +21,15 @@ rm -rf cfengine-masterfiles*
2121

2222
function 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

8383
echo "Install distribution upgrades and set software alias for platform"
8484
if [ -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
104104
fi
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'
110110
else
111111
echo "Error: need something to fetch URLs. Didn't find either wget or curl."
112112
exit 1
113113
fi
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
126126
fi
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
134134
fi
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
149149
fi
150150

151151
if [ ! -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
@@ -181,13 +181,13 @@ fi # no cf-agent installed
181181

182182
echo "Checking for pre-installed CFEngine (chicken/egg problem)"
183183
# 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
184+
if ! /var/cfengine/bin/cf-agent -V 2>/dev/null; then
185185
echo "No existing CFEngine install found, try cf-remote..."
186-
if grep -i stretch /etc/os-release; then
186+
if grep -qi stretch /etc/os-release; then
187187
_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
188+
elif grep -qi bullseye /etc/os-release; then
189189
_VERSION="--version 3.24.3" # 3.27.0 has only debian > 11 (bullseye)
190-
elif grep suse /etc/os-release; then
190+
elif grep -q suse /etc/os-release; then
191191
# 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
192192
_VERSION="--version 3.24.2" # we removed suse platforms in 3.27.0
193193
else
@@ -209,9 +209,9 @@ if [ ! -x /var/cfengine/bin/cf-agent ]; then
209209
fi
210210

211211
# 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
212+
if ! ls cfengine-masterfiles*gz >/dev/null 2>&1; then
213213
# 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
214+
if ! command -v cf-remote >/dev/null 2>&1; then
215215
urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.27.0/misc/cfengine-masterfiles-3.27.0-1.pkg.tar.gz
216216
else
217217
cf-remote download masterfiles --output-dir .

0 commit comments

Comments
 (0)