#!/bin/sh set -eu umask 077 download_only=0 case "${1:-}" in "") ;; --download-only) download_only=1;; *) echo "Usage: install.sh [--download-only]" >&2; exit 2;; esac os=$(uname -s); arch=$(uname -m) case "$os" in Darwin) if [ "$(/usr/sbin/sysctl -n hw.optional.arm64 2>/dev/null || true)" = 1 ]; then arch=arm64; fi case "$arch" in arm64) target=darwin-arm64;; x86_64) target=darwin-x64;; *) echo "Unsupported Mac architecture" >&2; exit 2;; esac;; Linux) [ "$(id -u)" -ne 0 ] || { echo "Run as your normal user, not sudo/root" >&2; exit 2; } [ "$arch" = x86_64 ] || { echo "Only Linux x64 is supported" >&2; exit 2; } target=linux-x64 glibc=$(getconf GNU_LIBC_VERSION 2>/dev/null || true); glibc=${glibc#glibc } awk -v v="$glibc" 'BEGIN { split(v,p,"."); exit !(p[1]>2 || (p[1]==2 && p[2]>=34)) }' || { echo "glibc 2.34+ is required" >&2; exit 2; };; *) echo "Unsupported operating system" >&2; exit 2;; esac command -v curl >/dev/null || { echo "curl is required" >&2; exit 2; } case "$target" in darwin-arm64) url='https://downloads.568920429.xyz/releases/0.2.2/Team-DevSpace-0.2.2-macos-arm64.pkg'; hash='c300130ebf86f362148098dc2a6390940dac70318f4cde6bab383234436bca1a'; size=94370674; name='Team-DevSpace-0.2.2-macos-arm64.pkg';; darwin-x64) url='https://downloads.568920429.xyz/releases/0.2.2/Team-DevSpace-0.2.2-macos-x64.pkg'; hash='e799c72dcfe8cc3cbab67b9ac275cda0f5ef76524d9cfbf36905efde01d18c0c'; size=96749765; name='Team-DevSpace-0.2.2-macos-x64.pkg';; linux-x64) url='https://downloads.568920429.xyz/releases/0.2.2/Team-DevSpace-0.2.2-linux-x64-offline.tar.gz'; hash='df09c2ceef09c73d328f06195100095d753be92e7dfa13a8ff15e01c1db49dc7'; size=99955622; name='Team-DevSpace-0.2.2-linux-x64-offline.tar.gz';; esac d=$(mktemp -d) trap 'rm -rf "$d"' EXIT trap 'exit 130' INT; trap 'exit 143' HUP TERM f="$d/$name"; printf "Downloading Team DevSpace (%s)...\n" "$target" curl --fail --silent --show-error --proto "=https" --tlsv1.2 --connect-timeout 30 --max-time 1800 --retry 2 --output "$f" "$url" actual_size=$(wc -c < "$f" | tr -d "[:space:]") if [ "$os" = Darwin ]; then actual=$(shasum -a 256 "$f"); else actual=$(sha256sum "$f"); fi; actual=${actual%% *} [ "$actual" = "$hash" ] && [ "$actual_size" = "$size" ] || { echo "Package verification failed; nothing was installed" >&2; exit 1; } if [ "$os" = Darwin ] || [ "$download_only" = 1 ]; then mkdir -p "$HOME/Downloads"; saved=$(mktemp -d "$HOME/Downloads/TeamDevSpace.XXXXXX"); mv "$f" "$saved/$name" printf "Verified package: %s\n" "$saved/$name" if [ "$download_only" = 0 ]; then printf "Complete the macOS Installer and normal security confirmations; no security settings were changed.\n" /usr/bin/open "$saved/$name" fi else mkdir "$d/media"; tar -xzf "$f" -C "$d/media" sh "$d/media/install.sh" --offline "$d/media" --setup none printf "Software installed. Run ~/.local/bin/team-devspace setup to enter your Access Key; use access-key change later.\n" fi