Skip to content

Commit 3381047

Browse files
committed
Use set -euxo pipefail in 01_install_requirements
Replace set -ex with set -euxo pipefail for consistency with 02_configure_host.sh and 04_setup_ironic.sh. Guard optional environment variables with :- defaults to avoid nounset errors, scope || true to grep in pipelines that may legitimately produce no matches, and fix a $ARCH typo that should be $GOARCH. Also fix common.sh to handle the case where Go is not yet installed when sourced by 01_install_requirements.sh — skip 'go env' if the go binary is absent and default GOPATH to empty.
1 parent 2f483b9 commit 3381047

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

01_install_requirements.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -ex
2+
set -euxo pipefail
33

44

55
source logging.sh
@@ -10,7 +10,7 @@ source validation.sh
1010

1111
early_deploy_validation true
1212

13-
if [ -z "${METAL3_DEV_ENV}" ]; then
13+
if [ -z "${METAL3_DEV_ENV:-}" ]; then
1414
export REPO_PATH=${WORKING_DIR}
1515
sync_repo_and_patch metal3-dev-env https://github.com/metal3-io/metal3-dev-env.git
1616
pushd ${METAL3_DEV_ENV_PATH}
@@ -41,7 +41,7 @@ sudo sh -c "echo 'max_parallel_downloads=8' >> /etc/dnf/dnf.conf"
4141
# in the upgrade command,but this is more explicit and complete
4242
sudo dnf -y clean all
4343

44-
old_version=$(sudo dnf info NetworkManager | grep Version | cut -d ':' -f 2)
44+
old_version=$(sudo dnf info NetworkManager | { grep Version || true; } | cut -d ':' -f 2)
4545

4646
# Update to latest packages first
4747
# Number of attempts
@@ -69,7 +69,7 @@ if (( attempt > MAX_RETRIES )); then
6969
exit 1
7070
fi
7171

72-
new_version=$(sudo dnf info NetworkManager | grep Version | cut -d ':' -f 2)
72+
new_version=$(sudo dnf info NetworkManager | { grep Version || true; } | cut -d ':' -f 2)
7373
# If NetworkManager was upgraded it needs to be restarted
7474
if [ "$old_version" != "$new_version" ]; then
7575
sudo systemctl restart NetworkManager
@@ -153,7 +153,7 @@ GO_CHECKSUM="$(
153153
)"
154154

155155
if [ -z "$GO_CHECKSUM" ]; then
156-
echo "Error: Could not find checksum for $VERSION ($OS/$ARCH)" >&2
156+
echo "Error: Could not find checksum for $VERSION ($OS/$GOARCH)" >&2
157157
else
158158
echo "Checksum: $GO_CHECKSUM"
159159
fi
@@ -180,17 +180,17 @@ ANSIBLE_FORCE_COLOR=true ansible-playbook \
180180
-b -vvv vm-setup/install-package-playbook.yml
181181
popd
182182

183-
if [ -n "${KNI_INSTALL_FROM_GIT}" ]; then
183+
if [ -n "${KNI_INSTALL_FROM_GIT:-}" ]; then
184184
# zip is required for building the installer from source
185185
sudo dnf -y install zip
186186
fi
187187

188188
# Install nfs for persistent volumes
189-
if [ "${PERSISTENT_IMAGEREG}" == true ] ; then
189+
if [ "${PERSISTENT_IMAGEREG:-}" == true ] ; then
190190
sudo dnf -y install nfs-utils
191191
fi
192192

193-
if [[ "${NODES_PLATFORM}" == "baremetal" ]] ; then
193+
if [[ "${NODES_PLATFORM:-}" == "baremetal" ]] ; then
194194
sudo dnf -y install ipmitool
195195
fi
196196

common.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ export PATH="/usr/local/go/bin:$HOME/.local/bin:$PATH"
66
# Set a PS4 value which logs the script name and line #.
77
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
88

9-
eval "$(go env)"
10-
11-
export PATH="${GOPATH}/bin:$PATH"
9+
if command -v go &>/dev/null; then
10+
eval "$(go env)"
11+
fi
12+
export PATH="${GOPATH:-}/bin:$PATH"
1213

1314
# Ensure if a go program crashes we get a coredump
1415
#

0 commit comments

Comments
 (0)