Skip to content

Commit 5006bab

Browse files
committed
cleanup and reformat bash syntax in 04 script
Cleanup and reforamt bash syntax in 04 script. Also requires fixes to lib/common.sh, but to keep PR contained, I rather took out the utility functions and put them in new lib/utils.sh. Also, fixed some leftover issues I missed first time around in 01, 02 and 03 scripts for consistency. Signed-off-by: Tuomo Tanskanen <[email protected]>
1 parent a28e083 commit 5006bab

13 files changed

+425
-425
lines changed

01_prepare_host.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
set -eux
44

55
# shellcheck disable=SC1091
6-
source lib/logging.sh
6+
. lib/logging.sh
77
# shellcheck disable=SC1091
8-
source lib/common.sh
8+
. lib/common.sh
99

1010
if [[ "${EUID}" -eq 0 ]]; then
1111
echo "Please run 'make' as a non-root user"
@@ -28,7 +28,7 @@ if [[ "${OS}" = "ubuntu" ]]; then
2828
ubuntu24)
2929
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 ;;
3030
*) ;;
31-
esac
31+
esac
3232

3333
elif [[ "${OS}" = "centos" ]] || [[ "${OS}" = "rhel" ]]; then
3434
sudo dnf upgrade -y --nobest
@@ -53,14 +53,14 @@ fi
5353
# NOTE(tuminoid) lib/releases.sh must be after the jq and python installation
5454
# TODO: fix all of the lib/ scripts not to actually run code, but only define functions
5555
# shellcheck disable=SC1091
56-
source lib/releases.sh
56+
. lib/releases.sh
5757
# shellcheck disable=SC1091
58-
source lib/download.sh
58+
. lib/download.sh
5959
# NOTE(fmuyassarov) Make sure to source before runnig install-package-playbook.yml
6060
# because there are some vars exported in network.sh and used by
6161
# install-package-playbook.yml.
6262
# shellcheck disable=SC1091
63-
source lib/network.sh
63+
. lib/network.sh
6464

6565
# NOTE(dtantsur): system-site-packages is required because of certain Python
6666
# packages that cannot be pip-installed (firewalld, selinux, etc).

02_configure_host.sh

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env bash
2+
23
set -eux
34

45
# shellcheck disable=SC1091
5-
source lib/logging.sh
6+
. lib/logging.sh
7+
# shellcheck disable=SC1091
8+
. lib/common.sh
69
# shellcheck disable=SC1091
7-
source lib/common.sh
10+
. lib/network.sh
811
# shellcheck disable=SC1091
9-
source lib/network.sh
12+
. lib/releases.sh
1013
# shellcheck disable=SC1091
11-
source lib/releases.sh
12-
# pre-pull node and container images
14+
. lib/image_prepull.sh
1315
# shellcheck disable=SC1091
14-
source lib/image_prepull.sh
16+
. lib/utils.sh
1517

1618
# cleanup ci config file if it exists from earlier run
1719
rm -f "${CI_CONFIG_FILE}"
@@ -30,7 +32,7 @@ elif grep -q svm /proc/cpuinfo; then
3032
fi
3133

3234
# Clean, copy and extract local IPA
33-
if [[ "${USE_LOCAL_IPA}" == "true" ]]; then
35+
if [[ "${USE_LOCAL_IPA}" = "true" ]]; then
3436
sudo rm -f "${IRONIC_DATA_DIR}/html/images/ironic-python-agent*"
3537
sudo cp "${LOCAL_IPA_PATH}/ironic-python-agent.tar" "${IRONIC_DATA_DIR}/html/images"
3638
sudo tar --extract --file "${IRONIC_DATA_DIR}/html/images/ironic-python-agent.tar" \
@@ -94,7 +96,7 @@ init_minikube()
9496
fi
9597
}
9698

97-
if [[ "${EPHEMERAL_CLUSTER}" == "minikube" ]]; then
99+
if [[ "${EPHEMERAL_CLUSTER}" = "minikube" ]]; then
98100
init_minikube
99101
fi
100102

@@ -137,19 +139,19 @@ EOF
137139
sudo virsh pool-autostart default
138140
fi
139141

140-
if [[ "${OS}" == "ubuntu" ]]; then
142+
if [[ "${OS}" = "ubuntu" ]]; then
141143
# source ubuntu_bridge_network_configuration.sh
142144
# shellcheck disable=SC1091
143145
source ubuntu_bridge_network_configuration.sh
144146
# shellcheck disable=SC1091
145147
source disable_apparmor_driver_libvirtd.sh
146148
else
147-
if [[ "${MANAGE_PRO_BRIDGE}" == "y" ]]; then
149+
if [[ "${MANAGE_PRO_BRIDGE}" = "y" ]]; then
148150
# Adding an IP address in the libvirt definition for this network results in
149151
# dnsmasq being run, we don't want that as we have our own dnsmasq, so set
150152
# the IP address here
151153
if [[ ! -e /etc/NetworkManager/system-connections/provisioning.nmconnection ]]; then
152-
if [[ "${BARE_METAL_PROVISIONER_SUBNET_IPV6_ONLY}" == "true" ]]; then
154+
if [[ "${BARE_METAL_PROVISIONER_SUBNET_IPV6_ONLY}" = "true" ]]; then
153155
sudo tee -a /etc/NetworkManager/system-connections/provisioning.nmconnection <<EOF
154156
[connection]
155157
id=provisioning
@@ -206,7 +208,7 @@ EOF
206208
sudo nmcli con up "${PRO_IF}"
207209
fi
208210

209-
if [[ "${MANAGE_INT_BRIDGE}" == "y" ]]; then
211+
if [[ "${MANAGE_INT_BRIDGE}" = "y" ]]; then
210212
if [[ "$(nmcli con show)" != *"external"* ]]; then
211213
sudo tee /etc/NetworkManager/system-connections/external.nmconnection <<EOF
212214
[connection]
@@ -250,7 +252,7 @@ EOF
250252
fi
251253

252254
# Restart the libvirt network so it applies an ip to the bridge
253-
if [[ "${MANAGE_EXT_BRIDGE}" == "y" ]]; then
255+
if [[ "${MANAGE_EXT_BRIDGE}" = "y" ]]; then
254256
sudo virsh net-destroy external
255257
sudo virsh net-start external
256258
if [[ -n "${INT_IF}" ]]; then
@@ -266,7 +268,7 @@ ANSIBLE_FORCE_COLOR=true "${ANSIBLE}-playbook" \
266268
-b vm-setup/firewall.yml
267269

268270
# FIXME(stbenjam): ansbile firewalld module doesn't seem to be doing the right thing
269-
if [[ "${USE_FIREWALLD}" == "True" ]]; then
271+
if [[ "${USE_FIREWALLD}" = "True" ]]; then
270272
sudo firewall-cmd --zone=libvirt --change-interface=provisioning
271273
sudo firewall-cmd --zone=libvirt --change-interface=external
272274
fi
@@ -281,7 +283,7 @@ fi
281283
reg_state=$(sudo "${CONTAINER_RUNTIME}" inspect registry --format "{{.State.Status}}" || echo "error")
282284

283285
# ubuntu_install_requirements.sh script restarts docker daemon which causes local registry container to be in exited state.
284-
if [[ "${reg_state}" == "exited" ]]; then
286+
if [[ "${reg_state}" = "exited" ]]; then
285287
sudo "${CONTAINER_RUNTIME}" start registry
286288
elif [[ "${reg_state}" != "running" ]]; then
287289
sudo "${CONTAINER_RUNTIME}" rm registry -f || true
@@ -293,7 +295,7 @@ detect_mismatch()
293295
{
294296
local LOCAL_IMAGE="$1"
295297
local REPO_PATH="$2"
296-
if [[ -z "${LOCAL_IMAGE}" ]] || [[ "${LOCAL_IMAGE}" == "${REPO_PATH}" ]]; then
298+
if [[ -z "${LOCAL_IMAGE}" ]] || [[ "${LOCAL_IMAGE}" = "${REPO_PATH}" ]]; then
297299
echo "Local image: ${LOCAL_IMAGE} and repo path: ${REPO_PATH} are matching!"
298300
else
299301
echo "There is a mismatch between LOCAL_IMAGE:${LOCAL_IMAGE} and IMAGE_PATH:${REPO_PATH}"
@@ -330,11 +332,11 @@ clone_repo "${IRSOREPO}" "${IRSOBRANCH}" "${IRSOPATH}" "${IRSOCOMMIT}"
330332
# need to clone the repo.
331333
# There is no need to keep the PATH and the IMAGE vars in sync as there
332334
# is no other use of the path variable than cloning
333-
if [[ "${MARIADB_LOCAL_IMAGE:-}" == "${MARIADB_IMAGE_PATH}" ]]; then
335+
if [[ "${MARIADB_LOCAL_IMAGE:-}" = "${MARIADB_IMAGE_PATH}" ]]; then
334336
clone_repo "${MARIADB_IMAGE_REPO}" "${MARIADB_IMAGE_BRANCH}" "${MARIADB_IMAGE_PATH}" "${MARIADB_IMAGE_COMMIT}"
335337
fi
336338

337-
if [[ "${IRONIC_LOCAL_IMAGE:-}" == "${IRONIC_IMAGE_PATH}" ]]; then
339+
if [[ "${IRONIC_LOCAL_IMAGE:-}" = "${IRONIC_IMAGE_PATH}" ]]; then
338340
clone_repo "${IRONIC_IMAGE_REPO}" "${IRONIC_IMAGE_BRANCH}" "${IRONIC_IMAGE_PATH}" "${IRONIC_IMAGE_COMMIT}"
339341
fi
340342

@@ -352,7 +354,7 @@ for IMAGE_VAR in $(env | grep "_LOCAL_IMAGE=" | grep -o "^[^=]*"); do
352354
IMAGE_DATE="$(date -u +%y_%j_%H%M)"
353355

354356
# Support building ironic-image from source
355-
if [[ "${IMAGE_VAR/_LOCAL_IMAGE}" == "IRONIC" ]] && [[ ${IRONIC_FROM_SOURCE:-} == "true" ]]; then
357+
if [[ "${IMAGE_VAR/_LOCAL_IMAGE}" = "IRONIC" ]] && [[ ${IRONIC_FROM_SOURCE:-} = "true" ]]; then
356358
# NOTE(rpittau): to customize the source origin we need to copy the source code we
357359
# want to use into the sources directory under the ironic-image repository.
358360
for CODE_SOURCE_VAR in $(env | grep -E '^IRONIC_SOURCE=|^IRONIC_INSPECTOR_SOURCE=|^SUSHY_SOURCE=' | grep -o "^[^=]*"); do
@@ -368,7 +370,7 @@ for IMAGE_VAR in $(env | grep "_LOCAL_IMAGE=" | grep -o "^[^=]*"); do
368370
-t "${IMAGE_URL}:latest" -t "${IMAGE_URL}:${IMAGE_GIT_HASH}_${IMAGE_DATE}" . -f ./Dockerfile
369371

370372
# TODO: Do we want to support CAPI in dev-env? CI just pulls it anyways ...
371-
elif [[ "${IMAGE_VAR/_LOCAL_IMAGE}" == "CAPI" ]]; then
373+
elif [[ "${IMAGE_VAR/_LOCAL_IMAGE}" = "CAPI" ]]; then
372374
CAPI_GO_VERSION=$(grep "GO_VERSION ?= [0-9].*" Makefile | sed -e 's/GO_VERSION ?= //g')
373375
# shellcheck disable=SC2016
374376
CAPI_BASEIMAGE=$(grep "GO_CONTAINER_IMAGE ?=" Makefile | sed -e 's/GO_CONTAINER_IMAGE ?= //g' -e 's/$(GO_VERSION)//g')
@@ -382,7 +384,7 @@ for IMAGE_VAR in $(env | grep "_LOCAL_IMAGE=" | grep -o "^[^=]*"); do
382384
fi
383385

384386
cd - || exit
385-
if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
387+
if [[ "${CONTAINER_RUNTIME}" = "podman" ]]; then
386388
sudo "${CONTAINER_RUNTIME}" push --tls-verify=false "${IMAGE_URL}"
387389
else
388390
sudo "${CONTAINER_RUNTIME}" push "${IMAGE_URL}"
@@ -405,7 +407,7 @@ done
405407

406408
# IRONIC_IMAGE is also used in this script so when it is built locally and
407409
# consequently unset, it has to be redefined for local use
408-
if [[ "${BUILD_IRONIC_IMAGE_LOCALLY:-}" == "true" ]] || [[ -n "${IRONIC_LOCAL_IMAGE:-}" ]]; then
410+
if [[ "${BUILD_IRONIC_IMAGE_LOCALLY:-}" = "true" ]] || [[ -n "${IRONIC_LOCAL_IMAGE:-}" ]]; then
409411
IRONIC_IMAGE="${REGISTRY}/localimages/$(basename "${IRONIC_LOCAL_IMAGE}")"
410412
export IRONIC_IMAGE
411413
fi
@@ -423,15 +425,15 @@ for IMAGE_VAR in $(env | grep -v "_LOCAL_IMAGE=" | grep "_IMAGE=" | grep -o "^[^
423425
LOCAL_IMAGE="${REGISTRY}/localimages/${IMAGE_NAME%@*}"
424426
sudo "${CONTAINER_RUNTIME}" tag "${IMAGE}" "${LOCAL_IMAGE}"
425427

426-
if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
428+
if [[ "${CONTAINER_RUNTIME}" = "podman" ]]; then
427429
sudo "${CONTAINER_RUNTIME}" push --tls-verify=false "${LOCAL_IMAGE}"
428430
else
429431
sudo "${CONTAINER_RUNTIME}" push "${LOCAL_IMAGE}"
430432
fi
431433
done
432434

433435
# Start httpd-infra container
434-
if [[ "${OS}" == "ubuntu" ]]; then
436+
if [[ "${OS}" = "ubuntu" ]]; then
435437
# shellcheck disable=SC2086
436438
sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name httpd-infra ${POD_NAME_INFRA} \
437439
-v "${IRONIC_DATA_DIR}":/shared --entrypoint /bin/runhttpd \

03_launch_mgmt_cluster.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
set -eux
44

55
# shellcheck disable=SC1091
6-
source lib/logging.sh
6+
. lib/logging.sh
77
# shellcheck disable=SC1091
8-
source lib/common.sh
8+
. lib/common.sh
99
# shellcheck disable=SC1091
10-
source lib/releases.sh
10+
. lib/releases.sh
1111
# shellcheck disable=SC1091
12-
source lib/network.sh
12+
. lib/network.sh
1313

1414
# Default CAPI_CONFIG_DIR to $HOME/.config directory if XDG_CONFIG_HOME not set
1515
CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}"
@@ -36,9 +36,9 @@ sudo mkdir -p "${IRONIC_DATA_DIR}"
3636
sudo chown -R "${USER}:${USER}" "${IRONIC_DATA_DIR}"
3737

3838
# shellcheck disable=SC1091
39-
source lib/ironic_tls_setup.sh
39+
. lib/ironic_tls_setup.sh
4040
# shellcheck disable=SC1091
41-
source lib/ironic_basic_auth.sh
41+
. lib/ironic_basic_auth.sh
4242

4343
# ------------------------------------
4444
# BMO and Ironic deployment functions
@@ -135,11 +135,11 @@ update_images()
135135
# Assign images from local image registry after update image
136136
# This allows to use cached images for faster downloads
137137
for image_var in $(env | grep -v "_LOCAL_IMAGE=" | grep "_IMAGE=" | grep -o "^[^=]*") ; do
138-
image=${!image_var}
139-
#shellcheck disable=SC2086
140-
image_name="${image##*/}"
141-
local_image="${REGISTRY}/localimages/${image_name}"
142-
eval "${image_var}"="${local_image}"
138+
image=${!image_var}
139+
#shellcheck disable=SC2086
140+
image_name="${image##*/}"
141+
local_image="${REGISTRY}/localimages/${image_name}"
142+
eval "${image_var}"="${local_image}"
143143
done
144144
}
145145

0 commit comments

Comments
 (0)