Skip to content

Commit d9aeba8

Browse files
An earthly.sh shim script
1 parent fe40953 commit d9aeba8

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tools/earthly.sh

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

0 commit comments

Comments
 (0)