#!/bin/bash # Install Fiscoo on a Mac with a single command (from https://fiscoo.us/download/; Italian version: /installa/mac.sh): # # curl -fsSL https://fiscoo.us/installa/en/mac.sh | bash -s YOUR-FIRM-CODE # # What it does, in order: # 1. checks macOS (12 or later) and picks the right build: Apple silicon or Intel; # 2. asks the Fiscoo website for the download link using your firm's personal code; # 3. downloads Fiscoo and checks its SHA-256 fingerprint (if it doesn't match, it stops and installs nothing); # 4. copies it to Applications (replacing an older version: your firm's data is not touched) and opens it. # It doesn't ask for a password, doesn't use sudo and doesn't change any Mac settings. Downloaded this way, Fiscoo # opens without the "Open Anyway" step in System Settings. set -euo pipefail # FISCOO_SITO is only for local testing. SITO="${FISCOO_SITO:-https://fiscoo.us}" CODICE="${1:-${FISCOO_CODICE:-}}" grassetto=$'\033[1m'; rosso=$'\033[31m'; verde=$'\033[32m'; normale=$'\033[0m' passo() { printf '%s→ %s%s\n' "$grassetto" "$1" "$normale"; } errore() { printf '\n%sFiscoo could not be installed:%s %s\n' "$rosso" "$normale" "$1" >&2; printf 'If the problem persists, write to us and we’ll help.\n' >&2; exit 1; } printf '\n%sInstalling Fiscoo%s\n\n' "$grassetto" "$normale" [ "$(uname -s)" = "Darwin" ] || errore "this command is for Mac. On Windows, use the command on the Download page." maggiore="$(sw_vers -productVersion | cut -d. -f1)" [ "$maggiore" -ge 12 ] 2>/dev/null || errore "macOS 12 Monterey or later is required (this Mac has $(sw_vers -productVersion))." [ -n "$CODICE" ] || errore "the personal code is missing. Copy the command again from the Download page: the code is already in it." # Apple silicon even when Terminal runs under Rosetta. if [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = "1" ]; then file="mac-arm64"; tipo="Apple silicon"; else file="mac-x64"; tipo="an Intel processor"; fi passo "Mac with $tipo, macOS $(sw_vers -productVersion)" # Response fields read with the system's JavaScript (osascript), without installing anything. leggi() { RISPOSTA="$1" osascript -l JavaScript -e "ObjC.import('stdlib'); const r = JSON.parse(\$.getenv('RISPOSTA')); r['$2'] === undefined ? '' : String(r['$2'])"; } passo "Checking the code" corpo="$(printf '{"codice":"%s","file":"%s"}' "$(printf '%s' "$CODICE" | tr -cd 'A-Za-z0-9 -')" "$file")" risposta="$(curl --proto '=https' --tlsv1.2 -sS -X POST -H 'content-type: application/json' --data "$corpo" "$SITO/api/scarica")" || errore "the Fiscoo website isn’t responding: check your internet connection." messaggio="$(leggi "$risposta" errore 2>/dev/null || true)" [ -z "$messaggio" ] || errore "$messaggio" link="$(leggi "$risposta" url 2>/dev/null)" || errore "invalid response from the website." impronta="$(leggi "$risposta" sha256)" nome="$(leggi "$risposta" file)" [ -n "$link" ] && [ ${#impronta} -eq 64 ] || errore "invalid response from the website." lavoro="$(mktemp -d -t fiscoo)" volume="$lavoro/volume" pulisci() { hdiutil detach "$volume" -quiet >/dev/null 2>&1 || true; rm -rf "$lavoro"; } trap pulisci EXIT passo "Downloading $nome" curl --proto '=https' --tlsv1.2 -fL --progress-bar -o "$lavoro/fiscoo.dmg" "$SITO$link" || errore "download interrupted: try again (the code is still valid)." passo "Checking the file fingerprint" [ "$(shasum -a 256 "$lavoro/fiscoo.dmg" | cut -d' ' -f1)" = "$impronta" ] || errore "the downloaded file is not the one published by Fiscoo (fingerprint mismatch). Nothing was installed." passo "Installing Fiscoo" mkdir -p "$volume" hdiutil attach "$lavoro/fiscoo.dmg" -nobrowse -readonly -noautoopen -mountpoint "$volume" -quiet || errore "the downloaded file can’t be opened." [ -d "$volume/Fiscoo.app" ] || errore "Fiscoo is missing from the downloaded file." # If Fiscoo is open, quit it before replacing it (when it quits, the app stops its own database). if pgrep -f '/Fiscoo.app/Contents/MacOS/Fiscoo' >/dev/null; then osascript -e 'tell application "Fiscoo" to quit' >/dev/null 2>&1 || true for _ in $(seq 1 30); do pgrep -f '/Fiscoo.app/Contents/MacOS/Fiscoo' >/dev/null || break; sleep 1; done pgrep -f '/Fiscoo.app/Contents/MacOS/Fiscoo' >/dev/null && errore "Fiscoo is still open: quit it and run the command again." fi if [ -w /Applications ]; then destinazione="/Applications"; else destinazione="$HOME/Applications"; mkdir -p "$destinazione"; fi rm -rf "$destinazione/Fiscoo.app" ditto "$volume/Fiscoo.app" "$destinazione/Fiscoo.app" || errore "couldn’t copy Fiscoo to $destinazione." xattr -dr com.apple.quarantine "$destinazione/Fiscoo.app" 2>/dev/null || true passo "Opening Fiscoo" open "$destinazione/Fiscoo.app" printf '\n%s✓ Fiscoo is installed in %s.%s Next time, open it from Applications or Launchpad.\n' "$verde" "$destinazione" "$normale" printf 'You can close this Terminal window.\n\n'