-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_import.sh
More file actions
66 lines (59 loc) · 1.69 KB
/
Copy pathdb_import.sh
File metadata and controls
66 lines (59 loc) · 1.69 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
#!/usr/bin/env bash
# ==============================================================================
# Database Import Studio — Main Entry Point
# Cross-platform: Linux + macOS + Windows (Git Bash / WSL)
# Usage:
# ./db_import.sh Auto-launch UI mode (or CLI fallback)
# ./db_import.sh --ui Launch Browser UI mode
# ./db_import.sh --cli Launch Terminal CLI mode
# ==============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check arguments for explicit mode flags
MODE=""
CLI_ARGS=()
for arg in "$@"; do
case "$arg" in
--ui|--gui|--browser)
MODE="ui"
;;
--cli|--terminal|--cmd)
MODE="cli"
;;
*)
CLI_ARGS+=("$arg")
;;
esac
done
# If no explicit flag passed, prompt or default to UI mode
if [[ -z "$MODE" ]]; then
if [[ ${#CLI_ARGS[@]} -gt 0 ]]; then
# Flags passed like -d mydb -f dump.sql -> user wants CLI
MODE="cli"
else
# Interactive check or default to UI
if command -v python3 &>/dev/null || command -v python &>/dev/null; then
MODE="ui"
else
MODE="cli"
fi
fi
fi
if [[ "$MODE" == "ui" ]]; then
PYTHON_EXE=""
if command -v python3 &>/dev/null; then
PYTHON_EXE="python3"
elif command -v python &>/dev/null; then
PYTHON_EXE="python"
else
echo "Python 3 is required for UI mode. Falling back to CLI mode..."
MODE="cli"
fi
if [[ "$MODE" == "ui" ]]; then
echo "Starting Database Import Studio (Browser UI)..."
exec "$PYTHON_EXE" "$SCRIPT_DIR/db_import_server.py" 7321
fi
fi
if [[ "$MODE" == "cli" ]]; then
exec bash "$SCRIPT_DIR/db_import_cli.sh" "${CLI_ARGS[@]}"
fi