22shopt -s expand_aliases
33thisdir=" $( dirname " $0 " ) "
44
5- # Use the newest CFEngine version we can
6- CFE_VERSION=3.26.0
7- if [ -f /etc/centos-release ]; then
8- _version=$( cat /etc/centos-release | cut -d' ' -f3 | cut -d. -f1)
9- if [ " $_version " = " 6" ]; then
10- CFE_VERSION=3.24.2
11- fi
12- elif [ -f /etc/os-release ]; then
13- source /etc/os-release
14- if [ " $ID " = " debian" ]; then
15- if [ " $VERSION_ID " -lt " 9" ]; then
16- echo " Platform $ID $VERSION_ID is too old."
17- exit 9
18- fi
19- if [ " $VERSION_ID " -lt " 11" ]; then
20- CFE_VERSION=3.21.7
21- fi
22- fi
23- if [ " $ID " = " redhat" ] || [ " $ID " = " centos" ]; then
24- if [ " $VERSION_ID " -lt " 6" ]; then
25- echo " Platform $ID $VERSION_ID is too old."
26- exit 9
27- fi
28- if [ " $VERSION_ID " -lt " 7" ]; then
29- CFE_VERSION=3.24.2
30- fi
31- fi
32- if [ " $ID " = " ubuntu" ]; then
33- _version=" $( echo " $VERSION_ID " | cut -d. -f1) "
34- if [ " $_version " -lt " 16" ]; then
35- echo " Platform $ID $VERSION_ID is too old."
36- exit 9
37- fi
38- if [ " $_version " -lt " 20" ]; then
39- CFE_VERSION=3.21.7
40- fi
41- fi
42- fi
43-
445# install needed packages and software for a build host
456set -ex
467if [ " $( id -u) " != " 0" ]; then
@@ -146,61 +107,40 @@ else
146107 exit 1
147108fi
148109
149- echo " Checking for pre-installed CFEngine (chicken/egg problem)"
150- # We need a cf-agent to run build host setup policy and redhat-10-arm has not previous package to install.
151- # solution: install from source and make a custom AWS AMI image
152- if ! /var/cfengine/bin/cf-agent -V; then
153- echo " No existing CFEngine install found, try quickinstall script..."
154- if grep -i suse /etc/os-release; then
155- # need to add our public key first otherwise zypper install fails
156- rpm --import https://cfengine-package-repos.s3.amazonaws.com/pub/gpg.key
157- if grep ' VERSION.*12' /etc/os-release; then
158- urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-" $CFE_VERSION " /agent/agent_suse12_x86_64/cfengine-nova-" $CFE_VERSION " -1.suse12.x86_64.rpm
159- zypper install -y cfengine-nova-" $CFE_VERSION " -1.suse12.x86_64.rpm
160- elif grep ' VERSION.*15' /etc/os-release; then
161- urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-" $CFE_VERSION " /agent/agent_suse15_x86_64/cfengine-nova-" $CFE_VERSION " -1.suse15.x86_64.rpm
162- zypper install -y cfengine-nova-" $CFE_VERSION " -1.suse15.x86_64.rpm
163- else
164- echo " Unsupported suse version:"
165- grep VERSION /etc/os-release
166- exit 1
167- fi
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
168121 else
169- urlget https://s3.amazonaws.com/cfengine.packages/quick-install-cfengine-enterprise.sh
170- # log sha256 checksum expected and actuall for debugging purposes
171- echo " Expected quick install checksum: "
172- cat " $thisdir " /quick-install-cfengine-enterprise.sh.sha256
173- echo " Actual quick install checksum: "
174- sha256sum quick-install-cfengine-enterprise.sh
175-
176- sha256sum --check " $thisdir " /quick-install-cfengine-enterprise.sh.sha256
177- chmod +x quick-install-cfengine-enterprise.sh
178- export CFEngine_Enterprise_Package_Version=" $CFE_VERSION "
179- bash ./quick-install-cfengine-enterprise.sh agent
122+ echo " failure: neither pip nor pip3 seem to be available."
123+ exit 42
180124 fi
181125fi
126+ export PATH=/usr/local/bin:$PATH # add /usr/local/bin for pip/pipx installed cf-remote
127+
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
182132
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.
183135if ! /var/cfengine/bin/cf-agent -V; then
184- echo " quickinstall script didn't install CFEngine, try cf-remote..."
185- # try pipx first for debian as pip won't work.
186- # If that fails to install CFEngine then try python3-pip for redhats.
187- if software pipx; then
188- pipx install cf-remote
189- export PATH=$HOME /.local/bin:$PATH
190- elif software python3-pip; then
191- pip install cf-remote
192- fi
193- export PATH=/usr/local/bin:$PATH # add /usr/local/bin for pip/pipx installed cf-remote
194- if command -v cf-remote > /dev/null; then
195- cf-remote --log-level info --version master install --clients localhost || true
196- fi
136+ echo " No existing CFEngine install found, try cf-remote..."
137+ cf-remote --log-level info --version master install --clients localhost || true
197138fi
198139
199140if [ ! -x /var/cfengine/bin/cf-agent ]; then
200141 echo " cf-remote didn't install CFEngine, build from source..."
201142 software git
202- echo " quickinstall and cf-remote didn't install cf-agent, try from source"
203- CFE_VERSION=3.26.0 # need to use an actualy release which has a checksum for masterfiles download
143+ echo " cf-remote didn't install cf-agent, try from source"
204144 rm -rf core # just in case we are repeating the script
205145 git clone --recursive --depth 1 https://github.com/cfengine/core
206146 (
@@ -210,11 +150,9 @@ if [ ! -x /var/cfengine/bin/cf-agent ]; then
210150fi
211151
212152# get masterfiles
213- urlget https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-" $CFE_VERSION " /misc/cfengine-masterfiles-" $CFE_VERSION " -1.pkg.tar.gz
214-
215- sha256sum --check " $thisdir " /cfengine-masterfiles-" $CFE_VERSION " -1.pkg.tar.gz.sha256
216-
217- tar xf cfengine-masterfiles-" $CFE_VERSION " -1.pkg.tar.gz
153+ rm -rf cfengine-masterfiles* tar.gz
154+ cf-remote download masterfiles --output-dir .
155+ tar xf cfengine-masterfiles-* tar.gz
218156cp -a masterfiles/* /var/cfengine/inputs/
219157
220158# run three times to ensure all is done
0 commit comments