|
| 1 | +#!/bin/bash |
| 2 | +# Install.command — v1.1.1 |
| 3 | +# Double-clickable launcher for macOS (Finder). |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 7 | +cd "$SCRIPT_DIR" |
| 8 | + |
| 9 | +chmod +x ./one-shot-migrate.sh 2>/dev/null || true |
| 10 | + |
| 11 | +has_osascript=0 |
| 12 | +command -v osascript >/dev/null 2>&1 && has_osascript=1 |
| 13 | + |
| 14 | +choose_preset() { |
| 15 | + if [[ "$has_osascript" == "1" ]]; then |
| 16 | + osascript <<'OSA' |
| 17 | +set choices to {"Keep current exclude.txt","minimal (Library + macOS metadata)","developer-heavy (skip caches)","media-keeper (keep project deps)"} |
| 18 | +set c to choose from list choices with prompt "Pick an exclusion preset (you can edit later):" default items {"Keep current exclude.txt"} |
| 19 | +if c is false then return "KEEP" |
| 20 | +set v to item 1 of c |
| 21 | +if v is "Keep current exclude.txt" then return "KEEP" |
| 22 | +if v is "minimal (Library + macOS metadata)" then return "minimal.txt" |
| 23 | +if v is "developer-heavy (skip caches)" then return "developer-heavy.txt" |
| 24 | +if v is "media-keeper (keep project deps)" then return "media-keeper.txt" |
| 25 | +return "KEEP" |
| 26 | +OSA |
| 27 | + else |
| 28 | + echo "Pick an exclusion preset:" |
| 29 | + echo " 1) Keep current exclude.txt" |
| 30 | + echo " 2) minimal" |
| 31 | + echo " 3) developer-heavy" |
| 32 | + echo " 4) media-keeper" |
| 33 | + read -r -p "Choose [1-4]: " n |
| 34 | + case "${n:-1}" in |
| 35 | + 2) echo "minimal.txt" ;; |
| 36 | + 3) echo "developer-heavy.txt" ;; |
| 37 | + 4) echo "media-keeper.txt" ;; |
| 38 | + *) echo "KEEP" ;; |
| 39 | + esac |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +ask_yesno() { |
| 44 | + local prompt="$1" |
| 45 | + local default="$2" |
| 46 | + if [[ "$has_osascript" == "1" ]]; then |
| 47 | + osascript <<OSA |
| 48 | +display dialog "$prompt" buttons {"No","Yes"} default button "$default" |
| 49 | +button returned of result |
| 50 | +OSA |
| 51 | + else |
| 52 | + read -r -p "$prompt (y/N): " yn |
| 53 | + [[ "$yn" =~ ^[Yy]$ ]] && echo "Yes" || echo "No" |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +ask_mode() { |
| 58 | + if [[ "$has_osascript" == "1" ]]; then |
| 59 | + osascript <<'OSA' |
| 60 | +set choices to {"DRYRUN","RUN"} |
| 61 | +set c to choose from list choices with prompt "Choose run mode:" default items {"DRYRUN"} |
| 62 | +if c is false then return "DRYRUN" |
| 63 | +return item 1 of c |
| 64 | +OSA |
| 65 | + else |
| 66 | + echo "Choose run mode:" |
| 67 | + echo " 1) DRYRUN (preview only)" |
| 68 | + echo " 2) RUN (real copy)" |
| 69 | + read -r -p "Choose [1-2]: " n |
| 70 | + [[ "${n:-1}" == "2" ]] && echo "RUN" || echo "DRYRUN" |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +preset="$(choose_preset)" |
| 75 | +if [[ "$preset" != "KEEP" ]]; then |
| 76 | + cp -f "./presets/$preset" ./exclude.txt |
| 77 | +fi |
| 78 | + |
| 79 | +edit="$(ask_yesno "Do you want to edit exclude.txt now?" "Yes")" |
| 80 | +if [[ "$edit" == "Yes" ]]; then |
| 81 | + open -t ./exclude.txt || true |
| 82 | +fi |
| 83 | + |
| 84 | +mode="$(ask_mode)" |
| 85 | +verify="$(ask_yesno "Enable checksum verification after copy?" "Yes")" |
| 86 | +bg="$(ask_yesno "Run in background (recommended for many files)?" "Yes")" |
| 87 | + |
| 88 | +export DRYRUN=0 |
| 89 | +export VERIFY=1 |
| 90 | +[[ "$mode" == "DRYRUN" ]] && export DRYRUN=1 |
| 91 | +[[ "$verify" == "No" ]] && export VERIFY=0 |
| 92 | + |
| 93 | +echo "" |
| 94 | +echo "Mode: DRYRUN=$DRYRUN VERIFY=$VERIFY" |
| 95 | +echo "" |
| 96 | + |
| 97 | +if [[ "$bg" == "Yes" && "$DRYRUN" == "0" ]]; then |
| 98 | + mkdir -p "$HOME/migration_logs" |
| 99 | + nohup ./one-shot-migrate.sh > "$HOME/migration_logs/one_shot_run.out" 2>&1 & |
| 100 | + msg="Migration started in background.\n\nLog: ~/migration_logs/one_shot_run.out\n\nFollow: tail -f ~/migration_logs/one_shot_run.out" |
| 101 | + echo "$msg" |
| 102 | + [[ "$has_osascript" == "1" ]] && osascript -e "display dialog \"$msg\" buttons {\"OK\"} default button \"OK\"" |
| 103 | + exit 0 |
| 104 | +fi |
| 105 | + |
| 106 | +./one-shot-migrate.sh |
0 commit comments