#!/bin/sh # AirWallet's installer for Mac and Linux: # # curl -fsSL https://airwallet.tech/install | sh # curl -fsSL https://airwallet.tech/install-offline | sh (AirWallet Offline, the hardened build) # # (Windows: irm https://airwallet.tech/install | iex -- the same address, PowerShell's script.) # # It takes the newest release from airwallet.tech/download, checks it against the release's checksum list -- signed # with AirWallet's release key, written into this script below (the key VERIFY.txt names) -- and puts it in place: # Mac the app in /Applications (~/Applications without the rights there), then opens it # Linux the AppImage in ~/Applications, with an entry in the apps menu, then starts it # A browser marks what it downloads as "from the internet", and macOS asks before the first start of an app with # that mark that Apple hasn't notarized (AirWallet isn't, yet). This download has no mark: nothing is asked. # The checks catch a damaged or swapped file on the download server. They can't vouch for this script, which comes # from the same place: read it first if you like (curl -fsSL https://airwallet.tech/install.sh). # Options: --offline, --no-open, --dest=FOLDER. set -eu BASE="${AIRWALLET_BASE:-https://airwallet.tech/download}" KEY='airwallet-release namespaces="airwallet-release" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIusKIKFk8gLDQgFNpxjjo7BRsy05sG11P42Dl0UGP8Y' FPR='SHA256:SV031wxY3OKk8aYTY4a6b7UYa80onuXiDi0tFobgOFE' say() { printf '%s\n' "$*"; } die() { printf 'AirWallet installer: %s\n' "$*" >&2; exit 1; } offline=0 open_it=1 dest="" # (install-offline.sh: offline=1 -- stage.py) for a in "$@"; do case "$a" in --offline) offline=1 ;; --no-open) open_it=0 ;; --dest=*) dest="${a#--dest=}" ;; -h|--help) sed -n '2,17p' "$0" 2>/dev/null || say "See https://airwallet.tech/install.sh"; exit 0 ;; *) die "unknown option: $a (--offline, --no-open, --dest=FOLDER)" ;; esac done off=""; [ "$offline" = 1 ] && off="Offline" case "$(uname -s)" in Darwin) kind=Intel # (the Mac's own chip: a shell under Rosetta reports x86_64 on Apple Silicon too) [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = 1 ] && kind=AppleSilicon pat="AirWallet-${off:+$off-}Mac-$kind-*.dmg" ;; Linux) [ "$(uname -m)" = x86_64 ] || die "AirWallet for Linux is for 64-bit PCs (x86-64); this one is $(uname -m)." pat="AirWallet-${off:+$off-}Linux-x86_64-*.AppImage" ;; *) die "this installer is for Mac and Linux. Windows, Android and Chrome: https://airwallet.tech/#download" ;; esac command -v curl >/dev/null 2>&1 || die "it needs curl." command -v ssh-keygen >/dev/null 2>&1 || die "it needs ssh-keygen to check the release's signature (Linux: the openssh-client package)." if command -v shasum >/dev/null 2>&1; then sha() { shasum -a 256 "$1" | cut -d' ' -f1; } elif command -v sha256sum >/dev/null 2>&1; then sha() { sha256sum "$1" | cut -d' ' -f1; } else die "it needs shasum or sha256sum."; fi tmp="$(mktemp -d "${TMPDIR:-/tmp}/airwallet.XXXXXX")" mnt="" cleanup() { if [ -n "$mnt" ]; then hdiutil detach -quiet "$mnt" 2>/dev/null || true; fi; rm -rf "$tmp"; } trap cleanup EXIT trap 'exit 130' INT TERM get() { curl -fsSL --proto '=https' --tlsv1.2 --retry 2 -o "$2" "$BASE/$1" || die "couldn't download $1 from $BASE."; } # the release's list, signed with the key above: anything else stops here, nothing installed say "Checking the newest AirWallet release…" get SHA256SUMS.txt "$tmp/SHA256SUMS.txt" get SHA256SUMS.txt.sig "$tmp/SHA256SUMS.txt.sig" printf '%s\n' "$KEY" > "$tmp/key" ssh-keygen -Y verify -f "$tmp/key" -I airwallet-release -n airwallet-release -s "$tmp/SHA256SUMS.txt.sig" \ < "$tmp/SHA256SUMS.txt" >/dev/null 2>&1 \ || die "the release's checksum list isn't signed with AirWallet's release key ($FPR). Stopped: nothing was installed." file="" want="" while read -r h n; do n="${n#\*}" case "$n" in $pat) file="$n" want="$h" ;; esac done < "$tmp/SHA256SUMS.txt" [ -n "$file" ] || die "this release has no $pat." say "Downloading $file…" curl -fL --proto '=https' --tlsv1.2 --retry 2 --progress-bar -o "$tmp/$file" "$BASE/$file" || die "couldn't download $file." [ "$(sha "$tmp/$file")" = "$want" ] || die "$file doesn't match the signed list (a damaged or swapped download). Stopped: nothing was installed." say "Checked: it's the signed release." if [ "$(uname -s)" = Darwin ]; then app="AirWallet${off:+ $off}.app" mnt="$tmp/mnt" && mkdir "$mnt" hdiutil attach -quiet -nobrowse -readonly -noautoopen -mountpoint "$mnt" "$tmp/$file" || { mnt=""; die "couldn't open the disk image."; } [ -d "$mnt/$app" ] || die "$app isn't in the disk image." if [ -z "$dest" ]; then if [ -w /Applications ]; then dest=/Applications; else dest="$HOME/Applications"; fi fi mkdir -p "$dest" if pgrep -f "$dest/$app/Contents/" >/dev/null 2>&1; then die "${app%.app} is open: quit it (its menu → Quit), then run this again. Your wallets stay where they are." fi # (an older copy: to the Trash, where it can still be taken back -- the wallets aren't in the app) if [ -e "$dest/$app" ]; then old="$HOME/.Trash/${app%.app} $(date +%Y-%m-%d\ %H.%M.%S).app" mv "$dest/$app" "$old" || die "couldn't move the older $app aside (to the Trash)." say "The older ${app%.app} is in the Trash." fi ditto "$mnt/$app" "$dest/$app" || die "couldn't copy $app into $dest." hdiutil detach -quiet "$mnt" 2>/dev/null || true mnt="" xattr -dr com.apple.quarantine "$dest/$app" 2>/dev/null || true # (none: curl adds no mark. To be sure) codesign --verify --strict "$dest/$app" 2>/dev/null || die "$dest/$app doesn't verify after copying." say "Done: ${app%.app} is in $dest." [ "$open_it" = 1 ] && open "$dest/$app" else dest="${dest:-$HOME/Applications}" name="AirWallet${off:+-$off}" mkdir -p "$dest" cp "$tmp/$file" "$dest/.$name.AppImage.new" chmod +x "$dest/.$name.AppImage.new" mv -f "$dest/.$name.AppImage.new" "$dest/$name.AppImage" # (one step: a copy that's open keeps running) exe="$dest/$name.AppImage" args="" if ! command -v fusermount >/dev/null 2>&1 && ! command -v fusermount3 >/dev/null 2>&1; then args=" --appimage-extract-and-run" # (no FUSE here: unpacked to a temporary folder at each start instead) say "No FUSE here (fusermount): AirWallet starts unpacked each time, a little slower. Your distribution's fuse package lets it start directly." fi apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" icons="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/512x512/apps" mkdir -p "$apps" "$icons" icon="airwallet" curl -fsSL --proto '=https' -o "$icons/airwallet.png" "${BASE%/download}/air-512.png" 2>/dev/null || icon="$exe" low="$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')" cat > "$apps/$low.desktop" </dev/null 2>&1 && update-desktop-database "$apps" >/dev/null 2>&1 || true say "Done: AirWallet${off:+ $off} is in $dest, and in your apps menu." if [ "$open_it" = 1 ] && { [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; }; then # shellcheck disable=SC2086 nohup "$exe"$args >/dev/null 2>&1 & fi fi