Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions functions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

#!/usr/bin/env bash
#
# Utlity functions

info() {
Expand Down Expand Up @@ -37,12 +37,12 @@ function get_arch() {
arch="arm32v7"
;;
*)
echo "$0 does not support architecture $arch ... aborting"
echo "$0 does not support architecture ${arch} ... aborting"
exit 1
;;
esac

echo "$arch"
echo "${arch}"
}

# Get corresponding variants based on the architecture.
Expand All @@ -62,12 +62,12 @@ function get_variants() {

arch=$(get_arch)
variantsfilter=("$@")
IFS=' ' read -ra availablevariants <<<"$(grep "^$arch" "$dir/architectures" | sed -E 's/'"$arch"'[[:space:]]*//' | sed -E 's/,/ /g')"
IFS=' ' read -ra availablevariants <<<"$(grep "^${arch}" "${dir}/architectures" | sed -E 's/'"${arch}"'[[:space:]]*//' | sed -E 's/,/ /g')"

if [ ${#variantsfilter[@]} -gt 0 ]; then
for variant1 in "${availablevariants[@]}"; do
for variant2 in "${variantsfilter[@]}"; do
if [[ "$variant1" == "$variant2" ]]; then
if [ "$variant1" = "$variant2" ]; then
variants+=("$variant1")
fi
done
Expand Down Expand Up @@ -100,16 +100,16 @@ function get_supported_arches() {
shift

# Get default supported arches
lines=$(grep "$variant" "$(dirname "$version")"/architectures 2>/dev/null | cut -d' ' -f1)
lines=$(grep "$variant" "$(dirname "${version}")"/architectures 2>/dev/null | cut -d' ' -f1)

# Get version specific supported architectures if there is specialized information
if [ -a "$version"/architectures ]; then
lines=$(grep "$variant" "$version"/architectures 2>/dev/null | cut -d' ' -f1)
if [ -a "${version}"/architectures ]; then
lines=$(grep "$variant" "${version}"/architectures 2>/dev/null | cut -d' ' -f1)
fi

while IFS='' read -r line; do
arches+=("$line")
done <<<"$lines"
arches+=("${line}")
done <<<"${lines}"

echo "${arches[@]}"
}
Expand All @@ -127,7 +127,7 @@ function get_config() {
shift

local value
value=$(grep "^$name" "$dir/config" | sed -E 's/'"$name"'[[:space:]]*//')
value=$(grep "^$name" "${dir}/config" | sed -E 's/'"$name"'[[:space:]]*//')
echo "$value"
}

Expand All @@ -150,13 +150,13 @@ function get_versions() {
fi

for dir in "${dirs[@]}"; do
if [ -a "$dir/config" ]; then
if [ -a "${dir}/config" ]; then
local subdirs
IFS=' ' read -ra subdirs <<<"$(get_versions "${dir#./}")"
for subdir in "${subdirs[@]}"; do
versions+=("$subdir")
done
elif [ -a "$dir/Dockerfile" ]; then
elif [ -a "${dir}/Dockerfile" ]; then
versions+=("${dir#./}")
fi
done
Expand All @@ -171,7 +171,7 @@ function get_fork_name() {
version=$1
shift

IFS='/' read -ra versionparts <<<"$version"
IFS='/' read -ra versionparts <<<"${version}"
if [ ${#versionparts[@]} -gt 1 ]; then
echo "${versionparts[0]}"
fi
Expand All @@ -182,7 +182,7 @@ function get_full_version() {
version=$1
shift

grep -m1 'ENV NODE_VERSION ' "$version/Dockerfile" | cut -d' ' -f3
grep -m1 'ENV NODE_VERSION ' "${version}/Dockerfile" | cut -d' ' -f3
}

function get_major_minor_version() {
Expand All @@ -191,9 +191,9 @@ function get_major_minor_version() {
shift

local fullversion
fullversion=$(get_full_version "$version")
fullversion=$(get_full_version "${version}")

echo "$(echo "$fullversion" | cut -d'.' -f1).$(echo "$fullversion" | cut -d'.' -f2)"
echo "$(echo "${fullversion}" | cut -d'.' -f1).$(echo "${fullversion}" | cut -d'.' -f2)"
}

function get_tag() {
Expand All @@ -206,14 +206,14 @@ function get_tag() {
shift

local tagversion
if [ "$versiontype" = full ]; then
tagversion=$(get_full_version "$version")
elif [ "$versiontype" = majorminor ]; then
tagversion=$(get_major_minor_version "$version")
if [ "${versiontype}" = full ]; then
tagversion=$(get_full_version "${version}")
elif [ "${versiontype}" = majorminor ]; then
tagversion=$(get_major_minor_version "${version}")
fi

local tagparts
IFS=' ' read -ra tagparts <<<"$(get_fork_name "$version") $tagversion"
IFS=' ' read -ra tagparts <<<"$(get_fork_name "${version}") ${tagversion}"
IFS='-'
echo "${tagparts[*]}"
unset IFS
Expand All @@ -230,12 +230,12 @@ function sort_versions() {
unset IFS

while IFS='' read -r line; do
sorted+=("$line")
done <<<"$(echo "$lines" | grep "^[0-9]" | sort -r)"
sorted+=("${line}")
done <<<"$(echo "${lines}" | grep "^[0-9]" | sort -r)"

while IFS='' read -r line; do
sorted+=("$line")
done <<<"$(echo "$lines" | grep -v "^[0-9]" | sort -r)"
sorted+=("${line}")
done <<<"$(echo "${lines}" | grep -v "^[0-9]" | sort -r)"

echo "${sorted[@]}"
}
27 changes: 14 additions & 13 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash

set -e
. functions.sh

Expand Down Expand Up @@ -31,7 +32,7 @@ fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
}

echo "# this file is generated via ${url}/blob/$(fileCommit "$self")/$self"
echo "# this file is generated via ${url}/blob/$(fileCommit "${self}")/${self}"
echo
echo "Maintainers: The Node.js Docker Team <${url}> (@nodejs)"
echo "GitRepo: ${url}.git"
Expand All @@ -49,24 +50,24 @@ join() {
get_stub() {
local version="$1"
shift
IFS='/' read -ra versionparts <<<"$version"
IFS='/' read -ra versionparts <<<"${version}"
local stub
eval stub="$(join '_' "${versionparts[@]}" | awk -F. '{ print "$array_" $1 }')"
echo "$stub"
}

for version in "${versions[@]}"; do
# Skip "docs" and other non-docker directories
[ -f "$version/Dockerfile" ] || continue
[ -f "${version}/Dockerfile" ] || continue

stub=$(get_stub "$version")
commit="$(fileCommit "$version")"
fullVersion="$(get_tag "$version" full)"
majorMinorVersion="$(get_tag "$version" majorminor)"
stub=$(get_stub "${version}")
commit="$(fileCommit "${version}")"
fullVersion="$(get_tag "${version}" full)"
majorMinorVersion="$(get_tag "${version}" majorminor)"

IFS=' ' read -ra versionAliases <<<"$fullVersion $majorMinorVersion $stub"
# Get supported architectures for a specific version. See details in function.sh
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "$version" "default")"
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "${version}" "default")"

echo "Tags: $(join ', ' "${versionAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
Expand All @@ -76,19 +77,19 @@ for version in "${versions[@]}"; do

# Get supported variants according to the target architecture.
# See details in function.sh
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "$version")")"
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "${version}")")"
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "$version/$variant/Dockerfile" ] || continue
[ -f "${version}/${variant}/Dockerfile" ] || continue

commit="$(fileCommit "$version/$variant")"
commit="$(fileCommit "${version}/${variant}")"

slash='/'
variantAliases=("${versionAliases[@]/%/-${variant//$slash/-}}")
variantAliases=("${variantAliases[@]//latest-/}")
# Get supported architectures for a specific version and variant.
# See details in function.sh
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "$version" "$variant")"
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "${version}" "${variant}")"

echo "Tags: $(join ', ' "${variantAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
Expand Down
Loading