|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script install the latest version of goci for the correct OS and architecture. |
| 4 | + |
| 5 | +# Exit immediately if a command exits with a non-zero status |
| 6 | +set -e |
| 7 | + |
| 8 | +GITHUB_TOKEN=$1 |
| 9 | +if [[ -z $GITHUB_TOKEN ]]; then echo "Missing arg1 GITHUB_TOKEN" && exit 1; fi |
| 10 | + |
| 11 | +# Configuration |
| 12 | +REPO="Clever/ci-scripts" |
| 13 | +INSTALL_DIR="/usr/local/bin" |
| 14 | + |
| 15 | +# Detect OS and Architecture |
| 16 | +OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 17 | +ARCH=$(uname -m) |
| 18 | +if [[ "$ARCH" == "x86_64" ]]; then |
| 19 | + ARCH="amd64" |
| 20 | +fi |
| 21 | + |
| 22 | +# Fetch the latest release |
| 23 | +echo "Fetching the latest release from $REPO..." |
| 24 | +LATEST_RELEASE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$REPO/releases/latest") |
| 25 | + |
| 26 | +if [ -z "$LATEST_RELEASE" ]; then |
| 27 | + echo "Error: No latest release found. Check repository permissions." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Find the asset matching the OS and architecture |
| 32 | +ASSET_URL=$(echo "$LATEST_RELEASE" | jq -r ".assets[] | select(.name | test(\"$OS.*$ARCH\")) | .browser_download_url") |
| 33 | + |
| 34 | +if [ -z "$ASSET_URL" ]; then |
| 35 | + echo "Error: No matching release asset found for OS=$OS and ARCH=$ARCH." |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +# Download the asset |
| 40 | +ASSET_NAME=$(basename "$ASSET_URL") |
| 41 | +echo "Downloading $ASSET_NAME..." |
| 42 | +curl -L -o "/tmp/$ASSET_NAME" "$ASSET_URL" |
| 43 | + |
| 44 | +# Move the asset to the install directory and make it executable |
| 45 | +echo "Installing $ASSET_NAME to $INSTALL_DIR..." |
| 46 | +sudo mv "/tmp/$ASSET_NAME" "$INSTALL_DIR/goci" |
| 47 | +sudo chmod +x "$INSTALL_DIR/goci" |
| 48 | + |
| 49 | +echo "Installation complete. goci is now available in \$PATH." |
0 commit comments