#!/usr/bin/env sh # Deployr bootstrap for macOS and Linux. # # curl -fsSL https://git.starwarslab.us/ATOM_IT/Deployr/raw/branch/main/scripts/install.sh | sh # # With no arguments it installs deployr and opens the UI. To pass arguments # through, use `sh -s --`: # # curl -fsSL | sh -s -- install @standard # # Environment: # DEPLOYR_VERSION release tag to install (default: latest) # DEPLOYR_PREFIX install directory (default: /usr/local/bin) # DEPLOYR_INSTALL_ONLY=1 install without running anything set -eu REPO="https://git.starwarslab.us/ATOM_IT/Deployr" VERSION="${DEPLOYR_VERSION:-latest}" PREFIX="${DEPLOYR_PREFIX:-/usr/local/bin}" BIN="$PREFIX/deployr" say() { printf ' %s\n' "$*"; } die() { printf ' error: %s\n' "$*" >&2; exit 1; } # Only escalate when we actually need to write to the prefix, so a user-local # install never prompts for a password it does not need. SUDO="" if [ ! -w "$(dirname "$BIN")" ] 2>/dev/null || [ ! -d "$PREFIX" ]; then if [ "$(id -u)" -ne 0 ]; then command -v sudo >/dev/null 2>&1 || die "need root to write $PREFIX (set DEPLOYR_PREFIX to a writable directory)" SUDO="sudo" fi fi printf '\n Deployr bootstrap\n ------------------------------------------------\n' case "$(uname -s)" in Darwin) OS="darwin" ;; Linux) OS="linux" ;; *) die "unsupported operating system: $(uname -s)" ;; esac case "$(uname -m)" in x86_64|amd64) ARCH="amd64" ;; arm64|aarch64) ARCH="arm64" ;; *) die "unsupported architecture: $(uname -m)" ;; esac ASSET="deployr_${OS}_${ARCH}" say "Platform: $OS/$ARCH" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 3 --connect-timeout 20 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" else die "neither curl nor wget is available" fi } # "latest" is not a real download path in Gitea: resolve the release through the # API and use the asset URLs it publishes. API="$(printf '%s' "$REPO" | sed -E 's#/([^/]+)/([^/]+)$#/api/v1/repos/\1/\2#')" if [ "$VERSION" = "latest" ]; then RELEASE_URL="$API/releases/latest" else RELEASE_URL="$API/releases/tags/$VERSION" fi say "Resolving release ($VERSION) ..." fetch "$RELEASE_URL" "$TMP/release.json" || die "could not reach $RELEASE_URL" # Pull one asset's download URL out of the release JSON without needing jq. asset_url() { tr ',' '\n' < "$TMP/release.json" \ | grep -F "browser_download_url" \ | sed -E 's/.*"browser_download_url" *: *"([^"]+)".*/\1/' \ | grep -E "/$1\$" \ | head -n 1 } ASSET_URL="$(asset_url "$ASSET")" SUMS_URL="$(asset_url 'SHA256SUMS')" [ -n "$ASSET_URL" ] || die "this release has no asset named $ASSET" say "Downloading $ASSET ..." fetch "$ASSET_URL" "$TMP/deployr" || die "download failed" # Verify against the release checksums when they are reachable. if [ -n "$SUMS_URL" ] && fetch "$SUMS_URL" "$TMP/SHA256SUMS" 2>/dev/null; then EXPECTED="$(awk -v a="$ASSET" '{ n=$NF; sub(/^[*.\/]+/,"",n); if (n==a) print $1 }' "$TMP/SHA256SUMS")" if [ -n "$EXPECTED" ]; then if command -v sha256sum >/dev/null 2>&1; then ACTUAL="$(sha256sum "$TMP/deployr" | cut -d' ' -f1)" else ACTUAL="$(shasum -a 256 "$TMP/deployr" | cut -d' ' -f1)" fi [ "$ACTUAL" = "$EXPECTED" ] || die "checksum mismatch: expected $EXPECTED, got $ACTUAL" say "Checksum verified" fi else say "warning: could not fetch SHA256SUMS, skipping verification" fi chmod 0755 "$TMP/deployr" $SUDO mkdir -p "$PREFIX" $SUDO install -m 0755 "$TMP/deployr" "$BIN" say "Installed to $BIN" # macOS quarantines anything downloaded by a browser-facing tool; strip it so # Gatekeeper does not block the binary on first run. if [ "$OS" = "darwin" ] && command -v xattr >/dev/null 2>&1; then $SUDO xattr -d com.apple.quarantine "$BIN" 2>/dev/null || true fi printf ' ------------------------------------------------\n' "$BIN" version printf '\n' [ "${DEPLOYR_INSTALL_ONLY:-}" = "1" ] && exit 0 if [ "$#" -gt 0 ]; then exec $SUDO "$BIN" "$@" fi # The UI needs root to install anything, but it must not run the browser as # root -- deployr opens that as the invoking user itself. exec $SUDO "$BIN" ui