-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.sh
More file actions
114 lines (106 loc) · 4.31 KB
/
launch.sh
File metadata and controls
114 lines (106 loc) · 4.31 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
#!/usr/bin/env bash
# Author: Nima Shafie
# =============================================================================
# launch.sh -- airgap-cpp-devkit primary entry point
#
# Preferred way to install and manage devkit tools.
# Finds Python 3.8+, launches the DevKit Manager web UI, and opens the browser.
# Falls back to the interactive CLI installer (install-cli.sh) if Python is absent.
#
# USAGE:
# bash launch.sh # auto-detect; launch UI or CLI fallback
# bash launch.sh --port 9090 # custom port for the web UI
# bash launch.sh --host 0.0.0.0 # bind to all interfaces (LAN access)
# bash launch.sh --no-browser # start server but don't open browser
# bash launch.sh --cli # skip UI, run install-cli.sh directly
#
# WHAT HAPPENS:
# 1. Script searches for Python 3.8+ (python3 / python).
# 2. If found -> launches dev-tools/devkit-ui/devkit.py and opens
# http://127.0.0.1:8080 (or --port value).
# From there: pick a profile or install tools individually.
# 3. If not found -> falls back to bash install-cli.sh (interactive CLI wizard).
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEVKIT_UI="${SCRIPT_DIR}/dev-tools/devkit-ui/devkit.py"
INSTALL_SH="${SCRIPT_DIR}/install-cli.sh"
# ---------------------------------------------------------------------------
# Plain ASCII display helpers (match install-cli.sh style)
# ---------------------------------------------------------------------------
_sep2() { printf '%s\n' "================================================================================"; }
# ---------------------------------------------------------------------------
# Parse flags: consume --cli; pass everything else through to devkit.py
# ---------------------------------------------------------------------------
FORCE_CLI=false
UI_ARGS=()
UI_PORT=8080
UI_HOST="127.0.0.1"
while [[ $# -gt 0 ]]; do
case "$1" in
--cli) FORCE_CLI=true; shift ;;
--port) UI_PORT="$2"; UI_ARGS+=("$1" "$2"); shift 2 ;;
--host) UI_HOST="$2"; UI_ARGS+=("$1" "$2"); shift 2 ;;
*) UI_ARGS+=("$1"); shift ;;
esac
done
# ---------------------------------------------------------------------------
# --cli: skip Python detection, go straight to install-cli.sh
# ---------------------------------------------------------------------------
if [[ "${FORCE_CLI}" == "true" ]]; then
echo ""
_sep2
echo " airgap-cpp-devkit -- CLI Installer"
_sep2
echo ""
echo " [--cli] Skipping DevKit Manager. Launching install-cli.sh..."
echo ""
exec bash "${INSTALL_SH}" "${UI_ARGS[@]+"${UI_ARGS[@]}"}"
fi
# ---------------------------------------------------------------------------
# Find Python 3.8+
# ---------------------------------------------------------------------------
_find_python() {
local candidates=(python3 python python3.13 python3.12 python3.11 python3.10 python3.9 python3.8)
for py in "${candidates[@]}"; do
if command -v "${py}" &>/dev/null; then
local ok
ok="$("${py}" -c 'import sys; print(sys.version_info >= (3,8))' 2>/dev/null || echo "False")"
if [[ "${ok}" == "True" ]]; then
echo "${py}"
return 0
fi
fi
done
return 1
}
echo ""
_sep2
echo " airgap-cpp-devkit -- Launcher"
_sep2
echo ""
echo " Checking for Python 3.8+..."
PYTHON_BIN=""
if PYTHON_BIN="$(_find_python 2>/dev/null)"; then
PY_VER="$(${PYTHON_BIN} --version 2>&1 | awk '{print $2}')"
echo " [OK] Python ${PY_VER} found (${PYTHON_BIN})"
echo ""
echo " Starting DevKit Manager..."
echo " Open your browser at http://${UI_HOST}:${UI_PORT} if it does not open automatically."
echo " Press Ctrl+C to stop the server."
echo ""
_sep2
echo ""
exec "${PYTHON_BIN}" "${DEVKIT_UI}" "${UI_ARGS[@]+"${UI_ARGS[@]}"}"
else
echo " [!!] Python 3.8+ not found on PATH."
echo ""
echo " The DevKit Manager (web UI) requires Python 3.8+."
echo ""
echo " Falling back to the interactive CLI installer..."
echo ""
printf " Press Enter to continue with install-cli.sh, or Ctrl+C to cancel..."
read -r
echo ""
exec bash "${INSTALL_SH}"
fi