-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·312 lines (284 loc) · 13 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·312 lines (284 loc) · 13 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env bash
# =============================================================================
# Traveller World Generator — Quick Install (macOS / Linux)
# =============================================================================
# Creates a Python virtual environment, installs the GUI library (PySide6),
# and generates launcher scripts for the desktop app and command-line tools.
#
# Usage:
# bash install.sh
#
# Requirements:
# Python 3.9 or later — https://www.python.org/downloads/
# =============================================================================
set -euo pipefail
# ── Colours ───────────────────────────────────────────────────────────────────
if [ -t 1 ]; then
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; CYAN='\033[0;36m'; NC='\033[0m'
else
GREEN=''; YELLOW=''; RED=''; CYAN=''; NC=''
fi
info() { echo -e "${GREEN}[install]${NC} $*"; }
warn() { echo -e "${YELLOW}[warning]${NC} $*"; }
fail() { echo -e "${RED}[error]${NC} $*" >&2; exit 1; }
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
echo ""
echo -e "${CYAN}Traveller World Generator — Installation${NC}"
echo "========================================="
echo ""
# ── 1. Locate Python 3.9+ ─────────────────────────────────────────────────────
info "Checking Python..."
PYTHON=""
for cmd in python3 python python3.11 python3.10 python3.9; do
if command -v "$cmd" &>/dev/null; then
major=$("$cmd" -c "import sys; print(sys.version_info.major)" 2>/dev/null || echo 0)
minor=$("$cmd" -c "import sys; print(sys.version_info.minor)" 2>/dev/null || echo 0)
if [ "$major" -gt 3 ] || { [ "$major" -eq 3 ] && [ "$minor" -ge 9 ]; }; then
PYTHON="$cmd"
break
fi
fi
done
if [ -z "$PYTHON" ]; then
warn "Python 3.9 or later was not found."
OS_TYPE="$(uname -s)"
if [ "$OS_TYPE" = "Darwin" ]; then
# macOS
if command -v brew &>/dev/null; then
info "Installing Python 3.11 via Homebrew..."
brew install python@3.11 \
|| fail "Homebrew failed to install Python. Download from: https://www.python.org/downloads/"
else
fail "Python 3.9 or later is required but was not found.
Install Homebrew (https://brew.sh) first, then run: brew install python@3.11
Or download Python directly from: https://www.python.org/downloads/"
fi
elif [ "$OS_TYPE" = "Linux" ]; then
# Linux — detect package manager
if command -v apt-get &>/dev/null; then
info "Installing Python 3 via apt..."
sudo apt-get update -qq \
&& sudo apt-get install -y python3 python3-venv \
|| fail "apt failed to install Python. Try: sudo apt-get install python3 python3-venv"
elif command -v dnf &>/dev/null; then
info "Installing Python 3 via dnf..."
sudo dnf install -y python3 \
|| fail "dnf failed to install Python. Try: sudo dnf install python3"
elif command -v pacman &>/dev/null; then
info "Installing Python 3 via pacman..."
sudo pacman -Sy --noconfirm python \
|| fail "pacman failed to install Python. Try: sudo pacman -S python"
else
fail "No supported package manager found (apt, dnf, pacman).
Download Python 3.11 from: https://www.python.org/downloads/
After installing, re-run this script."
fi
else
fail "Unsupported OS: $OS_TYPE.
Download Python 3.11 from: https://www.python.org/downloads/"
fi
# Re-check after auto-install
for cmd in python3.11 python3 python; do
if command -v "$cmd" &>/dev/null; then
major=$("$cmd" -c "import sys; print(sys.version_info.major)" 2>/dev/null || echo 0)
minor=$("$cmd" -c "import sys; print(sys.version_info.minor)" 2>/dev/null || echo 0)
if [ "$major" -gt 3 ] || { [ "$major" -eq 3 ] && [ "$minor" -ge 9 ]; }; then
PYTHON="$cmd"
break
fi
fi
done
if [ -z "$PYTHON" ]; then
fail "Python was installed but cannot be found. Open a new terminal and re-run install.sh"
fi
fi
PY_VER=$("$PYTHON" -c "import sys; print('%d.%d' % sys.version_info[:2])")
info "Found Python $PY_VER ($PYTHON)"
# ── 2. Create virtual environment ─────────────────────────────────────────────
VENV_DIR="$SCRIPT_DIR/.venv"
if [ -d "$VENV_DIR" ]; then
info "Virtual environment already exists — will update packages."
else
info "Creating virtual environment in .venv/ ..."
"$PYTHON" -m venv "$VENV_DIR" || fail "Could not create virtual environment."
fi
VENV_PYTHON="$VENV_DIR/bin/python3"
# ── 3. Install dependencies ───────────────────────────────────────────────────
info "Upgrading pip..."
"$VENV_PYTHON" -m pip install --quiet --upgrade pip
info "Installing traveller-gen package (generation modules + CLI entry points)..."
"$VENV_PYTHON" -m pip install --quiet -e "$SCRIPT_DIR" \
|| fail "Failed to install traveller-gen package."
info "Installing PySide6 and PySide6-Addons (desktop GUI library) — this may take a few minutes..."
"$VENV_PYTHON" -m pip install --quiet -r "$SCRIPT_DIR/gen-ui/requirements.txt" \
|| fail "Failed to install PySide6. Check your internet connection and try again."
info "Installing dev tools (pytest, pylint)..."
"$VENV_PYTHON" -m pip install --quiet -r "$SCRIPT_DIR/requirements-dev.txt" \
|| fail "Failed to install dev tools."
info "All dependencies installed."
# ── 4. Create VS Code settings ───────────────────────────────────────────────
VSCODE_DIR="$SCRIPT_DIR/.vscode"
VSCODE_SETTINGS="$VSCODE_DIR/settings.json"
if [ ! -f "$VSCODE_SETTINGS" ]; then
info "Creating VS Code settings (.vscode/settings.json)..."
mkdir -p "$VSCODE_DIR"
cat > "$VSCODE_SETTINGS" << 'VSCODE'
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python3",
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.analysis.venvPath": "${workspaceFolder}",
"python.analysis.venv": ".venv",
"python.analysis.extraPaths": [
"${workspaceFolder}"
],
"python.analysis.typeCheckingMode": "basic",
"editor.formatOnSave": true,
"editor.rulers": [
88
],
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true,
".pytest_cache": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 2,
"pylint.path": [
"${workspaceFolder}/.venv/bin/pylint"
],
"pylint.interpreter": [
"${workspaceFolder}/.venv/bin/python3"
],
"pylint.args": [
"--disable=duplicate-code,too-many-lines"
]
}
VSCODE
else
info "VS Code settings already exist - skipping."
fi
# ── 5. Create launcher scripts ────────────────────────────────────────────────
info "Creating launcher scripts..."
# -- Desktop GUI (.command = double-clickable in Finder on macOS) -------------
cat > "$SCRIPT_DIR/run-gui.command" << 'LAUNCHER'
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
exec "$SCRIPT_DIR/.venv/bin/python3" "$SCRIPT_DIR/gen-ui/app.py"
LAUNCHER
chmod +x "$SCRIPT_DIR/run-gui.command"
# -- World generator CLI -------------------------------------------------------
cat > "$SCRIPT_DIR/run-world.sh" << 'LAUNCHER'
#!/usr/bin/env bash
# Generate one or more Traveller mainworlds.
#
# Options:
# --name NAME World name (default: auto-numbered)
# --count N Number of worlds to generate (default: 1)
# --seed N RNG seed for reproducible results
# --json Output as JSON instead of text
# --html Output as an HTML card
#
# Examples:
# bash run-world.sh
# bash run-world.sh --name "New Terra" --count 3
# bash run-world.sh --name Zhodane --seed 42 --json
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
exec "$SCRIPT_DIR/.venv/bin/traveller-world" "$@"
LAUNCHER
chmod +x "$SCRIPT_DIR/run-world.sh"
# -- TravellerMap lookup CLI ---------------------------------------------------
cat > "$SCRIPT_DIR/run-mapfetch.sh" << 'LAUNCHER'
#!/usr/bin/env bash
# Fetch a world from TravellerMap and generate a full star system.
# Requires an internet connection.
#
# Options (--sector is always required):
# --sector SECTOR Sector name, e.g. "Spinward Marches"
# --name NAME World name within the sector
# --hex NNNN 4-digit hex position (alternative to --name)
# --seed N RNG seed for reproducible results
# --detail Include secondary world and moon profiles
# --json Output as JSON
# --html Output as an HTML card
#
# Examples:
# bash run-mapfetch.sh --sector "Spinward Marches" --name Regina
# bash run-mapfetch.sh --sector "Spinward Marches" --hex 1910 --detail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
exec "$SCRIPT_DIR/.venv/bin/traveller-mapfetch" "$@"
LAUNCHER
chmod +x "$SCRIPT_DIR/run-mapfetch.sh"
# -- FastAPI server ------------------------------------------------------------
cat > "$SCRIPT_DIR/run-fastapi.sh" << 'LAUNCHER'
#!/usr/bin/env bash
# Start the Traveller World Generator FastAPI server.
#
# The server listens on http://localhost:8000 by default.
#
# Options (passed through to uvicorn):
# --host HOST Bind address (default: 127.0.0.1)
# --port PORT Port number (default: 8000)
# --reload Auto-reload on source changes (development only)
#
# Examples:
# bash run-fastapi.sh
# bash run-fastapi.sh --host 0.0.0.0 --port 8080
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR/fastapi"
exec "$SCRIPT_DIR/.venv/bin/uvicorn" app:app --host 127.0.0.1 --port 8000 "$@"
LAUNCHER
chmod +x "$SCRIPT_DIR/run-fastapi.sh"
# ── 6. Activate virtual environment ──────────────────────────────────────────
if [ "${VIRTUAL_ENV:-}" != "$VENV_DIR" ]; then
info "Activating virtual environment..."
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
else
info "Virtual environment already active."
fi
# ── 7. Done ───────────────────────────────────────────────────────────────────
echo ""
info "Installation complete!"
echo ""
echo -e "${CYAN} ┌──────────────────────────────────────────────────────────────┐${NC}"
echo -e "${CYAN} │ Desktop app │${NC}"
echo -e "${CYAN} │ macOS: double-click run-gui.command in Finder │${NC}"
echo -e "${CYAN} │ Linux: bash run-gui.command │${NC}"
echo -e "${CYAN} │ │${NC}"
echo -e "${CYAN} │ World generator (command line) │${NC}"
echo -e "${CYAN} │ bash run-world.sh [--name NAME] [--count N] │${NC}"
echo -e "${CYAN} │ │${NC}"
echo -e "${CYAN} │ TravellerMap lookup (command line, needs internet) │${NC}"
echo -e "${CYAN} │ bash run-mapfetch.sh --sector SECTOR --name NAME │${NC}"
echo -e "${CYAN} └──────────────────────────────────────────────────────────────┘${NC}"
echo ""
echo " Examples:"
echo " bash run-world.sh"
echo " bash run-world.sh --name \"New Terra\" --count 5"
echo " bash run-mapfetch.sh --sector \"Spinward Marches\" --name Regina"
echo ""
echo -e " ${YELLOW}macOS note:${NC} If Finder shows a security warning when opening"
echo " run-gui.command, right-click it and choose Open, then click Open."
echo ""
echo -e " ${YELLOW}To activate the venv in a new terminal:${NC}"
echo " source .venv/bin/activate"
echo " # or dot-source this script: . ./install.sh"
echo ""