-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
129 lines (109 loc) · 2.88 KB
/
setup.sh
File metadata and controls
129 lines (109 loc) · 2.88 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
#!/usr/bin/env bash
set -euo pipefail
# Trap for clean exit on interrupt
trap 'echo ""; echo "Setup interrupted."; exit 130' INT TERM
SCRIPT_DIR=""
LIB_DIR=""
REMOTE_LIB_DIR=""
RC_FILE=""
REQUIRED_MODULES=(
"constants.sh"
"dependency_policy.sh"
"ui.sh"
"platform.sh"
"taildrive_templates.sh"
"rc_blocks.sh"
"managed_blocks.sh"
"package_manager.sh"
"tailscale_macos.sh"
"packages.sh"
"update.sh"
"install.sh"
"uninstall.sh"
"cli.sh"
)
resolve_script_dir() {
local source="${BASH_SOURCE[0]:-}"
local source_dir
local resolved_dir
if [[ -z "$source" ]]; then
echo ""
return 0
fi
while [[ -h "$source" ]]; do
source_dir="$(cd -P "$(dirname "$source")" >/dev/null 2>&1 && pwd)"
source="$(readlink "$source")"
[[ "$source" != /* ]] && source="$source_dir/$source"
done
if resolved_dir="$(cd -P "$(dirname "$source")" >/dev/null 2>&1 && pwd)"; then
:
else
resolved_dir=""
fi
echo "$resolved_dir"
}
cleanup_remote_lib_dir() {
if [[ -n "$REMOTE_LIB_DIR" && -d "$REMOTE_LIB_DIR" ]]; then
rm -rf "$REMOTE_LIB_DIR"
fi
}
load_module_from_local() {
local module_name="${1:?missing module name}"
local module_path="$LIB_DIR/$module_name"
if [[ ! -f "$module_path" ]]; then
echo "Error: Required module missing: $module_path" >&2
exit 1
fi
# shellcheck disable=SC1090
source "$module_path"
}
fetch_remote_modules() {
local raw_base="${TAILMUX_RAW_BASE:-https://raw.githubusercontent.com/ddv1982/tailmux/main}"
local module_name
local module_url
local module_path
if ! command -v curl >/dev/null 2>&1; then
echo "Error: curl is required to fetch setup modules when running from a remote setup.sh." >&2
exit 1
fi
REMOTE_LIB_DIR="$(mktemp -d)"
trap 'cleanup_remote_lib_dir' EXIT
for module_name in "${REQUIRED_MODULES[@]}"; do
module_url="$raw_base/scripts/lib/$module_name"
module_path="$REMOTE_LIB_DIR/$module_name"
if ! curl -fsSL "$module_url" -o "$module_path"; then
echo "Error: Failed to download required module: $module_url" >&2
exit 1
fi
done
LIB_DIR="$REMOTE_LIB_DIR"
}
load_modules() {
local module_name
if [[ "${TAILMUX_USE_LOCAL_MODULES:-0}" == "1" ]]; then
if [[ ! -d "$LIB_DIR" ]]; then
echo "Error: TAILMUX_USE_LOCAL_MODULES=1 but local module directory was not found: $LIB_DIR" >&2
exit 1
fi
for module_name in "${REQUIRED_MODULES[@]}"; do
load_module_from_local "$module_name"
done
return 0
fi
# Default behavior: fetch latest module set from raw GitHub main.
fetch_remote_modules
for module_name in "${REQUIRED_MODULES[@]}"; do
# shellcheck disable=SC1090
source "$LIB_DIR/$module_name"
done
}
SCRIPT_DIR="$(resolve_script_dir)"
if [[ -n "$SCRIPT_DIR" ]]; then
LIB_DIR="$SCRIPT_DIR/scripts/lib"
else
LIB_DIR=""
fi
load_modules
# shellcheck disable=SC2034
RC_FILE="$(detect_shell_rc)"
main "${1:-}"