#!/bin/bash { set -euo pipefail 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=/usr/local/bin INSTALL_PATH="$INSTALL_DIR/devcloud" if [[ ! ":$PATH:" == *":$INSTALL_DIR:"* ]]; then echoerr "Your path is missing /usr/local/bin, you need to add this to use this installer." exit 1 fi $SUDO install -d -m 755 "$INSTALL_DIR" URL=https://cli.sehlat.io/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() { local url=$1 local output=$2 local curl_args=( --fail --location --silent --show-error --output "$output" --retry 5 --retry-delay 2 --continue-at - ) if curl_supports_retry_all_errors; then curl_args+=(--retry-all-errors) fi if curl "${curl_args[@]}" --http2 "$url"; then return 0 fi echoerr "Download over HTTP/2 failed, retrying over HTTP/1.1..." curl "${curl_args[@]}" --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 }