Skip to content

Commit b3ef946

Browse files
authored
Merge pull request #2130 from larsewi/provision
ENT-13766: Various fixes / improvements to buildhost provisioning
2 parents e99c289 + 0ae92fe commit b3ef946

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

ci/cfengine-build-host-setup.cf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ bundle agent cfengine_build_host_setup
6767

6868

6969
mingw_build_host::
70-
"wine:i386";
7170
"mingw-w64";
71+
mingw_build_host.have_i386_architecture::
72+
"wine:i386";
7273
(debian_10|debian_11).systemssl_build_host::
7374
"libssl-dev";
7475
debian.bootstrap_pr_host::
@@ -239,9 +240,8 @@ bundle agent cfengine_build_host_setup
239240
classes:
240241
debian_11::
241242
"have_pip2" expression => fileexists("/usr/local/bin/pip");
242-
ubuntu_16::
243-
"have_i386_architecture" expression => strcmp(execresult("${paths.dpkg} --print-foreign-architectures", "noshell"), "i386");
244243
ubuntu::
244+
"have_i386_architecture" expression => strcmp(execresult("${paths.dpkg} --print-foreign-architectures", "noshell"), "i386");
245245
"localhost_localdomain_hostname_missing" expression => not(strcmp(execresult("${paths.hostname} -f", "useshell"), "localhost.localdomain"));
246246
opensuse|suse|sles::
247247
"have_$(suse_users_and_groups)_group" expression => returnszero("grep '^$(suse_users_and_groups):' /etc/group >/dev/null", "useshell");
@@ -321,7 +321,11 @@ jenkins_builds ALL=NOPASSWD: /usr/bin/podman
321321
"yum install -y python3-pip" contain => in_shell;
322322

323323
mingw_build_host.!have_i386_architecture::
324-
"${paths.dpkg} --add-architecture i386";
324+
"${paths.dpkg} --add-architecture i386"
325+
handle => "i386_arch_added";
326+
"DEBIAN_FRONTEND=noninteractive apt-get update"
327+
depends_on => { "i386_arch_added" },
328+
contain => in_shell;
325329

326330
ubuntu.not_in_container.localhost_localdomain_hostname_missing::
327331
"/usr/bin/hostnamectl set-hostname localhost.localdomain"

ci/setup-cfengine-build-host.sh

Lines changed: 31 additions & 27 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
@@ -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
180184
fi # no cf-agent installed
181185

182186
echo "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
209213
fi
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

Comments
 (0)