#!/bin/sh # dten-speed installer for Linux and macOS: https://dten.com.br/cli # # curl -fsSL https://dten.com.br/cli/install.sh | sh # # It downloads the dten-speed binary for this system from the signed release at # https://github.com/Dten-Org/dten-speed/releases, checks it against the checksum written in this # script (taken from the signed SHA256SUMS of that release), and puts it in ~/.local/bin, without sudo. # Set DTEN_SPEED_INSTALL_DIR to install somewhere else. # # SM-CLI-07 set -eu VERSION="1.0.0" SHA256_LINUX_X64="ee988b85abdd0bebda2959ec8595bcce78becaf005490cb4f72cfca4cab28082" SHA256_LINUX_ARM64="3080fb52784e252068e59ee05a00761265034f2e2eb4b0a68484989098158665" SHA256_MACOS_ARM64="3c4c18bdbeda4d0cc0930d7a152b25e21992c6dc5c5da87cb11fe59d5f8606a2" SHA256_MACOS_X64="6c8487a77b155006cd74ef5e00ebc53a7900e18fa49e17f28cf7771e57734890" RELEASE="https://github.com/Dten-Org/dten-speed/releases/download/v${VERSION}" fail() { printf 'dten-speed install: %s\n' "$1" >&2 exit 1 } platform() { case "$(uname -s)" in Linux) os=linux ;; Darwin) os=macos ;; *) fail "no binary for $(uname -s). On Windows: irm https://dten.com.br/cli/install.ps1 | iex" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=x64 ;; aarch64 | arm64) arch=arm64 ;; *) fail "no binary for the $(uname -m) processor. Measure in the browser: https://dten.com.br" ;; esac if [ "$os" = macos ] && [ "$arch" = x64 ] && [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = 1 ]; then arch=arm64 fi if [ "$os" = linux ] && ldd --version 2>&1 | grep -qi musl; then fail "dten-speed needs glibc; Alpine and other musl systems are not supported." fi case "$os-$arch" in linux-x64) expected=$SHA256_LINUX_X64 ;; linux-arm64) expected=$SHA256_LINUX_ARM64 ;; macos-arm64) expected=$SHA256_MACOS_ARM64 ;; macos-x64) expected=$SHA256_MACOS_X64 ;; esac asset="dten-speed-$os-$arch" } download() { if command -v curl >/dev/null 2>&1; then curl -fsSL --proto '=https' --tlsv1.2 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q --https-only -O "$2" "$1" else fail "needs curl or wget" fi } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d ' ' -f 1 elif command -v openssl >/dev/null 2>&1; then openssl dgst -sha256 -r "$1" | cut -d ' ' -f 1 else fail "needs sha256sum, shasum or openssl to check the download" fi } main() { platform dir="${DTEN_SPEED_INSTALL_DIR:-$HOME/.local/bin}" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM printf 'Downloading dten-speed %s for %s...\n' "$VERSION" "$os-$arch" download "$RELEASE/$asset" "$tmp/dten-speed" actual=$(sha256 "$tmp/dten-speed") if [ "$actual" != "$expected" ]; then fail "the download does not match the signed checksum (expected $expected, got $actual). Nothing was installed." fi chmod 755 "$tmp/dten-speed" if ! version=$("$tmp/dten-speed" --version 2>/dev/null); then fail "dten-speed was downloaded but does not run on this system (it needs 64-bit Linux with glibc, or macOS). Nothing was installed." fi mkdir -p "$dir" mv -f "$tmp/dten-speed" "$dir/dten-speed" printf 'Installed %s (%s).\n' "$dir/dten-speed" "$version" case ":$PATH:" in *":$dir:"*) printf 'Run: dten-speed\n' ;; *) printf '%s is not in your PATH. Add it, or run: %s\n' "$dir" "$dir/dten-speed" ;; esac } main "$@"