Repository navigation
Expand file tree
/
Copy pathinstall.command
More file actions
executable file
·415 lines (356 loc) · 16.1 KB
/
Copy pathinstall.command
File metadata and controls
executable file
·415 lines (356 loc) · 16.1 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/bin/bash
# ==============================================================================
#
# ███████╗██████╗ ███████╗███████╗███╗ ███╗███████╗
# ██╔════╝██╔══██╗██╔════╝██╔════╝████╗ ████║██╔════╝
# █████╗ ██████╔╝█████╗ █████╗ ██╔████╔██║█████╗
# ██╔══╝ ██╔══██╗██╔══╝ ██╔══╝ ██║╚██╔╝██║██╔══╝
# ██║ ██║ ██║███████╗███████╗██║ ╚═╝ ██║███████╗
# ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚══════╝
#
# AUTOMATIC INSTALLER v1.9.0
# NAS Freebox → Google Drive Backup
# by Andre Preda (@andre_uxui)
#
# ==============================================================================
# Exit on error
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
GRAY='\033[0;90m'
NC='\033[0m'
# Paths
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_DIR="$HOME/Freeme"
# ==============================================================================
# DETECT LANGUAGE
# ==============================================================================
SYS_LANG=$(defaults read -g AppleLocale 2>/dev/null | cut -d'_' -f1)
if [[ "$SYS_LANG" == "fr" ]]; then
L_INSTALLER="Installateur"
L_WELCOME="Bienvenue ! L'installateur va tout configurer automatiquement."
L_DURATION="Cela prend environ 2-3 minutes."
L_START="Appuyez sur ENTRÉE pour commencer, ou Ctrl+C pour annuler..."
L_STEP1="Étape 1/6 : Installation des fichiers Freeme"
L_COPYING="Copie des fichiers vers ~/Freeme..."
L_FILES_INSTALLED="Fichiers Freeme installés"
L_STEP2="Étape 2/6 : Vérification de Homebrew"
L_HOMEBREW_OK="Homebrew déjà installé"
L_HOMEBREW_INSTALL="Homebrew requis (installation automatique désactivée pour sécurité)."
L_HOMEBREW_DONE="Homebrew installé"
L_HOMEBREW_MANUAL="Installez Homebrew manuellement : https://brew.sh/"
L_STEP3="Étape 3/6 : Installation de fswatch"
L_FSWATCH_OK="fswatch déjà installé"
L_FSWATCH_INSTALL="Installation de fswatch..."
L_FSWATCH_DONE="fswatch installé"
L_STEP4="Étape 4/6 : Installation de rclone"
L_RCLONE_OK="rclone déjà installé"
L_RCLONE_INSTALL="Installation de rclone..."
L_RCLONE_DONE="rclone installé"
L_STEP5="Étape 5/6 : Connexion Google Drive"
L_GDRIVE_OK="Google Drive déjà connecté"
L_GDRIVE_BROWSER="Une fenêtre de navigateur va s'ouvrir pour l'authentification Google."
L_GDRIVE_ALLOW="Connectez-vous et cliquez 'Autoriser' pour donner l'accès."
L_GDRIVE_ENTER="Appuyez sur ENTRÉE pour ouvrir l'authentification Google..."
L_GDRIVE_OPENING="Ouverture de l'authentification Google..."
L_GDRIVE_SUCCESS="Google Drive connecté avec succès"
L_GDRIVE_FAIL="La configuration de Google Drive a peut-être échoué"
L_GDRIVE_LATER="Vous pouvez le configurer plus tard avec : rclone config"
L_STEP6="Étape 6/6 : Configuration de Freeme"
L_FREEME_CONFIG="Freeme configuré"
L_AUTOSTART="Démarrage automatique configuré"
L_APP_INSTALLED="Freeme ajouté aux Applications"
L_COMPLETE="Installation terminée !"
L_STATUS="État :"
L_GDRIVE_CONNECTED="Google Drive connecté"
L_GDRIVE_NOT="Google Drive non configuré"
L_NAS_CONNECTED="NAS Freebox connecté"
L_NAS_NOT="NAS Freebox non connecté"
L_OPENING_GUIDE="Ouverture du guide de configuration NAS..."
L_OPENING_DOCS="Ouverture de la documentation..."
L_ALL_READY="Tout est configuré ! Démarrage de Freeme..."
L_CLOSE="Appuyez sur ENTRÉE pour fermer..."
else
L_INSTALLER="Installer"
L_WELCOME="Welcome! This installer will set up everything automatically."
L_DURATION="It takes about 2-3 minutes."
L_START="Press ENTER to start, or Ctrl+C to cancel..."
L_STEP1="Step 1/6: Installing Freeme files"
L_COPYING="Copying files to ~/Freeme..."
L_FILES_INSTALLED="Freeme files installed"
L_STEP2="Step 2/6: Checking Homebrew"
L_HOMEBREW_OK="Homebrew already installed"
L_HOMEBREW_INSTALL="Homebrew is required (auto-install disabled for security)."
L_HOMEBREW_DONE="Homebrew installed"
L_HOMEBREW_MANUAL="Install Homebrew manually: https://brew.sh/"
L_STEP3="Step 3/6: Installing fswatch"
L_FSWATCH_OK="fswatch already installed"
L_FSWATCH_INSTALL="Installing fswatch..."
L_FSWATCH_DONE="fswatch installed"
L_STEP4="Step 4/6: Installing rclone"
L_RCLONE_OK="rclone already installed"
L_RCLONE_INSTALL="Installing rclone..."
L_RCLONE_DONE="rclone installed"
L_STEP5="Step 5/6: Connect Google Drive"
L_GDRIVE_OK="Google Drive already connected"
L_GDRIVE_BROWSER="A browser window will open for Google authentication."
L_GDRIVE_ALLOW="Sign in and click 'Allow' to grant access."
L_GDRIVE_ENTER="Press ENTER to open Google authentication..."
L_GDRIVE_OPENING="Opening Google authentication..."
L_GDRIVE_SUCCESS="Google Drive connected successfully"
L_GDRIVE_FAIL="Google Drive setup may have failed"
L_GDRIVE_LATER="You can configure it later by running: rclone config"
L_STEP6="Step 6/6: Configuring Freeme"
L_FREEME_CONFIG="Freeme configured"
L_AUTOSTART="Auto-start configured"
L_APP_INSTALLED="Freeme added to Applications"
L_COMPLETE="Installation complete!"
L_STATUS="Status:"
L_GDRIVE_CONNECTED="Google Drive connected"
L_GDRIVE_NOT="Google Drive not configured"
L_NAS_CONNECTED="NAS Freebox connected"
L_NAS_NOT="NAS Freebox not connected"
L_OPENING_GUIDE="Opening setup guide for NAS configuration..."
L_OPENING_DOCS="Opening documentation..."
L_ALL_READY="Everything is configured! Starting Freeme..."
L_CLOSE="Press ENTER to close..."
fi
# ==============================================================================
# HELPERS
# ==============================================================================
print_logo() {
clear
echo ""
echo -e "${CYAN}"
echo " ███████╗██████╗ ███████╗███████╗███╗ ███╗███████╗"
echo " ██╔════╝██╔══██╗██╔════╝██╔════╝████╗ ████║██╔════╝"
echo " █████╗ ██████╔╝█████╗ █████╗ ██╔████╔██║█████╗ "
echo " ██╔══╝ ██╔══██╗██╔══╝ ██╔══╝ ██║╚██╔╝██║██╔══╝ "
echo " ██║ ██║ ██║███████╗███████╗██║ ╚═╝ ██║███████╗"
echo " ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚══════╝"
echo -e "${NC}"
echo -e "${GRAY} NAS Freebox → Google Drive Backup${NC}"
echo ""
}
print_step() {
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${WHITE} $1${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
}
print_ok() {
echo -e "${GREEN} ✓ $1${NC}"
}
print_info() {
echo -e "${CYAN} ℹ $1${NC}"
}
print_warn() {
echo -e "${YELLOW} ⚠ $1${NC}"
}
print_error() {
echo -e "${RED} ✗ $1${NC}"
}
spinner() {
local pid=$1
local delay=0.1
local spinstr='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " ${CYAN}%c${NC} " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b"
done
printf " \b\b\b\b"
}
# ==============================================================================
# MAIN INSTALLATION
# ==============================================================================
print_logo
echo -e "${WHITE} ${L_WELCOME}${NC}"
echo -e "${GRAY} ${L_DURATION}${NC}"
echo ""
echo -e "${WHITE} ${L_START}${NC}"
read -r
# ============================================================================
# STEP 1: Copy files
# ============================================================================
print_step "$L_STEP1"
if [ "$SCRIPT_DIR" != "$APP_DIR" ]; then
print_info "$L_COPYING"
mkdir -p "$APP_DIR"
cp -R "$SCRIPT_DIR"/* "$APP_DIR/" 2>/dev/null || true
fi
chmod +x "$APP_DIR/scripts/"*.sh 2>/dev/null || true
chmod +x "$APP_DIR/plugin/"*.sh 2>/dev/null || true
chmod +x "$APP_DIR/"*.command 2>/dev/null || true
chmod +x "$APP_DIR/Freeme.app/Contents/MacOS/Freeme" 2>/dev/null || true
print_ok "$L_FILES_INSTALLED"
# ============================================================================
# STEP 2: Install Homebrew
# ============================================================================
print_step "$L_STEP2"
if command -v brew &>/dev/null; then
print_ok "$L_HOMEBREW_OK"
else
print_warn "$L_HOMEBREW_INSTALL"
print_info "$L_HOMEBREW_MANUAL"
print_info "After installing Homebrew, run install.command again."
exit 1
fi
# Ensure brew is in PATH
if [ -f "/opt/homebrew/bin/brew" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [ -f "/usr/local/bin/brew" ]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
# ============================================================================
# STEP 3: Install fswatch (for real-time file monitoring)
# ============================================================================
print_step "$L_STEP3"
if [ -f "/opt/homebrew/bin/fswatch" ] || [ -f "/usr/local/bin/fswatch" ] || command -v fswatch &>/dev/null; then
print_ok "$L_FSWATCH_OK"
else
print_info "$L_FSWATCH_INSTALL"
if brew install fswatch >/dev/null 2>&1; then
print_ok "$L_FSWATCH_DONE"
else
print_error "fswatch installation failed"
exit 1
fi
fi
# ============================================================================
# STEP 4: Install rclone
# ============================================================================
print_step "$L_STEP4"
RCLONE_PATH="/opt/homebrew/bin/rclone"
RCLONE_INTEL="/usr/local/bin/rclone"
if [ -f "$RCLONE_PATH" ] || [ -f "$RCLONE_INTEL" ] || command -v rclone &>/dev/null; then
print_ok "$L_RCLONE_OK"
else
print_info "$L_RCLONE_INSTALL"
if brew install rclone >/dev/null 2>&1; then
print_ok "$L_RCLONE_DONE"
else
print_error "rclone installation failed"
exit 1
fi
fi
# fswatch already installed in STEP 3
# ============================================================================
# STEP 5: Configure Google Drive
# ============================================================================
print_step "$L_STEP5"
# Check if Google Drive is already configured (use rclone.sh for consistency)
if bash "$APP_DIR/scripts/lib/rclone.sh" remote_exists gdrive 2>/dev/null | grep -q "true"; then
print_ok "$L_GDRIVE_OK"
else
echo ""
echo -e "${WHITE} ${L_GDRIVE_BROWSER}${NC}"
echo -e "${GRAY} ${L_GDRIVE_ALLOW}${NC}"
echo ""
echo -e "${WHITE} ${L_GDRIVE_ENTER}${NC}"
read -r
# Use centralized rclone.sh configure_gdrive function (REUSE-FIRST RULE)
print_info "$L_GDRIVE_OPENING"
result=$(bash "$APP_DIR/scripts/lib/rclone.sh" configure_gdrive 2>/dev/null)
# Verify it worked
if [[ "$result" == ok* ]]; then
print_ok "$L_GDRIVE_SUCCESS"
else
print_warn "$L_GDRIVE_FAIL"
print_info "$L_GDRIVE_LATER"
fi
fi
# ============================================================================
# STEP 6: Configure Freeme app (Electron Tray)
# ============================================================================
print_step "$L_STEP6"
# Note: SwiftBar removed - Freeme uses Electron Tray now
print_ok "$L_FREEME_CONFIG"
# Create LaunchAgent for daemon auto-start (using centralized template)
LAUNCHD_LIB="$APP_DIR/scripts/lib/launchd.sh"
if [ -f "$LAUNCHD_LIB" ]; then
result=$(bash "$LAUNCHD_LIB" install "$APP_DIR/scripts/freeme_daemon.sh")
if [[ "$result" == "ok" ]]; then
print_ok "$L_AUTOSTART"
else
print_warn "LaunchAgent: $result"
fi
else
print_warn "LaunchAgent library not found"
fi
# Copy Freeme.app to Applications folder
if [ -d "$APP_DIR/Freeme.app" ]; then
rm -rf "/Applications/Freeme.app" 2>/dev/null || true
cp -R "$APP_DIR/Freeme.app" "/Applications/Freeme.app" 2>/dev/null || true
print_ok "$L_APP_INSTALLED"
fi
# ============================================================================
# DONE - Open Setup Wizard for NAS configuration
# ============================================================================
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${WHITE} ✓ ${L_COMPLETE}${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Check status
GDRIVE_OK=false
NAS_OK=false
# UNIFIED: Use rclone.sh remote_exists as single source of truth
if bash "$APP_DIR/scripts/lib/rclone.sh" remote_exists gdrive 2>/dev/null | grep -q "true"; then
GDRIVE_OK=true
fi
# UNIFIED: Use storage.sh check_nas as single source of truth
if bash "$APP_DIR/scripts/lib/storage.sh" check_nas "/Volumes/NAS" 2>/dev/null | grep -q "true"; then
NAS_OK=true
fi
# Show status
echo -e "${WHITE} ${L_STATUS}${NC}"
[ "$GDRIVE_OK" = true ] && echo -e "${GREEN} ✓ ${L_GDRIVE_CONNECTED}${NC}" || echo -e "${YELLOW} ○ ${L_GDRIVE_NOT}${NC}"
[ "$NAS_OK" = true ] && echo -e "${GREEN} ✓ ${L_NAS_CONNECTED}${NC}" || echo -e "${YELLOW} ○ ${L_NAS_NOT}${NC}"
echo ""
# Open onboarding for NAS setup if needed
if [ "$NAS_OK" = false ]; then
echo -e "${WHITE} ${L_OPENING_GUIDE}${NC}"
sleep 1
open "$APP_DIR/onboarding/index.html"
fi
# Always open documentation
echo -e "${WHITE} ${L_OPENING_DOCS}${NC}"
sleep 1
open "$APP_DIR/docs/README.html"
# If everything is ready, start Freeme.app (Electron Tray)
if [ "$GDRIVE_OK" = true ] && [ "$NAS_OK" = true ]; then
echo ""
echo -e "${GREEN} ${L_ALL_READY}${NC}"
# Marchează prima configurare ca finalizată (skip first-run detection in Electron)
PREFS_FILE="$HOME/.freeme_prefs"
if [ -f "$PREFS_FILE" ]; then
if grep -q '^FIRST_RUN_DONE=' "$PREFS_FILE"; then
sed -i '' 's/^FIRST_RUN_DONE=.*/FIRST_RUN_DONE="true"/' "$PREFS_FILE"
else
echo 'FIRST_RUN_DONE="true"' >> "$PREFS_FILE"
fi
else
echo 'FIRST_RUN_DONE="true"' > "$PREFS_FILE"
fi
# Start Freeme.app (Electron Tray) - daemon will auto-start
open -a "/Applications/Freeme.app"
fi
echo ""
echo -e "${GRAY} ─────────────────────────────────────────────────────────${NC}"
echo -e "${GRAY} Freeme v1.9.0 by Andre Preda${NC}"
echo -e "${GRAY} Twitter/X: @andre_uxui${NC}"
echo -e "${GRAY} ─────────────────────────────────────────────────────────${NC}"
echo ""
echo -e "${WHITE} ${L_CLOSE}${NC}"
read -r
# Auto-close Terminal window
osascript -e 'tell application "Terminal" to close front window' 2>/dev/null &
exit 0