|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +VERSION=${TASK_VERSION:-"3.40.0"} |
| 4 | + |
| 5 | +# Define API |
| 6 | +# ========== |
| 7 | + |
| 8 | +# https://github.com/client9/shlib/blob/master/uname_os.sh |
| 9 | +detect_os() { |
| 10 | + os=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 11 | + |
| 12 | + # fixed up for https://git hub.com/client9/shlib/issues/3 |
| 13 | + case "$os" in |
| 14 | + msys*) os="windows" ;; |
| 15 | + mingw*) os="windows" ;; |
| 16 | + cygwin*) os="windows" ;; |
| 17 | + win*) os="windows" ;; # for windows busybox and like # https://frippery.org/busybox/ |
| 18 | + esac |
| 19 | + |
| 20 | + # other fixups here |
| 21 | + echo "$os" |
| 22 | +} |
| 23 | + |
| 24 | +# https://github.com/client9/shlib/blob/master/uname_arch.sh |
| 25 | +detect_arch() { |
| 26 | + arch=$(uname -m) |
| 27 | + case $arch in |
| 28 | + x86_64) arch="amd64" ;; |
| 29 | + x86) arch="386" ;; |
| 30 | + i686) arch="386" ;; |
| 31 | + i386) arch="386" ;; |
| 32 | + aarch64) arch="arm64" ;; |
| 33 | + armv5*) arch="armv5" ;; |
| 34 | + armv6*) arch="armv6" ;; |
| 35 | + armv7*) arch="armv7" ;; |
| 36 | + esac |
| 37 | + echo ${arch} |
| 38 | +} |
| 39 | + |
| 40 | +# https://github.com/client9/shlib/blob/master/http_download.sh |
| 41 | +download_file() { |
| 42 | + local_file=$1 |
| 43 | + source_url=$2 |
| 44 | + header=$3 |
| 45 | + if [ -z "$header" ]; then |
| 46 | + code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url") |
| 47 | + else |
| 48 | + code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url") |
| 49 | + fi |
| 50 | + if [ "$code" != "200" ]; then |
| 51 | + echo "Error! Downloading file from URL '$source_url' received HTTP status '$code'" |
| 52 | + return 1 |
| 53 | + fi |
| 54 | + return 0 |
| 55 | +} |
| 56 | + |
| 57 | +download_file_once () { |
| 58 | + URL=$1 |
| 59 | + FILE=$2 |
| 60 | + if [ ! -f "${FILE}" ]; then |
| 61 | + mkdir -p "$(dirname "$FILE")" |
| 62 | + FILE_TMP="$2.tmp" |
| 63 | + download_file "$FILE_TMP" "$URL" |
| 64 | + mv "$FILE_TMP" "$FILE" |
| 65 | + fi |
| 66 | +} |
| 67 | + |
| 68 | +unarchive_file() { |
| 69 | + FILE=$1 |
| 70 | + DIR=$2 |
| 71 | + |
| 72 | + rm -fr "$DIR" |
| 73 | + mkdir -p "$DIR" |
| 74 | + if [ "${FILE##*.}" = "zip" ] ; then |
| 75 | + unzip "$FILE" -d "$DIR" |
| 76 | + else |
| 77 | + tar -xf "$FILE" -C "$DIR" |
| 78 | + fi |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +# Download tool |
| 83 | +# ============= |
| 84 | + |
| 85 | +OS=$(detect_os) |
| 86 | +ARCH=$(detect_arch) |
| 87 | + |
| 88 | +AEM_DIR="aem" |
| 89 | +HOME_DIR="${AEM_DIR}/home" |
| 90 | +DOWNLOAD_DIR="${HOME_DIR}/opt" |
| 91 | + |
| 92 | +BIN_DOWNLOAD_NAME="task" |
| 93 | +BIN_ARCHIVE_EXT="tar.gz" |
| 94 | +if [ "$OS" = "windows" ] ; then |
| 95 | + BIN_ARCHIVE_EXT="zip" |
| 96 | +fi |
| 97 | +BIN_DOWNLOAD_URL="https://github.com/go-task/task/releases/download/v${VERSION}/${BIN_DOWNLOAD_NAME}_${OS}_${ARCH}.${BIN_ARCHIVE_EXT}" |
| 98 | +BIN_ROOT="${DOWNLOAD_DIR}/${BIN_DOWNLOAD_NAME}/${VERSION}" |
| 99 | +BIN_ARCHIVE_FILE="${BIN_ROOT}/${BIN_DOWNLOAD_NAME}.${BIN_ARCHIVE_EXT}" |
| 100 | +BIN_ARCHIVE_DIR="${BIN_ROOT}/${BIN_DOWNLOAD_NAME}" |
| 101 | +BIN_NAME="task" |
| 102 | +BIN_EXEC_FILE="${BIN_ARCHIVE_DIR}/${BIN_NAME}" |
| 103 | + |
| 104 | +if [ ! -f "${BIN_EXEC_FILE}" ]; then |
| 105 | + mkdir -p "${BIN_ARCHIVE_DIR}" |
| 106 | + download_file_once "${BIN_DOWNLOAD_URL}" "${BIN_ARCHIVE_FILE}" |
| 107 | + unarchive_file "${BIN_ARCHIVE_FILE}" "${BIN_ARCHIVE_DIR}" |
| 108 | + chmod +x "${BIN_EXEC_FILE}" |
| 109 | +fi |
| 110 | + |
| 111 | +# Prevent OS or shell-specific glitches |
| 112 | +# ===================================== |
| 113 | + |
| 114 | +# https://stackoverflow.com/questions/7250130/how-to-stop-mingw-and-msys-from-mangling-path-names-given-at-the-command-line |
| 115 | +export MSYS_NO_PATHCONV=1 |
| 116 | +export MSYS2_ARG_CONV_EXCL="*" |
| 117 | +export MSYS2_ENV_CONV_EXCL="*" |
| 118 | + |
| 119 | +# Execute Task Tool |
| 120 | +# ================= |
| 121 | + |
| 122 | +# https://taskfile.dev/api/#env |
| 123 | +export TASK_COLOR_GREEN=35 |
| 124 | + |
| 125 | +# https://taskfile.dev/experiments/env-precedence |
| 126 | +export TASK_X_ENV_PRECEDENCE=1 |
| 127 | + |
| 128 | +"./${BIN_EXEC_FILE}" "$@" |
0 commit comments