#!/bin/sh { set -eu SUDO='' if [ "$(id -u)" != "0" ]; then SUDO='sudo' echo "This script requires superuser access." echo "You will be prompted for your password by sudo." # clear any previous sudo permission sudo -k fi echoerr() { echo "$@" 1>&2; } case $(uname -s) in Linux|linux) os=linux ;; Darwin|darwin) os=darwin ;; *) os= ;; esac if [ -z "$os" ]; then echoerr "OS $(uname -s) not supported." exit 1 fi case $(uname -m) in amd64|x86_64) arch=amd64 ;; arm64|aarch64) arch=arm64 ;; *) arch= ;; esac if [ -z "$arch" ]; then echoerr "Architecture $(uname -m) not supported." exit 1 fi INSTALL_DIR= case ":$PATH:" in *":/usr/local/bin:"*) INSTALL_DIR=/usr/local/bin ;; esac if [ -z "$INSTALL_DIR" ] && [ "$os" = darwin ]; then case ":$PATH:" in *":/opt/homebrew/bin:"*) INSTALL_DIR=/opt/homebrew/bin ;; esac fi if [ -z "$INSTALL_DIR" ]; then if [ "$os" = darwin ]; then echoerr "Your path is missing /usr/local/bin or /opt/homebrew/bin, you need to add one of them to use this installer." else echoerr "Your path is missing /usr/local/bin, you need to add this to use this installer." fi exit 1 fi INSTALL_PATH="$INSTALL_DIR/devcloud" $SUDO install -d -m 755 "$INSTALL_DIR" URL=https://cli.tribbles.cloud/bin/$os/$arch/devcloud echo "Downloading CLI from $URL to a temporary file..." TMPFILE=$(mktemp) trap 'rm -f "$TMPFILE"' EXIT curl_supports_retry_all_errors() { curl --help all 2>/dev/null | grep -q -- '--retry-all-errors' } download_with_curl() { url=$1 output=$2 retry_all_errors= if curl_supports_retry_all_errors; then retry_all_errors=--retry-all-errors fi if curl --fail --location --silent --show-error --output "$output" \ --retry 5 --retry-delay 2 --continue-at - $retry_all_errors \ --http2 "$url"; then return 0 fi echoerr "Download over HTTP/2 failed, retrying over HTTP/1.1..." curl --fail --location --silent --show-error --output "$output" \ --retry 5 --retry-delay 2 --continue-at - $retry_all_errors \ --http1.1 "$url" } if command -v curl >/dev/null 2>&1; then download_with_curl "$URL" "$TMPFILE" elif command -v wget >/dev/null 2>&1; then wget -O "$TMPFILE" "$URL" else echoerr "This installer requires curl or wget." exit 1 fi if [ ! -s "$TMPFILE" ]; then echoerr "Downloaded file is empty." exit 1 fi echo "Installing devcloud to $INSTALL_DIR..." $SUDO install -m 755 "$TMPFILE" "$INSTALL_PATH" echo "devcloud installed to $INSTALL_PATH" devcloud --version }