Skip to content

Commit 251f63c

Browse files
committed
Make scripts POSIX compliant.
1 parent 0352779 commit 251f63c

7 files changed

+9
-31
lines changed

bin/docker-build-images.sh

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
# shellcheck shell=dash
32

43
#
54
# Builds images for each Dockerfile found recursively in the given directory.
@@ -31,19 +30,16 @@ normalize() {
3130

3231
# Build and tag the image based on the git branches in the current directory:
3332
build_versions() {
34-
local image="$1"
33+
image="$1"
3534
shift
3635
if [ ! -d '.git' ]; then
3736
# Not a git repository, so simply build a "latest" image version:
3837
docker build -t "$image" "$@" .
3938
return $?
4039
fi
41-
local current_branch
4240
current_branch=$(git rev-parse --abbrev-ref HEAD)
4341
# Iterate over all branches:
44-
local branches
4542
branches=$(git for-each-ref --format='%(refname:short)' refs/heads/)
46-
local branch
4743
for branch in $branches; do
4844
git checkout "$branch"
4945
# Tag master as "latest":
@@ -60,33 +56,29 @@ build_versions() {
6056

6157
# Builds an image for each git branch of the given Dockerfile directory:
6258
build() {
63-
local cwd="$PWD"
64-
local file
59+
cwd="$PWD"
6560
file="$(basename "$1")"
66-
local dir
6761
dir="$(dirname "$1")"
6862
cd "$dir" || return 1
69-
local organization="$DOCKER_ORG"
63+
organization="$DOCKER_ORG"
7064
if [ -z "$organization" ]; then
7165
# Use the parent folder for the organization/user name:
7266
organization="$(cd .. && normalize "$(basename "$PWD")")"
7367
fi
7468
if [ -n "$DOCKER_HUB" ]; then
7569
organization="$DOCKER_HUB/$organization"
7670
fi
77-
local image
7871
# Use the current folder for the image name:
7972
image="$organization/$(normalize "$(basename "$PWD")")"
8073
# Check if the image depends on another image of the same organization:
81-
local from
8274
from=$(grep "^FROM $organization/" "$file" | awk '{print $2}')
8375
# If it does, only build if the image is already available:
8476
if [ -z "$from" ] || docker inspect "$from" > /dev/null 2>&1; then
8577
build_versions "$image" -f "$file"
8678
else
8779
echo "$image requires $from ..." >&2 && false
8880
fi
89-
local status=$?
81+
status=$?
9082
cd "$cwd" || return 1
9183
return $status
9284
}
@@ -105,7 +97,6 @@ build_images() {
10597
echo 'Could not resolve image dependencies.' >&2
10698
return 1
10799
fi
108-
local file
109100
for file; do
110101
# Shift the arguments list to remove the current Dockerfile:
111102
shift
@@ -130,8 +121,7 @@ NEWLINE='
130121

131122
# Parses the arguments, finds Dockerfiles and starts the builds:
132123
init() {
133-
local args=''
134-
local arg
124+
args=''
135125
for arg; do
136126
if [ -d "$arg" ]; then
137127
# Search for Dockerfiles and add them to the list:

bin/docker-image-exists.sh

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
# shellcheck shell=dash
32

43
#
54
# Checks if a given docker image exists.

bin/envconfig.sh

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
# shellcheck shell=dash
32

43
#
54
# Wrapper script to write environment variables in config files.
@@ -84,16 +83,15 @@ gsub() {
8483
# Parses the given config file and writes the env config:
8584
write_envconfig() {
8685
# Store variables to unset in a space-separated list:
87-
local unset_variables=''
86+
unset_variables=''
8887
# Set the platform dependent base64 decode argument:
89-
local B64_DECODE_ARG
9088
B64_DECODE_ARG="$(b64_decode_arg)"
9189
# Iterate over each line of the config file:
9290
while read -r line; do
9391
# Skip empty lines and lines starting with a hash (#):
9492
[ -z "$line" ] || [ "${line#\#}" != "$line" ] && continue
9593
# Extract the substring up to the first space as variable name:
96-
local name="${line%% *}"
94+
name="${line%% *}"
9795
# Check if the variable should be unset (no exclamation mark prefix):
9896
if [ "${name#!}" = "$name" ]; then
9997
# Store the name and its variants in the list of variables to unset:
@@ -103,10 +101,9 @@ write_envconfig() {
103101
name="${name#!}"
104102
fi
105103
# Extract the substring after the last space as file path:
106-
local path="${line##* }"
104+
path="${line##* }"
107105
# Check if the file exists and has a size greater than zero:
108106
if [ -s "$path" ]; then
109-
local tmpfile
110107
tmpfile="$(mktemp "${TMPDIR:-/tmp}/$name.XXXXXXXXXX")"
111108
# Replace the placeholder with the environment variable:
112109
gsub "{{$name}}" "$(interpolate "$name")" < "$path" > "$tmpfile"

bin/github-release.sh

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ upload_release_asset() {
101101
publish_release() {
102102
# shellcheck disable=SC2059
103103
data="$(printf "$RELEASE_TEMPLATE" "$TAG" "$TAG" "$PRE" false)"
104-
# shellcheck disable=SC2059
105104
curl \
106105
--silent \
107106
--fail \

bin/log.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
# shellcheck shell=dash
32

43
#
54
# Executes the given command and logs the output.
@@ -73,7 +72,6 @@ get_log() {
7372

7473
# Processes stdin and logs each line:
7574
process() {
76-
local log
7775
log=$(get_log "$1")
7876
while read -r line; do
7977
$log "$1" "$line"
@@ -82,7 +80,7 @@ process() {
8280

8381
# Returns a string with the quoted arguments:
8482
quote() {
85-
local args=""
83+
args=''
8684
for arg; do
8785
# Escape single quotes:
8886
arg="$(echo "$arg" | sed "s/'/'\\\\''/g")"

bin/mail.sh

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ set -e
2121
HOST=localhost
2222
PORT=25
2323
USER=${USER:-user}
24-
# shellcheck disable=SC2169
2524
HOSTNAME=${HOSTNAME:-localhost}
2625
FROM="$USER <$USER@$HOSTNAME>"
2726
TO='test <[email protected]>'

bin/superd.sh

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
# shellcheck shell=dash
32

43
#
54
# Supervisor daemon to manage long running processes as a group.
@@ -47,7 +46,6 @@ startup() {
4746

4847
# Returns all given processes and their descendants tree as flat list:
4948
collect() {
50-
local pid
5149
for pid in "$@"; do
5250
printf ' %s' "$pid"
5351
# shellcheck disable=SC2046
@@ -57,7 +55,6 @@ collect() {
5755

5856
# Terminates the given list of processes:
5957
terminate() {
60-
local pid
6158
for pid in "$@"; do
6259
# Terminate the given process, ignore stdout and stderr output:
6360
kill "$pid" > /dev/null 2>&1
@@ -74,7 +71,6 @@ shutdown() {
7471

7572
# Monitors the started background processes until one of them exits:
7673
monitor() {
77-
local pid
7874
while true; do
7975
for pid in $PIDS; do
8076
# Return if the given process is not running:

0 commit comments

Comments
 (0)