#!/bin/bash # Pommedoro Installer # Double-click this file to install Pommedoro to /Applications set -euo pipefail APP_NAME="Pommedoro" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" APP_SRC="${SCRIPT_DIR}/${APP_NAME}.app" APP_DST="/Applications/${APP_NAME}.app" REMOTE_SHA_URL="https://git.nixc.us/colin/pommedoro/raw/branch/main/releases/Pommedoro.dmg.sha256" echo "" echo " Installing ${APP_NAME}..." echo "" if [ ! -d "${APP_SRC}" ]; then echo " ERROR: ${APP_NAME}.app not found next to this installer." echo " Make sure the DMG is mounted and try again." echo "" read -n 1 -s -r -p " Press any key to close..." exit 1 fi # Stop running instance if any pkill -9 -f "${APP_NAME}" 2>/dev/null || true sleep 0.3 # Copy to /Applications rm -rf "${APP_DST}" cp -R "${APP_SRC}" "${APP_DST}" # Strip quarantine attribute (fixes "app is damaged" on downloaded DMGs) xattr -cr "${APP_DST}" # Stamp state (SHA + timestamp) for auto-updater via HTTPS, no login SHA_DIR="${HOME}/Library/Application Support/Pommedoro" mkdir -p "${SHA_DIR}" OUR_SHA="" DMG_DEVICE="$(hdiutil info 2>/dev/null | grep -B 20 "${SCRIPT_DIR}" | grep 'image-path' | awk -F' : ' '{print $2}' | head -1)" if [ -n "${DMG_DEVICE}" ] && [ -f "${DMG_DEVICE}" ]; then OUR_SHA="$(shasum -a 256 "${DMG_DEVICE}" | awk '{print $1}')" fi REMOTE_SHA="" REMOTE_TS="0" if [ -n "${OUR_SHA}" ]; then REMOTE_SHA="$(curl -sL "${REMOTE_SHA_URL}" 2>/dev/null | head -1 | tr -d '\r')" LAST_MOD="$(curl -sIL "${REMOTE_SHA_URL}" 2>/dev/null | grep -i '^Last-Modified:' | head -1 | sed 's/^Last-Modified: *//' | tr -d '\r')" if [ -n "${LAST_MOD}" ]; then REMOTE_TS="$(date -j -f "%a, %d %b %Y %H:%M:%S %Z" "${LAST_MOD}" "+%s" 2>/dev/null || echo "0")" fi # If this DMG matches remote, use remote timestamp; else use 0 so app may prompt later if [ "${OUR_SHA}" = "${REMOTE_SHA}" ] && [ -n "${REMOTE_SHA}" ]; then printf "%s\n%s\n" "${OUR_SHA}" "${REMOTE_TS}" > "${SHA_DIR}/current.sha256" else printf "%s\n0\n" "${OUR_SHA}" > "${SHA_DIR}/current.sha256" fi echo " SHA256 stamped for auto-update." fi echo " Installed to ${APP_DST}" echo " Launching ${APP_NAME}..." echo "" open "${APP_DST}" echo " Done!" echo ""