Skip to content

Commit bc65073

Browse files
[fixup] Missing earthly.sh script
1 parent ce4453a commit bc65073

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tools/earthly.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
: "${EARTHLY_VERSION:=0.8.16}"
6+
7+
this_file=${BASH_SOURCE[0]}
8+
this_dir=$(readlink -f "$(dirname "$this_file")")
9+
repo_dir=$(dirname "$this_dir")
10+
scratch_dir="$repo_dir/_build"
11+
mkdir -p "$scratch_dir"
12+
13+
# Calc the arch of the executable we want
14+
case "$HOSTTYPE" in
15+
x64|x86_64)
16+
arch=amd64
17+
;;
18+
arm64)
19+
arch=arm64
20+
;;
21+
*)
22+
echo "Unsupported architecture for automatic Earthly download: $HOSTTYPE" 1>&1
23+
exit 99
24+
;;
25+
esac
26+
27+
# The location where the Earthly executable will live
28+
cache_dir="$scratch_dir/_earthly/$EARTHLY_VERSION"
29+
mkdir -p "$cache_dir"
30+
31+
exe_filename="earthly-$(uname | tr '[:upper:]' '[:lower:]')-$arch"
32+
EARTHLY_EXE="$cache_dir/$exe_filename"
33+
34+
# Download if it isn't already present
35+
if ! test -f "$EARTHLY_EXE"; then
36+
echo "Downloading $exe_filename $EARTHLY_VERSION"
37+
url="https://github.com/earthly/earthly/releases/download/v$EARTHLY_VERSION/$exe_filename"
38+
curl --retry 5 -LsS --max-time 120 --fail "$url" --output "$EARTHLY_EXE"
39+
chmod a+x "$EARTHLY_EXE"
40+
fi
41+
42+
"$EARTHLY_EXE" "$@"

0 commit comments

Comments
 (0)