-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·126 lines (107 loc) · 4.75 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·126 lines (107 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# Install the dependencies needed for local Synth Workshop development.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
MODE="install"
usage() {
cat <<'EOF'
Usage: ./scripts/install.sh [--bootstrap | --check | --dry-run]
(no option) Check prerequisites, create .env if absent, and run npm ci
--bootstrap Install build tools (Homebrew/Rust), then perform normal installation
--check Check prerequisites only; do not change the checkout
--dry-run Check prerequisites and print planned changes without making them
EOF
}
fail() {
printf '[install] ERROR: %s\n' "$*" >&2
exit 1
}
note() {
printf '[install] %s\n' "$*"
}
version_major() {
printf '%s' "$1" | sed -E 's/^[^0-9]*([0-9]+).*/\1/'
}
require_command() {
local command_name="$1" help_text="$2"
command -v "$command_name" >/dev/null 2>&1 || fail "Missing $command_name. $help_text"
}
require_major() {
local command_name="$1" minimum="$2" raw major
raw="$($command_name --version 2>/dev/null | head -n 1)" || fail "Could not read the $command_name version."
major="$(version_major "$raw")"
[[ "$major" =~ ^[0-9]+$ ]] || fail "Could not parse the $command_name version from: $raw"
(( major >= minimum )) || fail "$command_name $minimum+ is required; found $raw."
note "$command_name: $raw"
}
case "${1:-}" in
"") ;;
--check) MODE="check" ;;
--bootstrap) MODE="bootstrap" ;;
--dry-run) MODE="dry-run" ;;
--help|-h) usage; exit 0 ;;
*) usage >&2; fail "Unknown option: $1" ;;
esac
[[ $# -le 1 ]] || { usage >&2; fail "Expected at most one option."; }
if [[ "$MODE" == bootstrap ]]; then
bash "$ROOT/scripts/bootstrap-deps.sh"
fi
source "$ROOT/scripts/local-toolchain-env.sh"
cd "$ROOT"
[[ "$(uname -s)" == "Darwin" ]] || fail "Workshop development currently supports macOS only."
[[ "$(uname -m)" == "arm64" ]] || fail "Workshop development currently supports Apple Silicon (arm64) only."
require_command sw_vers "Install or update macOS."
macos_major="$(sw_vers -productVersion | cut -d. -f1)"
[[ "$macos_major" =~ ^[0-9]+$ ]] || fail "Could not determine the macOS version."
(( macos_major >= 14 )) || fail "macOS 14 (Sonoma) or newer is required."
note "platform: macOS $(sw_vers -productVersion) arm64"
require_command xcode-select "Install the Xcode command-line tools with: xcode-select --install"
xcode_path="$(xcode-select -p 2>/dev/null)" || fail "Xcode command-line tools are not configured. Run: xcode-select --install"
[[ -d "$xcode_path" ]] || fail "Xcode developer directory does not exist: $xcode_path"
note "Xcode command-line tools: $xcode_path"
require_command swift "Install Xcode 16 or newer (Swift 6 is required by the terminal host)."
swift_major="$(swift --version | sed -nE 's/.*Swift version ([0-9]+).*/\1/p' | head -n 1)"
[[ "$swift_major" =~ ^[0-9]+$ ]] && (( swift_major >= 6 )) || \
fail "Swift 6+ is required. Select Xcode 16+ with DEVELOPER_DIR before building."
require_command git "Install Git (included with the Xcode command-line tools)."
require_command node "Install Node.js 20 or newer."
require_command npm "Install npm 10 or newer."
require_command rustc "Install Rust from https://rustup.rs/."
require_command cargo "Install Rust from https://rustup.rs/."
require_command uv "Run ./scripts/install.sh --bootstrap to install uv and the other build tools."
require_command python3 "Install Python 3.11 or newer (required by runtime staging)."
require_command jq "Install jq (for example: brew install jq)."
require_command rg "Install ripgrep (for example: brew install ripgrep)."
require_command curl "Install the macOS command-line tools."
require_command lsof "Install the macOS command-line tools."
require_major node 20
require_major npm 10
require_major rustc 1
require_major python3 3
python3 -c 'import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)' || \
fail "Python 3.11+ must be available as python3 on PATH (runtime staging uses tomllib)."
[[ -f "$ROOT/package.json" && -f "$ROOT/package-lock.json" ]] || \
fail "Run this script from a complete Workshop checkout containing package.json and package-lock.json."
if [[ "$MODE" == "check" ]]; then
note "prerequisite check passed"
exit 0
fi
if [[ -e "$ROOT/.env" ]]; then
note "preserving existing .env"
elif [[ "$MODE" == "dry-run" ]]; then
note "would copy .env.example to .env with mode 0600"
else
[[ -f "$ROOT/.env.example" ]] || fail "Missing .env.example; cannot create local configuration."
cp "$ROOT/.env.example" "$ROOT/.env"
chmod 600 "$ROOT/.env"
note "created .env from .env.example (mode 0600)"
fi
if [[ "$MODE" == "dry-run" ]]; then
note "would run: npm ci"
note "dry run passed"
exit 0
fi
note "installing locked npm workspace dependencies"
(cd "$ROOT" && npm ci)
note "installation complete"
note "build and launch with: ./scripts/workshop.sh build-and-run"