1616mkdir -p /home/jenkins
1717chown -R jenkins /home/jenkins
1818
19+ # cleanup any previous runs cfengine-masterfiles tar balls
20+ rm -rf cfengine-masterfiles*
21+
1922function cleanup()
2023{
2124 set -ex
@@ -83,6 +86,9 @@ if [ -f /etc/os-release ]; then
8386 elif grep debian /etc/os-release; then
8487 DEBIAN_FRONTEND=noninteractive apt upgrade --yes && DEBIAN_FRONTEND=noninteractive apt autoremove --yes
8588 alias software=' DEBIAN_FRONTEND=noninteractive apt install --yes'
89+ if grep stretch /etc/os-release; then
90+ DEBIAN_STRETCH=1 # special case, cf-remote install needs to NOT use master as there are no packages there
91+ fi
8692 elif grep suse /etc/os-release; then
8793 zypper -n update
8894 alias software=' zypper install -y'
@@ -107,34 +113,65 @@ else
107113 exit 1
108114fi
109115
110- echo " Installing cf-remote for possible package install and masterfiles download"
111- # try pipx first for debian as pip won't work.
112- # If that fails to install CFEngine then try python3-pip for redhats.
113- if software pipx; then
114- pipx install cf-remote
115- export PATH=$HOME /.local/bin:$PATH
116- elif software python3-pip; then
117- if command -v pip; then
118- pip install cf-remote
119- elif command -v pip3; then
120- pip3 install cf-remote
121- else
122- echo " failure: neither pip nor pip3 seem to be available."
123- exit 42
116+ if grep 6.10 /etc/issue; then
117+ # special case of centos-6, cf-remote depends on urllib3 which depends on openssl 1.1.1+ that is not available
118+ # generally we rely on cf-remote to install cfengine-nova and download masterfiles so here we must provide for both of those
119+ echo " Found CentOS 6.10 so installing via hard-coded package URL..."
120+
121+ if [ ! -x /var/cfengine/bin/cf-agent ]; then
122+ rm -rf cfengine-nova* rpm
123+ urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.24.3/agent/agent_rhel6_x86_64/cfengine-nova-3.24.3-1.el6.x86_64.rpm
124+ rpm -i cfengine-nova-3.24.3-1.el6.x86_64.rpm
124125 fi
126+ urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.24.3/misc/cfengine-masterfiles-3.24.3-1.pkg.tar.gz
125127fi
126- export PATH=/usr/local/bin:$PATH # add /usr/local/bin for pip/pipx installed cf-remote
127128
128- if ! command -v cf-remote; then
129- echo " cf-remote was not installed, it is required so exiting now"
130- exit 42
131- fi
129+ if [ -x /var/cfengine/bin/cf-agent ]; then
130+ echo " Case of pre-installed CFEngine so skipping cf-remote install and assuming download of masterfiles earlier in the script."
131+ else
132+ echo " Installing cf-remote for possible package install and masterfiles download"
133+ # try pipx first for debian as pip won't work.
134+ # If that fails to install CFEngine then try python3-pip for redhats.
135+ PIP=" "
136+ software python3-venv || true # on ubuntu-20 this is needed, debian-12 it is not but won't hurt
137+ if software pipx; then
138+ PIP=pipx
139+ export PATH=$HOME /.local/bin:$PATH
140+ elif software python3-pip; then
141+ if command -v pip; then
142+ PIP=pip
143+ elif command -v pip3; then
144+ PIP=pip3
145+ fi
146+ elif software python-pip; then
147+ if command -v pip; then
148+ PIP=pip
149+ fi
150+ else
151+ echo " Tried installing pipx, python3-pip and python-pip, none of which resulted in pipx, pip3 or pip being available. Exiting."
152+ exit 23
153+ fi
154+ export PATH=/usr/local/bin:$PATH # some pip/pipx use /usr/local/bin
155+
156+ $PIP uninstall cf-remote || true # just in case a previous is there and would cause the install to fail
157+ $PIP install cf-remote
158+
159+ if ! command -v cf-remote; then
160+ echo " cf-remote was not installed, it is required so exiting now"
161+ exit 42
162+ fi
132163
133- echo " Checking for pre-installed CFEngine (chicken/egg problem)"
134- # We need a cf-agent to run build host setup policy and redhat-10-arm did not have a previous package to install.
135- if ! /var/cfengine/bin/cf-agent -V; then
136- echo " No existing CFEngine install found, try cf-remote..."
137- cf-remote --log-level info --version master install --clients localhost || true
164+ echo " Checking for pre-installed CFEngine (chicken/egg problem)"
165+ # We need a cf-agent to run build host setup policy and redhat-10-arm did not have a previous package to install.
166+ if ! /var/cfengine/bin/cf-agent -V; then
167+ echo " No existing CFEngine install found, try cf-remote..."
168+ if [ -n " $DEBIAN_STRETCH " ]; then
169+ _VERSION=" --version 3.21.8"
170+ else
171+ _VERSION=" --version master"
172+ fi
173+ cf-remote --log-level info $_VERSION install --clients localhost || true
174+ fi
138175fi
139176
140177if [ ! -x /var/cfengine/bin/cf-agent ]; then
@@ -149,9 +186,10 @@ if [ ! -x /var/cfengine/bin/cf-agent ]; then
149186 )
150187fi
151188
152- # get masterfiles
153- rm -rf cfengine-masterfiles* tar.gz
154- cf-remote download masterfiles --output-dir .
189+ # download masterfiles if not already present (such as in case of centos-6 above, hard-coded 3.24.3 download)
190+ if ! ls cfengine-masterfiles* gz; then
191+ cf-remote download masterfiles --output-dir .
192+ fi
155193tar xf cfengine-masterfiles-* tar.gz
156194cp -a masterfiles/* /var/cfengine/inputs/
157195
0 commit comments