#!/usr/bin/env bash set -euo pipefail REPO="lyleway/agy-tools" APP_NAME="Agy 管家.app" INSTALL_DIR="/Applications" MODE="release" for arg in "$@"; do case "$arg" in --build) MODE="build" ;; -h|--help) cat <<'EOF' Usage: install.sh [--build] Default Download and install Agy 管家.app to /Applications (Apple Silicon & Intel Mac) --build Build and install Agy 管家.app from source (requires pnpm & cargo-tauri) EOF exit 0 ;; *) echo "Unknown option: $arg" >&2 exit 1 ;; esac done if [[ "$(uname -s)" != "Darwin" ]]; then echo "agy-tools currently supports macOS only." >&2 exit 1 fi if ! python3 -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)'; then echo "Python 3.10 or higher is required." >&2 exit 1 fi ARCH="$(uname -m)" case "${ARCH}" in arm64) ASSET_NAME="Agy-Manager-macOS-arm64.tar.gz" ;; x86_64) ASSET_NAME="Agy-Manager-macOS-x64.tar.gz" ;; *) if [[ "${MODE}" == "release" ]]; then echo "No prebuilt binary for architecture ${ARCH}; falling back to source build..." MODE="build" fi ;; esac TMP_DIR="$(mktemp -d)" cleanup() { rm -rf "${TMP_DIR}" } trap cleanup EXIT install_app_bundle() { local src_app="$1" pkill -x "agy-manager" >/dev/null 2>&1 || true rm -rf "${INSTALL_DIR}/${APP_NAME}" ditto "${src_app}" "${INSTALL_DIR}/${APP_NAME}" xattr -cr "${INSTALL_DIR}/${APP_NAME}" >/dev/null 2>&1 || true echo "Installed ${APP_NAME} to ${INSTALL_DIR}/${APP_NAME}" } if [[ "${MODE}" == "release" ]]; then DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}" echo "Downloading ${ASSET_NAME}..." curl -fsSL "${DOWNLOAD_URL}" -o "${TMP_DIR}/${ASSET_NAME}" tar -xzf "${TMP_DIR}/${ASSET_NAME}" -C "${TMP_DIR}" install_app_bundle "${TMP_DIR}/${APP_NAME}" else SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || true)" if [[ -n "${SCRIPT_DIR}" && -f "${SCRIPT_DIR}/desktop/package.json" ]]; then SRC_DIR="${SCRIPT_DIR}" else SRC_DIR="${HOME}/.local/share/agy-tools" if [[ -d "${SRC_DIR}/.git" ]]; then git -C "${SRC_DIR}" pull --ff-only else mkdir -p "$(dirname "${SRC_DIR}")" git clone "https://github.com/${REPO}.git" "${SRC_DIR}" fi fi for tool in pnpm cargo; do if ! command -v "${tool}" >/dev/null 2>&1; then echo "${tool} is required for --build." >&2 exit 1 fi done if ! cargo tauri --version >/dev/null 2>&1; then echo "cargo-tauri is required. Install with: cargo install tauri-cli" >&2 exit 1 fi (cd "${SRC_DIR}/desktop" && pnpm install --frozen-lockfile && cargo tauri build --bundles app) install_app_bundle "${SRC_DIR}/desktop/src-tauri/target/release/bundle/macos/${APP_NAME}" fi echo "Done! Launch from Applications or run: open \"${INSTALL_DIR}/${APP_NAME}\""