#!/bin/sh # Shipcrate web installer: curl -fsSL https://shipcrate.app/install | sh # It does NOT download the product. It finds the zip you bought (in ~/Downloads, or the # path in $SHIPCRATE_ZIP), unpacks it to ~/Shipcrate and runs its install.sh. # Upgrading keeps your projects (studio/data) and companion-app settings. set -eu say() { printf '%s\n' "$*"; } die() { printf '\nStopped: %s\n' "$*" >&2; exit 1; } [ "$(uname -s)" = Darwin ] || die "Shipcrate runs on a Mac." command -v unzip >/dev/null 2>&1 || die "unzip was not found." ZIP="${SHIPCRATE_ZIP:-}" if [ -z "$ZIP" ]; then # shellcheck disable=SC2012 ZIP="$(ls -t "$HOME"/Downloads/shipcrate-*.zip 2>/dev/null | head -n 1 || true)" fi if [ -z "$ZIP" ]; then say "I couldn't find shipcrate-*.zip in your Downloads folder." if ( : /dev/null; then printf 'Drag the zip you bought into this window, then press Enter: ' >/dev/tty IFS= read -r ZIP /dev/null)" || die "That file is not a valid zip." TOP="$(printf '%s\n' "$LIST" | sed -n 's|^\(shipcrate-[^/]*\)/VERSION$|\1|p' | head -n 1)" [ -n "$TOP" ] || die "That zip is not a Shipcrate download (no shipcrate-*/VERSION inside)." printf '%s\n' "$LIST" | grep -qx "$TOP/install.sh" || die "That zip is not a Shipcrate download (no install.sh inside)." DEST="${SHIPCRATE_DIR:-$HOME/Shipcrate}" TMP="$(mktemp -d "$HOME/.shipcrate-unpack.XXXXXX")" trap 'rm -rf "$TMP"' EXIT INT TERM unzip -q "$ZIP" -d "$TMP" || die "Could not unpack the zip." [ -f "$TMP/$TOP/install.sh" ] || die "The unpacked folder is missing install.sh." say "Version $(cat "$TMP/$TOP/VERSION")" if [ -d "$DEST" ]; then say "Upgrading $DEST (keeping your projects and companion-app settings)." if [ -d "$DEST/studio/data" ]; then rm -rf "$TMP/$TOP/studio/data" mkdir -p "$TMP/$TOP/studio" cp -R "$DEST/studio/data" "$TMP/$TOP/studio/data" fi for d in "$DEST"/companions/*/; do n="$(basename "$d")" [ -d "$TMP/$TOP/companions/$n" ] || continue for f in Team.xcconfig device.local; do [ -f "$d$f" ] && cp "$d$f" "$TMP/$TOP/companions/$n/$f" done done OLD="$DEST.old.$$" mv "$DEST" "$OLD" if mv "$TMP/$TOP" "$DEST"; then rm -rf "$OLD"; else mv "$OLD" "$DEST"; die "Could not replace $DEST; your old copy was left in place."; fi else mv "$TMP/$TOP" "$DEST" fi rm -rf "$TMP"; trap - EXIT INT TERM # exec below skips the trap chmod +x "$DEST/install.sh" 2>/dev/null || true cd "$DEST" exec ./install.sh