Skip to content

Commit 04ac3d5

Browse files
committed
Format shell scripts with shfmt
1 parent c6df6a0 commit 04ac3d5

File tree

7 files changed

+74
-60
lines changed

7 files changed

+74
-60
lines changed

build-functions/docker-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ push_image_to_registry() {
55
echo "⏫ Pushing '${target_tag}'"
66
$DRY docker push "${target_tag}"
77
echo "✅ Finished pushing the Docker image '${target_tag}'."
8-
}
8+
}

build-functions/get-public-image-config.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ _get_image_configuration() {
4545
--silent \
4646
--location \
4747
--header "Authorization: Bearer $token" \
48-
"https://registry-1.docker.io/v2/$image/blobs/$digest" \
49-
| jq -r ".config.Labels.\"$label\""
48+
"https://registry-1.docker.io/v2/$image/blobs/$digest" |
49+
jq -r ".config.Labels.\"$label\""
5050
}
5151

5252
_get_token() {
5353
local image=$1
5454
curl \
5555
--silent \
56-
"https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" \
57-
| jq -r '.token'
56+
"https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" |
57+
jq -r '.token'
5858
}
5959

6060
_get_digest() {
@@ -65,8 +65,8 @@ _get_digest() {
6565
--silent \
6666
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
6767
--header "Authorization: Bearer $token" \
68-
"https://registry-1.docker.io/v2/$image/manifests/$tag" \
69-
| jq -r '.config.digest'
68+
"https://registry-1.docker.io/v2/$image/manifests/$tag" |
69+
jq -r '.config.digest'
7070
}
7171

7272
_get_layers() {
@@ -77,6 +77,6 @@ _get_layers() {
7777
--silent \
7878
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
7979
--header "Authorization: Bearer $token" \
80-
"https://registry-1.docker.io/v2/$image/manifests/$tag" \
81-
| jq -r '.layers[].digest'
80+
"https://registry-1.docker.io/v2/$image/manifests/$tag" |
81+
jq -r '.layers[].digest'
8282
}

build-latest.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919
# Checking if PRERELEASE is either unset, 'true' or 'false'
2020
###
2121
if [ -n "${PRERELEASE}" ] &&
22-
{ [ "${PRERELEASE}" != "true" ] && [ "${PRERELEASE}" != "false" ]; }; then
22+
{ [ "${PRERELEASE}" != "true" ] && [ "${PRERELEASE}" != "false" ]; }; then
2323

2424
if [ -z "${DEBUG}" ]; then
2525
echo "⚠️ PRERELEASE must be either unset, 'true' or 'false', but was '${PRERELEASE}'!"
@@ -60,9 +60,10 @@ if [ "${PRERELEASE}" == "true" ]; then
6060
# shellcheck disable=SC2003
6161
MINOR_UNSTABLE=$(expr match "${VERSION}" 'v[0-9]\+\.\([0-9]\+\)')
6262

63-
if { [ "${MAJOR_STABLE}" -eq "${MAJOR_UNSTABLE}" ] \
64-
&& [ "${MINOR_STABLE}" -ge "${MINOR_UNSTABLE}" ];
65-
} || [ "${MAJOR_STABLE}" -gt "${MAJOR_UNSTABLE}" ]; then
63+
if {
64+
[ "${MAJOR_STABLE}" -eq "${MAJOR_UNSTABLE}" ] &&
65+
[ "${MINOR_STABLE}" -ge "${MINOR_UNSTABLE}" ]
66+
} || [ "${MAJOR_STABLE}" -gt "${MAJOR_UNSTABLE}" ]; then
6667

6768
echo "❎ Latest unstable version '${VERSION}' is not higher than the latest stable version '$STABLE_VERSION'."
6869
if [ -z "$DEBUG" ]; then

build.sh

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ NETBOX_PATH="${NETBOX_PATH-.netbox}"
117117
###
118118
# Fetching the NetBox source
119119
###
120-
if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then
120+
if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then
121121
echo "🌐 Checking out '${NETBOX_BRANCH}' of NetBox from the url '${URL}' into '${NETBOX_PATH}'"
122122
if [ ! -d "${NETBOX_PATH}" ]; then
123123
$DRY git clone -q --depth 10 -b "${NETBOX_BRANCH}" "${URL}" "${NETBOX_PATH}"
@@ -174,9 +174,18 @@ PROJECT_VERSION="${PROJECT_VERSION-$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]
174174

175175
# Get the Git information from the netbox directory
176176
if [ -d "${NETBOX_PATH}/.git" ]; then
177-
NETBOX_GIT_REF=$(cd "${NETBOX_PATH}"; git rev-parse HEAD)
178-
NETBOX_GIT_BRANCH=$(cd "${NETBOX_PATH}"; git rev-parse --abbrev-ref HEAD)
179-
NETBOX_GIT_URL=$(cd "${NETBOX_PATH}"; git remote get-url origin)
177+
NETBOX_GIT_REF=$(
178+
cd "${NETBOX_PATH}"
179+
git rev-parse HEAD
180+
)
181+
NETBOX_GIT_BRANCH=$(
182+
cd "${NETBOX_PATH}"
183+
git rev-parse --abbrev-ref HEAD
184+
)
185+
NETBOX_GIT_URL=$(
186+
cd "${NETBOX_PATH}"
187+
git remote get-url origin
188+
)
180189
fi
181190

182191
###
@@ -186,19 +195,22 @@ DOCKER_REGISTRY="${DOCKER_REGISTRY-docker.io}"
186195
DOCKER_ORG="${DOCKER_ORG-netboxcommunity}"
187196
DOCKER_REPO="${DOCKER_REPO-netbox}"
188197
case "${NETBOX_BRANCH}" in
189-
master)
190-
TAG="${TAG-latest}";;
191-
develop)
192-
TAG="${TAG-snapshot}";;
193-
*)
194-
TAG="${TAG-$NETBOX_BRANCH}";;
198+
master)
199+
TAG="${TAG-latest}"
200+
;;
201+
develop)
202+
TAG="${TAG-snapshot}"
203+
;;
204+
*)
205+
TAG="${TAG-$NETBOX_BRANCH}"
206+
;;
195207
esac
196208

197209
###
198210
# Determine targets to build
199211
###
200212
DEFAULT_DOCKER_TARGETS=("main" "ldap")
201-
DOCKER_TARGETS=( "${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}")
213+
DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}")
202214
echo "🏭 Building the following targets:" "${DOCKER_TARGETS[@]}"
203215

204216
###
@@ -216,7 +228,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
216228
TARGET_DOCKER_TAG="${TARGET_DOCKER_TAG}-${DOCKER_TARGET}"
217229
fi
218230
if [ -n "${GH_ACTION}" ]; then
219-
echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG}" >> "$GITHUB_ENV"
231+
echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG}" >>"$GITHUB_ENV"
220232
echo "::set-output name=skipped::false"
221233
fi
222234

@@ -242,7 +254,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
242254
###
243255
# Proceeding to buils stage, except if `--push-only` is passed
244256
###
245-
if [ "${2}" != "--push-only" ] ; then
257+
if [ "${2}" != "--push-only" ]; then
246258
###
247259
# Checking if the build is necessary,
248260
# meaning build only if one of those values changed:
@@ -259,7 +271,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
259271
BUILD_REASON="${BUILD_REASON} interactive"
260272
elif [ "$DOCKER_REGISTRY" = "docker.io" ]; then
261273
source ./build-functions/get-public-image-config.sh
262-
IFS=':' read -ra DOCKER_FROM_SPLIT <<< "${DOCKER_FROM}"
274+
IFS=':' read -ra DOCKER_FROM_SPLIT <<<"${DOCKER_FROM}"
263275
if ! [[ ${DOCKER_FROM_SPLIT[0]} =~ .*/.* ]]; then
264276
# Need to use "library/..." for images the have no two part name
265277
DOCKER_FROM_SPLIT[0]="library/${DOCKER_FROM_SPLIT[0]}"
@@ -295,8 +307,8 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
295307
-t "${TARGET_DOCKER_TAG}"
296308
)
297309
if [ -n "${TARGET_DOCKER_SHORT_TAG}" ]; then
298-
DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_SHORT_TAG}" )
299-
DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_LATEST_TAG}" )
310+
DOCKER_BUILD_ARGS+=(-t "${TARGET_DOCKER_SHORT_TAG}")
311+
DOCKER_BUILD_ARGS+=(-t "${TARGET_DOCKER_LATEST_TAG}")
300312
fi
301313

302314
# --label
@@ -323,22 +335,22 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
323335
)
324336
fi
325337
if [ -n "${BUILD_REASON}" ]; then
326-
BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$BUILD_REASON")
327-
DOCKER_BUILD_ARGS+=( --label "BUILD_REASON=${BUILD_REASON}" )
338+
BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<<"$BUILD_REASON")
339+
DOCKER_BUILD_ARGS+=(--label "BUILD_REASON=${BUILD_REASON}")
328340
fi
329341

330342
# --build-arg
331-
DOCKER_BUILD_ARGS+=( --build-arg "NETBOX_PATH=${NETBOX_PATH}" )
343+
DOCKER_BUILD_ARGS+=(--build-arg "NETBOX_PATH=${NETBOX_PATH}")
332344

333345
if [ -n "${DOCKER_FROM}" ]; then
334-
DOCKER_BUILD_ARGS+=( --build-arg "FROM=${DOCKER_FROM}" )
346+
DOCKER_BUILD_ARGS+=(--build-arg "FROM=${DOCKER_FROM}")
335347
fi
336348
if [ -n "${HTTP_PROXY}" ]; then
337-
DOCKER_BUILD_ARGS+=( --build-arg "http_proxy=${HTTP_PROXY}" )
338-
DOCKER_BUILD_ARGS+=( --build-arg "https_proxy=${HTTPS_PROXY}" )
349+
DOCKER_BUILD_ARGS+=(--build-arg "http_proxy=${HTTP_PROXY}")
350+
DOCKER_BUILD_ARGS+=(--build-arg "https_proxy=${HTTPS_PROXY}")
339351
fi
340352
if [ -n "${NO_PROXY}" ]; then
341-
DOCKER_BUILD_ARGS+=( --build-arg "no_proxy=${NO_PROXY}" )
353+
DOCKER_BUILD_ARGS+=(--build-arg "no_proxy=${NO_PROXY}")
342354
fi
343355

344356
###
@@ -360,7 +372,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
360372
###
361373
# Pushing the docker images if either `--push` or `--push-only` are passed
362374
###
363-
if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ] ; then
375+
if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ]; then
364376
source ./build-functions/docker-functions.sh
365377
push_image_to_registry "${TARGET_DOCKER_TAG}"
366378

docker/docker-entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CUR_DB_WAIT_TIME=0
1818
while ! ./manage.py migrate 2>&1 && [ "${CUR_DB_WAIT_TIME}" -lt "${MAX_DB_WAIT_TIME}" ]; do
1919
echo "⏳ Waiting on DB... (${CUR_DB_WAIT_TIME}s / ${MAX_DB_WAIT_TIME}s)"
2020
sleep "${DB_WAIT_TIMEOUT}"
21-
CUR_DB_WAIT_TIME=$(( CUR_DB_WAIT_TIME + DB_WAIT_TIMEOUT ))
21+
CUR_DB_WAIT_TIME=$((CUR_DB_WAIT_TIME + DB_WAIT_TIMEOUT))
2222
done
2323
if [ "${CUR_DB_WAIT_TIME}" -ge "${MAX_DB_WAIT_TIME}" ]; then
2424
echo "❌ Waited ${MAX_DB_WAIT_TIME}s or more for the DB to become ready."
@@ -36,17 +36,17 @@ else
3636
SUPERUSER_EMAIL='admin@example.com'
3737
fi
3838
if [ -f "/run/secrets/superuser_password" ]; then
39-
SUPERUSER_PASSWORD="$(< /run/secrets/superuser_password)"
39+
SUPERUSER_PASSWORD="$(</run/secrets/superuser_password)"
4040
elif [ -z ${SUPERUSER_PASSWORD+x} ]; then
4141
SUPERUSER_PASSWORD='admin'
4242
fi
4343
if [ -f "/run/secrets/superuser_api_token" ]; then
44-
SUPERUSER_API_TOKEN="$(< /run/secrets/superuser_api_token)"
44+
SUPERUSER_API_TOKEN="$(</run/secrets/superuser_api_token)"
4545
elif [ -z ${SUPERUSER_API_TOKEN+x} ]; then
4646
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
4747
fi
4848

49-
./manage.py shell --interface python << END
49+
./manage.py shell --interface python <<END
5050
from django.contrib.auth.models import User
5151
from users.models import Token
5252
if not User.objects.filter(username='${SUPERUSER_NAME}'):

docker/launch-netbox.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ load_configuration() {
2222
# this curl call will get a reply once unit is fully launched
2323
curl --silent --output /dev/null --request GET --unix-socket $UNIT_SOCKET http://localhost/
2424

25-
echo "⚙️ Applying configuration from $UNIT_CONFIG";
26-
27-
RESP_CODE=$(curl \
28-
--silent \
29-
--output /dev/null \
30-
--write-out '%{http_code}' \
31-
--request PUT \
32-
--data-binary "@${UNIT_CONFIG}" \
33-
--unix-socket $UNIT_SOCKET \
34-
http://localhost/config
35-
)
25+
echo "⚙️ Applying configuration from $UNIT_CONFIG"
26+
27+
RESP_CODE=$(
28+
curl \
29+
--silent \
30+
--output /dev/null \
31+
--write-out '%{http_code}' \
32+
--request PUT \
33+
--data-binary "@${UNIT_CONFIG}" \
34+
--unix-socket $UNIT_SOCKET \
35+
http://localhost/config
36+
)
3637
if [ "$RESP_CODE" != "200" ]; then
3738
echo "⚠️ Could no load Unit configuration"
3839
kill "$(cat /opt/unit/unit.pid)"
@@ -45,9 +46,9 @@ load_configuration() {
4546
load_configuration &
4647

4748
exec unitd \
48-
--no-daemon \
49-
--control unix:$UNIT_SOCKET \
50-
--pid /opt/unit/unit.pid \
51-
--log /dev/stdout \
52-
--state /opt/unit/state/ \
53-
--tmp /opt/unit/tmp/
49+
--no-daemon \
50+
--control unix:$UNIT_SOCKET \
51+
--pid /opt/unit/unit.pid \
52+
--log /dev/stdout \
53+
--state /opt/unit/state/ \
54+
--tmp /opt/unit/tmp/

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [ -z "${IMAGE}" ]; then
2828
echo "⚠️ No image defined"
2929

3030
if [ -z "${DEBUG}" ]; then
31-
exit 1;
31+
exit 1
3232
else
3333
echo "⚠️ Would 'exit 1' here, but DEBUG is '${DEBUG}'."
3434
fi
@@ -49,7 +49,7 @@ test_setup() {
4949
(
5050
cd initializers
5151
for script in *.yml; do
52-
sed -E 's/^# //' "${script}" > "../${INITIALIZERS_DIR}/${script}"
52+
sed -E 's/^# //' "${script}" >"../${INITIALIZERS_DIR}/${script}"
5353
done
5454
)
5555
}

0 commit comments

Comments
 (0)