|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# cs launcher script |
| 4 | +# This script lives at https://github.com/coursier/ci-scripts/blob/master/cs.sh |
| 5 | +# (Raw version for curl: https://github.com/coursier/ci-scripts/raw/master/cs.sh) |
| 6 | + |
| 7 | +# Originally adapted from https://github.com/VirtusLab/scala-cli/blob/b754d2afdda114e97febfb0090773cc582bafd19/scala-cli.sh |
| 8 | + |
| 9 | +set -eu |
| 10 | + |
| 11 | +CS_VERSION="2.1.25-M4" |
| 12 | + |
| 13 | +GH_ORG="coursier" |
| 14 | +GH_NAME="coursier" |
| 15 | + |
| 16 | +TAG="v$CS_VERSION" |
| 17 | + |
| 18 | +IS_WINDOWS=false |
| 19 | +if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "MINGW" ]; then |
| 20 | + IS_WINDOWS=true |
| 21 | +fi |
| 22 | + |
| 23 | +if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then |
| 24 | + arch="$(uname -m)" |
| 25 | + if [ "$arch" == "aarch64" ] || [ "$arch" == "x86_64" ]; then |
| 26 | + CS_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/cs-$arch-pc-linux.gz" |
| 27 | + CACHE_BASE="$HOME/.cache/coursier/v1" |
| 28 | + else |
| 29 | + echo "No native coursier launcher available for architecture $arch on Linux" 1>&2 |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +elif [ "$(uname)" == "Darwin" ]; then |
| 33 | + arch="$(uname -m)" |
| 34 | + CACHE_BASE="$HOME/Library/Caches/Coursier/v1" |
| 35 | + if [ "$arch" == "x86_64" ]; then |
| 36 | + CS_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/cs-x86_64-apple-darwin.gz" |
| 37 | + elif [[ "$arch" == "arm64" ]]; then |
| 38 | + CS_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/cs-aarch64-apple-darwin.gz" |
| 39 | + else |
| 40 | + echo "No native coursier launcher available for architecture $arch on macOS" 1>&2 |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +elif [ "$IS_WINDOWS" == true ]; then |
| 44 | + CS_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/cs-x86_64-pc-win32.zip" |
| 45 | + CACHE_BASE="$LOCALAPPDATA/Coursier/cache/v1" |
| 46 | +else |
| 47 | + echo "This standalone cs launcher supports only Linux and macOS." 1>&2 |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | + |
| 51 | +CACHE_DEST="$CACHE_BASE/$(echo "$CS_URL" | sed 's@://@/@')" |
| 52 | + |
| 53 | +if [ "$IS_WINDOWS" == true ]; then |
| 54 | + CS_BIN_PATH="${CACHE_DEST%.zip}.exe" |
| 55 | +else |
| 56 | + CS_BIN_PATH=${CACHE_DEST%.gz} |
| 57 | +fi |
| 58 | + |
| 59 | +if [ ! -f "$CACHE_DEST" ]; then |
| 60 | + mkdir -p "$(dirname "$CACHE_DEST")" |
| 61 | + TMP_DEST="$CACHE_DEST.tmp-setup" |
| 62 | + echo "Downloading $CS_URL" 1>&2 |
| 63 | + curl -fLo "$TMP_DEST" "$CS_URL" |
| 64 | + mv "$TMP_DEST" "$CACHE_DEST" |
| 65 | +fi |
| 66 | + |
| 67 | +if [ ! -f "$CS_BIN_PATH" ]; then |
| 68 | + if [ "$IS_WINDOWS" == true ]; then |
| 69 | + unzip -p "$CACHE_DEST" cs-x86_64-pc-win32.exe > "$CS_BIN_PATH" |
| 70 | + else |
| 71 | + gunzip -k "$CACHE_DEST" |
| 72 | + fi |
| 73 | +fi |
| 74 | + |
| 75 | +if [ "$IS_WINDOWS" != true ]; then |
| 76 | + if [ ! -x "$CS_BIN_PATH" ]; then |
| 77 | + chmod +x "$CS_BIN_PATH" |
| 78 | + fi |
| 79 | +fi |
| 80 | + |
| 81 | +exec "$CS_BIN_PATH" "$@" |
0 commit comments