#!/usr/bin/env bash # Installs a complete release and a persistent user service. No cargo/npm needed. # curl -fsSL https://install.openartifact.sh/install.sh | bash set -euo pipefail umask 077 fail() { printf 'open-artifact: %s\n' "$*" >&2; exit 1; } case "$(uname -s)" in MINGW*|MSYS*|CYGWIN*) script="$(mktemp --suffix=.ps1)" trap 'rm -f "$script"' EXIT curl -fsSL --proto '=https' --proto-redir '=https' https://install.openartifact.sh/install.ps1 -o "$script" powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$(cygpath -w "$script")" exit $? ;; esac [[ "$(id -u)" != 0 ]] || fail 'Run as your regular user, without sudo. Use Docker for a root-managed installation.' for cmd in curl tar uname mktemp; do command -v "$cmd" >/dev/null || fail "$cmd is required"; done case "$(uname -s)" in Linux) os=unknown-linux-musl;; Darwin) os=apple-darwin;; *) fail 'Supported systems: Linux and macOS';; esac case "$(uname -m)" in x86_64|amd64) arch=x86_64;; aarch64|arm64) arch=aarch64;; *) fail 'Supported CPUs: x86_64 and arm64';; esac target="${arch}-${os}" version="${OPEN_ARTIFACT_VERSION:-latest}" [[ "$version" == latest || "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.-]+)?$ ]] || fail 'Invalid release version' repo=https://github.com/dusanstanojeviccs/open-artifact if [[ -n "${OPEN_ARTIFACT_RELEASES_URL:-}" ]]; then base="${OPEN_ARTIFACT_RELEASES_URL%/}/${version}" elif [[ "$version" == latest ]]; then base="${repo}/releases/latest/download" else base="${repo}/releases/download/${version}"; fi case "$base" in https://*|file://*) ;; *) fail 'Release downloads require HTTPS (file:// is supported for offline installation)' ;; esac archive="open-artifact-${target}.tar.gz" staging="$(mktemp -d)" trap 'rm -rf "$staging"' EXIT fetch() { curl --fail --silent --show-error --location --proto '=https,file' --proto-redir '=https' --retry 3 "$1" -o "$2"; } printf 'Downloading Open Artifact for %s…\n' "$target" fetch "$base/$archive" "$staging/$archive" fetch "$base/checksums.txt" "$staging/checksums.txt" expected="$(awk -v file="$archive" '$2==file {print $1}' "$staging/checksums.txt")" [[ "$expected" =~ ^[a-fA-F0-9]{64}$ ]] || fail 'No unique valid checksum for this archive' if command -v sha256sum >/dev/null; then actual="$(sha256sum "$staging/$archive" | awk '{print $1}')" elif command -v shasum >/dev/null; then actual="$(shasum -a 256 "$staging/$archive" | awk '{print $1}')" else fail 'sha256sum or shasum is required'; fi [[ "$actual" == "$expected" ]] || fail 'Checksum mismatch; nothing was installed' # Refuse paths outside the expected package before extraction. Our release # packager dereferences symlinks; archives contain directories and regular files. tar -tzf "$staging/$archive" > "$staging/members" awk -v root="open-artifact-$target" 'index($0,root "/")!=1 || $0 ~ /(^|\/)\.\.(\/|$)/ {bad=1} END{exit bad}' "$staging/members" || fail 'Unsafe archive path' if tar -tvzf "$staging/$archive" | awk 'substr($0,1,1)!="d" && substr($0,1,1)!="-" {bad=1} END {exit !bad}'; then fail 'Archive contains links or special files'; fi tar -xzf "$staging/$archive" -C "$staging" runtime="$staging/open-artifact-$target" [[ -x "$runtime/bin/node" && -x "$runtime/bin/open-artifact" ]] || fail 'Release is missing runtime binaries' "$runtime/bin/open-artifact" --version "$runtime/bin/node" "$runtime/scripts/install-runtime.mjs" "$runtime"