-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·301 lines (255 loc) · 8.14 KB
/
install
File metadata and controls
executable file
·301 lines (255 loc) · 8.14 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
#!/usr/bin/env bash
set -e
GITHUB_REPO="philogicae/fast_dev_container"
INSTALL_DIR="${HOME}/.fdevc"
REPO_URL="https://github.com/${GITHUB_REPO}.git"
# Colors and styling
RESET="\033[0m"
BOLD="\033[1m"
DIM="\033[2m"
BLUE="\033[94m"
CYAN="\033[96m"
GREEN="\033[92m"
YELLOW="\033[93m"
RED="\033[91m"
MAGENTA="\033[95m"
# Icons
ICON_ARROW="→"
ICON_CHECK="✓"
ICON_CROSS="✗"
ICON_ROCKET="🚀"
ICON_PACKAGE="📦"
ICON_SPARKLES="✨"
ICON_TOOL="🛠️"
log_step() {
echo -e "${BOLD}${CYAN}${ICON_ARROW} $1${RESET}"
}
log_success() {
echo -e "${BOLD}${GREEN}${ICON_CHECK} $1${RESET}"
}
log_error() {
echo -e "${BOLD}${RED}${ICON_CROSS} $1${RESET}" >&2
}
log_warning() {
echo -e "${BOLD}${YELLOW}⚠ $1${RESET}"
}
log_detail() {
echo -e " ${DIM}$1${RESET}"
}
log_highlight() {
echo -e "${BOLD}${BLUE}$1${RESET}"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
print_banner() {
echo -e "${BOLD}${CYAN}"
cat <<'EOF'
______ __ ____ ______ __ _
/ ____/___ ______/ /_ / __ \___ _ __ / ____/___ ____ / /_____ _(_)___ ___ _____
/ /_ / __ `/ ___/ __/ / / / / _ \ | / / / / / __ \/ __ \/ __/ __ `/ / __ \/ _ \/ ___/
/ __/ / /_/ (__ ) /_ / /_/ / __/ |/ / / /___/ /_/ / / / / /_/ /_/ / / / / / __/ /
/_/ \__,_/____/\__/ /_____/\___/|___/ \____/\____/_/ /_/\__/\__,_/_/_/ /_/\___/_/
EOF
echo -e "${RESET}"
echo -e "${BOLD}${MAGENTA}Lightweight CLI for Dev Environments${RESET}"
echo ""
}
check_dependency() {
local cmd="$1"
local name="$2"
local version_flag="${3:---version}"
if command_exists "$cmd"; then
local version
version=$(${cmd} "${version_flag}" 2>&1 | head -n1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 || echo "unknown")
log_success "${name} found ${DIM}(v${version})${RESET}"
return 0
else
log_error "${name} not found"
return 1
fi
}
check_dependencies() {
log_step "Checking dependencies"
local all_ok=true
if ! check_dependency git "Git"; then
all_ok=false
log_detail "Install: https://git-scm.com/install"
fi
if ! check_dependency python3 "Python 3" "--version"; then
all_ok=false
log_detail "Install: https://python.org/downloads"
fi
# Check for container runtime
if command_exists docker; then
check_dependency docker "Docker" "--version"
elif command_exists podman; then
check_dependency podman "Podman" "--version"
else
log_error "Docker or Podman not found"
log_detail "Install Docker: https://docs.docker.com/get-docker/"
log_detail "Or Podman: https://podman.io/getting-started/installation"
all_ok=false
fi
if [[ "${all_ok}" == false ]]; then
log_error "Missing required dependencies"
log_detail "Please install them before continuing."
exit 1
fi
log_success "All dependencies satisfied"
}
detect_shell_configs() {
local configs=()
add_config() {
local path="$1"
local shell_name="$2"
for existing in "${configs[@]}"; do
if [[ "${existing}" == "${path}" ]]; then
return
fi
done
configs+=("${path}")
if [[ -e "${path}" ]]; then
log_success "Detected ${shell_name} shell" >&2
log_detail "Config: ${path}" >&2
else
log_success "Detected ${shell_name} shell" >&2
log_detail "Config: ${path} (will be created)" >&2
fi
}
# zsh detection
if [[ -n "${ZSH_VERSION}" ]] || [[ "${SHELL}" == *"zsh"* ]] || command_exists zsh || [[ -f "${HOME}/.zshrc" ]]; then
add_config "${HOME}/.zshrc" "zsh"
fi
# bash detection
if [[ -n "${BASH_VERSION}" ]] || [[ "${SHELL}" == *"bash"* ]] || command_exists bash || [[ -f "${HOME}/.bashrc" ]] || [[ -f "${HOME}/.bash_profile" ]]; then
add_config "${HOME}/.bashrc" "bash"
if [[ -f "${HOME}/.bash_profile" ]]; then
add_config "${HOME}/.bash_profile" "bash"
fi
fi
if ((${#configs[@]} == 0)); then
log_warning "Could not detect any shell configuration files" >&2
log_detail "Expected: ~/.bashrc, ~/.bash_profile, or ~/.zshrc" >&2
return
fi
printf '%s\n' "${configs[@]}"
}
spinner() {
local pid=$1
local delay=0.1
local spinstr='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
while ps -p "$pid" >/dev/null 2>&1; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
install_fdevc() {
print_banner
# Step 1: Check dependencies
check_dependencies
# Step 2: Install or update
log_step "Installing Fast Dev Container"
if [[ -d "${INSTALL_DIR}" ]]; then
log_highlight "${ICON_PACKAGE} Existing installation detected"
log_detail "Location: ${INSTALL_DIR}"
log_step "Updating to latest version"
cd "${INSTALL_DIR}" || {
log_error "Failed to access ${INSTALL_DIR}"
exit 1
}
if git pull origin main --quiet 2>&1; then
local latest_commit
latest_commit=$(git log -1 --pretty=format:'%h - %s' 2>/dev/null || echo "unknown")
log_success "Repository updated"
log_detail "Latest: ${latest_commit}"
else
log_error "Failed to update repository"
log_warning "Try removing ${INSTALL_DIR} and reinstalling"
log_detail "Command: rm -rf ${INSTALL_DIR}"
exit 1
fi
else
log_highlight "${ICON_PACKAGE} Installing to ${INSTALL_DIR}"
if git clone --quiet "${REPO_URL}" "${INSTALL_DIR}" 2>&1; then
log_success "Repository cloned successfully"
local file_count
file_count=$(find "${INSTALL_DIR}" -type f | wc -l)
log_detail "Files installed: ${file_count}"
else
log_error "Failed to clone repository"
log_detail "Repository: ${REPO_URL}"
exit 1
fi
fi
# Step 3: Configure shell
log_step "Configuring shell integration"
mapfile -t shell_configs < <(detect_shell_configs)
if ((${#shell_configs[@]} == 0)); then
log_warning "Manual setup required"
log_detail "Add these lines to your shell config (.bashrc or .zshrc):"
echo -e " ${BOLD}${GREEN}export FDEVC=\"$HOME/.fdevc/fdevc.sh\"${RESET}"
echo -e " ${BOLD}${GREEN}source $FDEVC${RESET}"
exit 0
fi
for shell_config in "${shell_configs[@]}"; do
if [[ ! -e "${shell_config}" ]]; then
log_step "Preparing ${shell_config}"
local shell_config_dir
shell_config_dir=$(dirname "${shell_config}")
if [[ ! -d "${shell_config_dir}" ]]; then
if mkdir -p "${shell_config_dir}" 2>/dev/null; then
log_detail "Created directory: ${shell_config_dir}"
else
log_error "Unable to create directory ${shell_config_dir}"
log_detail "Create it manually and rerun the installer."
exit 1
fi
fi
if touch "${shell_config}" 2>/dev/null; then
log_success "Created ${shell_config}"
else
log_error "Unable to create ${shell_config}"
log_detail "Add 'export FDEVC=\"$HOME/.fdevc/fdevc.sh\"; source $FDEVC' to your shell config manually."
exit 1
fi
fi
# shellcheck disable=SC2016
if grep -qF 'FDEVC' "${shell_config}" 2>/dev/null; then
log_highlight "${ICON_CHECK} Already configured: ${shell_config}"
else
log_step "Adding to ${shell_config}"
cat <<'EOF' >>"${shell_config}"
# Fast Dev Container
export FDEVC="$HOME/.fdevc/fdevc.sh"
source $FDEVC
EOF
log_success "Added to ${shell_config}"
fi
done
# Step 4: Load commands when possible
if [[ -t 0 ]]; then
log_step "Loading fdevc for this session"
export FDEVC="${INSTALL_DIR}/fdevc.sh"
# shellcheck disable=SC1090
if source "${FDEVC}" 2>/dev/null; then
log_success "fdevc command is ready"
else
echo ""
log_warning "Could not auto-load fdevc, run:"
log_highlight "${BOLD}${RED}source $HOME/.fdevc/fdevc.sh${RESET}"
fi
fi
echo -e "${BOLD}${GREEN}\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
echo -e "${BOLD}${GREEN}${ICON_SPARKLES} Installation Complete! ${ICON_SPARKLES}${RESET}\n"
echo -e "${BOLD}${CYAN}${ICON_SPARKLES} Docs: ${RESET}https://github.com/${GITHUB_REPO}"
echo -e "${BOLD}${CYAN}${ICON_ROCKET} Quick Start: ${RESET}fdevc -h"
echo -e "${BOLD}${CYAN}${ICON_TOOL} If missing, run: ${RESET}source ${FDEVC}"
echo -e "${BOLD}${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n"
}
# Run installation
install_fdevc