Skip to content

Commit 4dd8a77

Browse files
Merge pull request docker-library#26 from polyverse/archis/macos-compat
Make update scripts MacOS compat
2 parents 3e6c4b7 + e69008f commit 4dd8a77

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

apply-templates.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
#!/usr/bin/env bash
22
set -Eeuo pipefail
33

4-
[ -f versions.json ] # run "versions.sh" first
4+
# Don't tolerate outdated bash on Darwin
5+
[ "${BASH_VERSINFO:-0}" -ge 4 ] || ( echo "Outdated bash version: ${BASH_VERSION}. If you're on MacOS/Darwin, please 'brew install bash' to move away from this comically outdated version." && exit 1)
6+
7+
[ -f versions.json ] || (echo "run 'versions.sh' first so templates can be applied to the right versions" && exit 1)
8+
9+
type gawk >/dev/null 2>&1 || (echo "Please install the gawk command. On MacOS, run 'brew install gawk'" && exit 1)
10+
11+
# GNU sed for Mac.
12+
# Copied from:
13+
# https://gist.github.com/bittner/5436f3dc011d43ab7551#file-gnu-tools-for-mac-sh
14+
sedcmd="sed"
15+
16+
[[ `uname` == 'Darwin' ]] && {
17+
which gsed > /dev/null && {
18+
sedcmd="gsed"
19+
} || {
20+
echo 'ERROR: GNU sed required for Mac. You may use homebrew to install it: brew install gnu-sed'
21+
exit 1
22+
}
23+
}
524

625
jqt='.jq-template.awk'
726
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
@@ -76,7 +95,7 @@ for version; do
7695

7796
cmd="$(jq <<<"$cmd" -r '.[0]')"
7897
if [ "$cmd" != 'php' ]; then
79-
sed -i -e 's! php ! '"$cmd"' !g' "$version/$dir/docker-php-entrypoint"
98+
$sedcmd -i -e 's! php ! '"$cmd"' !g' "$version/$dir/docker-php-entrypoint"
8099
fi
81100
done
82101
done

update.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
#!/usr/bin/env bash
22
set -Eeuo pipefail
33

4-
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
4+
# Don't tolerate outdated bash on Darwin
5+
[ "${BASH_VERSINFO:-0}" -ge 4 ] || ( echo "Outdated bash version: ${BASH_VERSION}. If you're on MacOS/Darwin, please 'brew install bash' to move away from this comically outdated version." && exit 1)
6+
7+
# Substitute for readlink that works on MacOS/Darwin.
8+
# Copied from: https://stackoverflow.com/questions/29836821/how-does-this-os-x-bash-script-that-emulates-linuxs-readlink-work
9+
function abspath() {
10+
pushd . > /dev/null;
11+
if [ -d "$1" ]; then
12+
cd "$1";
13+
dirs -l +0;
14+
else
15+
cd "`dirname \"$1\"`";
16+
cur_dir=`dirs -l +0`;
17+
if [ "$cur_dir" == "/" ]; then
18+
echo "$cur_dir`basename \"$1\"`";
19+
else
20+
echo "$cur_dir/`basename \"$1\"`";
21+
fi;
22+
fi;
23+
popd > /dev/null;
24+
}
25+
26+
cd "$(dirname "$(abspath "$BASH_SOURCE")")"
527

628
./versions.sh "$@"
729
./apply-templates.sh "$@"

versions.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
#!/usr/bin/env bash
22
set -Eeuo pipefail
33

4+
# Don't tolerate outdated bash on Darwin
5+
[ "${BASH_VERSINFO:-0}" -ge 4 ] || ( echo "Outdated bash version: ${BASH_VERSION}. If you're on MacOS/Darwin, please 'brew install bash' to move away from this comically outdated version." && exit 1)
6+
7+
# Substitute for readlink that works on MacOS/Darwin.
8+
# Copied from: https://stackoverflow.com/questions/29836821/how-does-this-os-x-bash-script-that-emulates-linuxs-readlink-work
9+
function abspath() {
10+
pushd . > /dev/null;
11+
if [ -d "$1" ]; then
12+
cd "$1";
13+
dirs -l +0;
14+
else
15+
cd "`dirname \"$1\"`";
16+
cur_dir=`dirs -l +0`;
17+
if [ "$cur_dir" == "/" ]; then
18+
echo "$cur_dir`basename \"$1\"`";
19+
else
20+
echo "$cur_dir/`basename \"$1\"`";
21+
fi;
22+
fi;
23+
popd > /dev/null;
24+
}
25+
426
# https://www.php.net/gpg-keys.php
527
declare -A gpgKeys=(
628
# https://wiki.php.net/todo/php81
@@ -31,7 +53,7 @@ declare -A gpgKeys=(
3153
)
3254
# see https://www.php.net/downloads.php
3355

34-
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
56+
cd "$(dirname "$(abspath "$BASH_SOURCE")")"
3557

3658
versions=( "$@" )
3759
if [ ${#versions[@]} -eq 0 ]; then
@@ -43,6 +65,14 @@ fi
4365
versions=( "${versions[@]%/}" )
4466

4567
for version in "${versions[@]}"; do
68+
# Versions begin with a digit
69+
if ! [[ $version =~ [0-9].* ]]; then
70+
echo "Ignoring directory $version, since versions must begin with a digit."
71+
continue
72+
fi
73+
74+
echo "Looking up php at version $version..."
75+
4676
rcVersion="${version%-rc}"
4777
export version rcVersion
4878

0 commit comments

Comments
 (0)