-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·183 lines (152 loc) · 4.56 KB
/
install.sh
File metadata and controls
executable file
·183 lines (152 loc) · 4.56 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
#!/usr/bin/env bash
#
# BugTraceAI one-liner bootstrap installer
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/BugTraceAI/BugTraceAI-Launcher/main/install.sh | bash
#
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
REPO_URL="https://github.com/BugTraceAI/BugTraceAI-Launcher.git"
info() { echo -e "${CYAN}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
is_macos() {
local kernel
kernel="$(uname -s 2>/dev/null || true)"
[[ "$kernel" == "Darwin" ]] && return 0
command -v sw_vers >/dev/null 2>&1
}
IS_MACOS=false
if is_macos; then
IS_MACOS=true
fi
TARGET_USER="${SUDO_USER:-$USER}"
# Resolve home directory safely (no eval)
if command -v getent >/dev/null 2>&1; then
TARGET_HOME="$(getent passwd "$TARGET_USER" | cut -d: -f6)"
elif $IS_MACOS && command -v dscl >/dev/null 2>&1; then
TARGET_HOME="$(dscl . -read "/Users/$TARGET_USER" NFSHomeDirectory 2>/dev/null | awk '{print $2}')"
fi
TARGET_HOME="${TARGET_HOME:-$HOME}"
LAUNCHER_DIR="${BUGTRACEAI_LAUNCHER_DIR:-$TARGET_HOME/bugtraceai-launcher}"
if [[ "$IS_MACOS" == true && $EUID -eq 0 ]]; then
error "On macOS, do not run this installer with sudo/root. Run as your normal user."
exit 1
fi
run_privileged() {
if [[ $EUID -eq 0 ]]; then
"$@"
else
sudo "$@"
fi
}
run_as_target() {
if [[ $EUID -eq 0 ]] && [[ -n "${SUDO_USER:-}" ]]; then
sudo -u "$TARGET_USER" "$@"
else
"$@"
fi
}
detect_brew() {
if command -v brew >/dev/null 2>&1; then
command -v brew
return 0
fi
if [[ -x /opt/homebrew/bin/brew ]]; then
echo "/opt/homebrew/bin/brew"
return 0
fi
if [[ -x /usr/local/bin/brew ]]; then
echo "/usr/local/bin/brew"
return 0
fi
return 1
}
ensure_homebrew() {
local brew_bin
if brew_bin="$(detect_brew)"; then
echo "$brew_bin"
return 0
fi
warn "Homebrew is required to auto-install dependencies on macOS."
read -rp "$(echo -e "${YELLOW}Install Homebrew now? [Y/n]: ${NC}")" confirm
if [[ "${confirm:-}" =~ ^[Nn]$ ]]; then
return 1
fi
run_as_target env NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew_bin="$(detect_brew)" || return 1
echo "$brew_bin"
}
ensure_basic_tools() {
local missing=()
local cmd
for cmd in git curl; do
if ! command -v "$cmd" >/dev/null 2>&1; then
missing+=("$cmd")
fi
done
if [[ ${#missing[@]} -eq 0 ]]; then
return 0
fi
warn "Missing required tools: ${missing[*]}"
if $IS_MACOS; then
local brew_bin
brew_bin="$(ensure_homebrew)" || {
error "Cannot continue without: ${missing[*]}"
return 1
}
info "Installing tools with Homebrew..."
run_as_target "$brew_bin" install "${missing[@]}"
return 0
fi
if command -v apt-get >/dev/null 2>&1; then
info "Installing tools with apt-get..."
run_privileged apt-get update -qq
run_privileged apt-get install -y "${missing[@]}"
return 0
fi
error "Please install manually: ${missing[*]}"
return 1
}
install_or_update_launcher() {
if [[ -d "$LAUNCHER_DIR/.git" ]]; then
info "Launcher already exists at $LAUNCHER_DIR, updating..."
run_as_target git -C "$LAUNCHER_DIR" pull --ff-only --quiet || warn "Could not fast-forward update launcher repo."
return 0
fi
info "Cloning BugTraceAI Launcher into $LAUNCHER_DIR..."
run_as_target mkdir -p "$(dirname "$LAUNCHER_DIR")"
run_as_target git clone --depth 1 "$REPO_URL" "$LAUNCHER_DIR"
}
fix_permissions_if_needed() {
if [[ $EUID -eq 0 ]] && [[ -n "${SUDO_USER:-}" ]]; then
chown -R "$TARGET_USER" "$LAUNCHER_DIR"
fi
}
launch_wizard() {
chmod +x "$LAUNCHER_DIR/launcher.sh"
info "Starting BugTraceAI setup wizard..."
if [[ $EUID -eq 0 ]] && [[ -n "${SUDO_USER:-}" ]]; then
exec sudo -u "$TARGET_USER" "$LAUNCHER_DIR/launcher.sh"
fi
exec "$LAUNCHER_DIR/launcher.sh"
}
echo ""
echo -e "${CYAN}${BOLD}BugTraceAI Bootstrap Installer${NC}"
echo ""
ensure_basic_tools
install_or_update_launcher
fix_permissions_if_needed
echo ""
success "Launcher is ready at: $LAUNCHER_DIR"
echo -e " ${DIM}The launcher will handle Docker/Colima runtime setup and dependency checks.${NC}"
echo ""
launch_wizard