normalize the variable format used
Use the "${var}" format for variables where possible
diff --git a/rhcos-toolbox b/rhcos-toolbox
index 203bd06..1f1757f 100755
--- a/rhcos-toolbox
+++ b/rhcos-toolbox
@@ -28,7 +28,7 @@
elif ! image_fresh; then
read -r -p "There is a newer version of ${TOOLBOX_IMAGE} available. Would you like to pull it? [y/N] "
- if [[ $REPLY =~ ^([Yy][Ee][Ss]|[Yy])+$ ]]; then
+ if [[ ${REPLY} =~ ^([Yy][Ee][Ss]|[Yy])+$ ]]; then
image_pull
if container_exists; then
sudo podman rm "${TOOLBOX_NAME}"
@@ -48,15 +48,15 @@
container_create_runlabel
fi
else
- echo "Container '$TOOLBOX_NAME' already exists. Trying to start..."
- echo "(To remove the container and start with a fresh toolbox, run: sudo podman rm '$TOOLBOX_NAME')"
+ echo "Container '${TOOLBOX_NAME}' already exists. Trying to start..."
+ echo "(To remove the container and start with a fresh toolbox, run: sudo podman rm '${TOOLBOX_NAME}')"
fi
local state=$(container_state)
- if [[ "$state" == configured ]] || [[ "$state" == exited ]] || [[ "$state" == stopped ]]; then
+ if [[ "${state}" == configured ]] || [[ "${state}" == exited ]] || [[ "${state}" == stopped ]]; then
container_start
- elif [[ "$state" != running ]]; then
- echo "Container '$TOOLBOX_NAME' in unknown state: '$state'"
+ elif [[ "${state}" != running ]]; then
+ echo "Container '${TOOLBOX_NAME}' in unknown state: '$state'"
return 1
fi
@@ -67,7 +67,7 @@
}
cleanup() {
- sudo podman stop "$TOOLBOX_NAME" &>/dev/null
+ sudo podman stop "${TOOLBOX_NAME}" &>/dev/null
}
container_exists() {
@@ -99,17 +99,17 @@
}
image_runlabel() {
- sudo podman image inspect "$TOOLBOX_IMAGE" --format '{{- if index .Labels "run" -}}{{.Labels.run}}{{- end -}}'
+ sudo podman image inspect "${TOOLBOX_IMAGE}" --format '{{- if index .Labels "run" -}}{{.Labels.run}}{{- end -}}'
}
image_pull() {
- if ! sudo --preserve-env podman pull --authfile "${AUTHFILE}" "$TOOLBOX_IMAGE"; then
+ if ! sudo --preserve-env podman pull --authfile "${AUTHFILE}" "${TOOLBOX_IMAGE}"; then
read -r -p "Would you like to manually authenticate to registry: '${REGISTRY}' and try again? [y/N] "
- if [[ $REPLY =~ ^([Yy][Ee][Ss]|[Yy])+$ ]]; then
+ if [[ ${REPLY} =~ ^([Yy][Ee][Ss]|[Yy])+$ ]]; then
sudo --preserve-env podman login --authfile "${AUTHFILE}" "${REGISTRY}"
- sudo --preserve-env podman pull --authfile "${AUTHFILE}" "$TOOLBOX_IMAGE"
+ sudo --preserve-env podman pull --authfile "${AUTHFILE}" "${TOOLBOX_IMAGE}"
else
echo "Exiting..."
exit 1
@@ -120,7 +120,7 @@
container_create() {
if ! sudo podman create \
--hostname toolbox \
- --name "$TOOLBOX_NAME" \
+ --name "${TOOLBOX_NAME}" \
--privileged \
--net=host \
--pid=host \
@@ -128,23 +128,23 @@
--tty \
--interactive \
-e HOST=/host \
- -e NAME="$TOOLBOX_NAME" \
- -e IMAGE="$IMAGE" \
+ -e NAME="${TOOLBOX_NAME}" \
+ -e IMAGE="${IMAGE}" \
--security-opt label=disable \
--volume /run:/run \
--volume /var/log:/var/log \
--volume /etc/machine-id:/etc/machine-id \
--volume /etc/localtime:/etc/localtime \
--volume /:/host \
- "$TOOLBOX_IMAGE" 2>&1; then
- echo "$0: failed to create container '$TOOLBOX_NAME'"
+ "${TOOLBOX_IMAGE}" 2>&1; then
+ echo "$0: failed to create container '${TOOLBOX_NAME}'"
exit 1
fi
}
container_start() {
- if ! sudo podman start "$TOOLBOX_NAME" 2>&1; then
- echo "$0: failed to start container '$TOOLBOX_NAME'"
+ if ! sudo podman start "${TOOLBOX_NAME}" 2>&1; then
+ echo "$0: failed to start container '${TOOLBOX_NAME}'"
exit 1
fi
}
@@ -153,14 +153,14 @@
# Variable replacement logic reproduced from:
# https://github.com/containers/podman/blob/29d7ab3f82e38c442e449739e218349b9a4a16ea/pkg/domain/infra/abi/containers_runlabel.go#L226
local pod
- pod="$(echo "$runlabel" \
+ pod="$(echo "${runlabel}" \
| sed 's/podman run/sudo podman create/' \
- | sed 's/--name NAME/--name $TOOLBOX_NAME/' \
- | sed 's/NAME=NAME/NAME=$TOOLBOX_NAME/' \
- | sed 's/IMAGE=IMAGE/IMAGE=$TOOLBOX_IMAGE/' \
- | sed 's/host IMAGE/host $TOOLBOX_IMAGE/')"
- if ! eval "$pod" ; then
- echo "$0: failed to create container from runlabel '$TOOLBOX_NAME'"
+ | sed 's/--name NAME/--name ${TOOLBOX_NAME}/' \
+ | sed 's/NAME=NAME/NAME=${TOOLBOX_NAME}/' \
+ | sed 's/IMAGE=IMAGE/IMAGE=${TOOLBOX_IMAGE}/' \
+ | sed 's/host IMAGE/host ${TOOLBOX_IMAGE}/')"
+ if ! eval "${pod}" ; then
+ echo "$0: failed to create container from runlabel '${TOOLBOX_NAME}'"
exit 1
fi
}
@@ -169,19 +169,19 @@
if [[ "$#" -eq 0 ]]; then
cmd=$(sudo podman image inspect "${TOOLBOX_IMAGE}" | jq -re ".[].Config.Cmd[0]") || cmd="/bin/sh"
sudo podman exec \
- --env LANG="$LANG" \
- --env TERM="$TERM" \
+ --env LANG="${LANG}" \
+ --env TERM="${TERM}" \
--tty \
--interactive \
- "$TOOLBOX_NAME" \
- "$cmd"
+ "${TOOLBOX_NAME}" \
+ "${cmd}"
else
sudo podman exec \
- --env LANG="$LANG" \
- --env TERM="$TERM" \
+ --env LANG="${LANG}" \
+ --env TERM="${TERM}" \
--tty \
--interactive \
- "$TOOLBOX_NAME" \
+ "${TOOLBOX_NAME}" \
"$@"
fi
}
@@ -196,9 +196,9 @@
-h/--help: Shows this help message
You may override the following variables by setting them in ${TOOLBOXRC}:
-- REGISTRY: The registry to pull from. Default: $REGISTRY
-- IMAGE: The image and tag from the registry to pull. Default: $IMAGE
-- TOOLBOX_NAME: The name to use for the local container. Default: $TOOLBOX_NAME
+- REGISTRY: The registry to pull from. Default: ${REGISTRY}
+- IMAGE: The image and tag from the registry to pull. Default: ${IMAGE}
+- TOOLBOX_NAME: The name to use for the local container. Default: ${TOOLBOX_NAME}
- AUTHFILE: The location where your registry credentials are stored. Default: ${AUTHFILE}
Example toolboxrc: