#!/bin/bash # NahuerOptimizador bootstrap # Usage, from Terminal on a Mac: curl -fsSL https://mantenimiento.nahuer.com | bash # # Downloads the one release pinned below into a fresh temporary folder, checks its SHA256 before # extracting anything and opens NahuerOptimizador.app from that folder. Nothing is installed and no # administrator password is needed to launch it. A download that does not match the pinned hash is # deleted and nothing opens; there is no fallback. tools/build_release.py fills in the pinned values. # # Everything runs inside functions and main is called on the last line, so a truncated download # defines at most some functions and runs nothing. bash 3.2 compatible (the one macOS ships). set -euo pipefail readonly VERSION='0.1.0' readonly SHA256='2104e81fd95cebe23a6856813438d976793d68e190ce93749de2d7ab004a1573' readonly BASE_URL='https://mantenimiento.nahuer.com' readonly ZIP_NAME='optimizador-0.1.0.zip' readonly APP_NAME='NahuerOptimizador.app' readonly MIN_MACOS_MAJOR=13 workdir='' launched=0 say() { printf '==> %s\n' "$1" } fail() { printf 'Error: %s\n' "$1" >&2 exit 1 } # Removes the temporary folder on any exit before the app was opened. cleanup() { if [ "$launched" -eq 0 ] && [ -n "$workdir" ] && [ -d "$workdir" ]; then rm -rf -- "$workdir" fi } check_system() { local system version major system=$(uname -s) if [ "$system" != 'Darwin' ]; then fail 'NahuerOptimizador funciona solo en macOS.' fi version=$(sw_vers -productVersion) major=${version%%.*} case "$major" in '' | *[!0-9]*) fail "No se pudo leer la versión de macOS ('$version')." ;; esac if [ "$major" -lt "$MIN_MACOS_MAJOR" ]; then fail "Hace falta macOS 13 o posterior; esta Mac tiene macOS $version." fi } verify_sha256() { local line actual line=$(/usr/bin/shasum -a 256 "$1") actual=${line%% *} [ "$actual" = "$SHA256" ] } main() { say "NahuerOptimizador $VERSION" check_system workdir=$(mktemp -d "${TMPDIR:-/tmp}/nahuer-optimizador.XXXXXX") trap cleanup EXIT local zip="$workdir/$ZIP_NAME" local app="$workdir/app/$APP_NAME" say "Descargando $ZIP_NAME..." if ! curl -fsSL --proto '=https' --tlsv1.2 -o "$zip" "$BASE_URL/releases/$ZIP_NAME"; then fail 'No se pudo descargar. Revisá la conexión a internet y probá de nuevo.' fi say 'Verificando el SHA256...' if ! verify_sha256 "$zip"; then rm -rf -- "$workdir" fail 'El SHA256 no coincide: borré la descarga y no se abrió nada.' fi say 'Descomprimiendo...' /usr/bin/ditto -x -k "$zip" "$workdir/app" if [ ! -d "$app" ]; then fail "El zip no tiene $APP_NAME." fi # A file saved by curl carries no quarantine flag; removing it is harmless and covers copies. /usr/bin/xattr -dr com.apple.quarantine "$app" 2>/dev/null || true say 'Abriendo NahuerOptimizador...' /usr/bin/open "$app" launched=1 say "Listo. La app corre desde $workdir/app; no se instaló nada." } main "$@"