forked from Dusk-Labs/dim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1832 lines (1683 loc) · 67.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·1832 lines (1683 loc) · 67.3 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
ECLIPSE_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
if [[ -n "${ECLIPSE_URL+x}" ]]; then
ECLIPSE_URL_OVERRIDDEN=true
else
ECLIPSE_URL_OVERRIDDEN=false
fi
ECLIPSE_URL=${ECLIPSE_URL:-http://localhost:8000}
ECLIPSE_SELECTED_PLATFORM=""
ECLIPSE_AUTO_CONFIRM=false
ECLIPSE_START=true
ECLIPSE_DEMO=false
ECLIPSE_DEMO_SCENARIO=fresh
ECLIPSE_DEMO_REQUIREMENTS_RESOLVED=false
ECLIPSE_MENU_SELECTION=0
ECLIPSE_NEXT_MENU_SELECTION=0
ECLIPSE_LOG=""
ECLIPSE_STEP_PID=""
ECLIPSE_WINDOWS_TOOLCHAIN_DETAIL=""
ECLIPSE_WINDOWS_TOOLCHAIN_STATUS="toolchain-inconclusive"
ECLIPSE_INSTALL_MODE=fresh
ECLIPSE_EXISTING_ACTION=""
ECLIPSE_EXISTING_INSTALLATION=false
ECLIPSE_RUNNING_PIDS=()
ECLIPSE_MANAGED_PATHS=()
ECLIPSE_LIFECYCLE_LOG=""
ECLIPSE_LIFECYCLE_DIAGNOSTICS_SHOWN=false
ECLIPSE_SHUTDOWN_ATTEMPTED=false
ECLIPSE_RUNTIME_DIR="$ECLIPSE_ROOT/target/release"
ECLIPSE_BINARY_SUFFIX=""
ECLIPSE_MEDIA_STATUS="unknown"
ECLIPSE_FFMPEG_STATUS="unknown"
ECLIPSE_FFPROBE_STATUS="unknown"
ECLIPSE_FFMPEG_MAJOR=""
ECLIPSE_FFPROBE_MAJOR=""
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
ECLIPSE_BOLD=$'\033[1m'
ECLIPSE_DIM=$'\033[2m'
ECLIPSE_BLUE=$'\033[34m'
ECLIPSE_GREEN=$'\033[32m'
ECLIPSE_YELLOW=$'\033[33m'
ECLIPSE_RED=$'\033[31m'
ECLIPSE_RESET=$'\033[0m'
else
ECLIPSE_BOLD=""
ECLIPSE_DIM=""
ECLIPSE_BLUE=""
ECLIPSE_GREEN=""
ECLIPSE_YELLOW=""
ECLIPSE_RED=""
ECLIPSE_RESET=""
fi
usage() {
cat <<'EOF'
Usage: ./install.sh [--demo] [--demo-scenario SCENARIO] [--existing-action ACTION] [--platform macos|linux|windows] [--yes] [--no-start]
Windows CMD or PowerShell: install.cmd [--demo] [--demo-scenario SCENARIO] [--existing-action ACTION] [--platform windows] [--yes] [--no-start]
Without --platform, Eclipse Setup starts with an interactive platform selector.
Demo mode runs the same flow with deterministic fake checks and no system changes.
Demo scenarios: fresh, reinstall, reset, clean, or exit.
Existing-install actions for automation: reinstall, reset, clean, or exit (requires --yes).
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--platform)
[[ $# -ge 2 ]] || { echo "--platform requires macos, linux, or windows." >&2; exit 2; }
ECLIPSE_SELECTED_PLATFORM=$2
shift
;;
--yes)
ECLIPSE_AUTO_CONFIRM=true
;;
--demo)
ECLIPSE_DEMO=true
;;
--demo-scenario)
[[ $# -ge 2 ]] || { echo "--demo-scenario requires fresh, reinstall, reset, clean, or exit." >&2; exit 2; }
ECLIPSE_DEMO_SCENARIO=$2
shift
;;
--existing-action)
[[ $# -ge 2 ]] || { echo "--existing-action requires reinstall, reset, clean, or exit." >&2; exit 2; }
ECLIPSE_EXISTING_ACTION=$2
shift
;;
--no-start)
ECLIPSE_START=false
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 2
;;
esac
shift
done
case "$ECLIPSE_DEMO_SCENARIO" in
fresh|reinstall|reset|clean|exit) ;;
*) echo "Unknown demo scenario: $ECLIPSE_DEMO_SCENARIO" >&2; exit 2 ;;
esac
case "$ECLIPSE_EXISTING_ACTION" in
""|reinstall|reset|clean|exit) ;;
*) echo "Unknown existing-install action: $ECLIPSE_EXISTING_ACTION" >&2; exit 2 ;;
esac
if [[ -n "$ECLIPSE_EXISTING_ACTION" && "$ECLIPSE_AUTO_CONFIRM" != true ]]; then
echo "--existing-action requires --yes so confirmations remain explicit." >&2
exit 2
fi
success() { printf '%s✓%s %s\n' "$ECLIPSE_GREEN" "$ECLIPSE_RESET" "$*"; }
notice() { printf '%s›%s %s\n' "$ECLIPSE_BLUE" "$ECLIPSE_RESET" "$*"; }
warning() { printf '%s!%s %s\n' "$ECLIPSE_YELLOW" "$ECLIPSE_RESET" "$*"; }
failure() { printf '%s✗%s %s\n' "$ECLIPSE_RED" "$ECLIPSE_RESET" "$*" >&2; }
setup_command() {
if [[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]]; then
printf 'install.cmd'
else
printf '%s/install.sh' "$ECLIPSE_ROOT"
fi
}
cancel_install() {
printf '\n' >&2
if [[ -n "$ECLIPSE_STEP_PID" ]] && kill -0 "$ECLIPSE_STEP_PID" 2>/dev/null; then
kill "$ECLIPSE_STEP_PID" 2>/dev/null || true
wait "$ECLIPSE_STEP_PID" 2>/dev/null || true
fi
failure "Setup cancelled. Run $(setup_command) whenever you are ready to continue."
exit 130
}
trap cancel_install INT TERM
confirm() {
local prompt=$1
local reply
if [[ "$ECLIPSE_AUTO_CONFIRM" == true ]]; then
printf '%s?%s %s %sYes%s\n' "$ECLIPSE_BLUE" "$ECLIPSE_RESET" "$prompt" "$ECLIPSE_DIM" "$ECLIPSE_RESET"
return 0
fi
printf '%s?%s %s %s[Y/n]%s ' "$ECLIPSE_BLUE" "$ECLIPSE_RESET" "$prompt" "$ECLIPSE_DIM" "$ECLIPSE_RESET"
read -r reply
[[ -z "$reply" || "$reply" == "y" || "$reply" == "Y" || "$reply" == "yes" || "$reply" == "Yes" ]]
}
select_menu() {
local prompt=$1
local allow_auto=$2
shift 2
local selected=$ECLIPSE_NEXT_MENU_SELECTION
local key
local escape
local options=("$@")
ECLIPSE_NEXT_MENU_SELECTION=0
if [[ -n "$prompt" ]]; then
printf '%s%s%s\n\n' "$ECLIPSE_BOLD" "$prompt" "$ECLIPSE_RESET"
fi
while true; do
local index=0
while [[ $index -lt ${#options[@]} ]]; do
if [[ $index -eq $selected ]]; then
printf '▶ %s\n' "${options[$index]}"
else
printf ' %s\n' "${options[$index]}"
fi
index=$((index + 1))
done
if [[ "$allow_auto" == true && "$ECLIPSE_AUTO_CONFIRM" == true ]]; then
break
fi
if [[ ! -t 0 || ! -t 1 ]]; then
failure "Interactive setup needs a terminal. Re-run ./install.sh in a terminal."
exit 2
fi
IFS= read -rsn1 key
if [[ "$key" == $'\033' ]]; then
IFS= read -rsn1 escape || true
IFS= read -rsn1 escape || true
if [[ "$escape" == "A" && $selected -gt 0 ]]; then
selected=$((selected - 1))
elif [[ "$escape" == "B" && $selected -lt $((${#options[@]} - 1)) ]]; then
selected=$((selected + 1))
fi
elif [[ -z "$key" ]]; then
break
elif [[ "$key" == "k" && $selected -gt 0 ]]; then
selected=$((selected - 1))
elif [[ "$key" == "j" && $selected -lt $((${#options[@]} - 1)) ]]; then
selected=$((selected + 1))
fi
printf '\033[%sA' "${#options[@]}"
done
ECLIPSE_MENU_SELECTION=$selected
printf '\n'
}
select_platform() {
select_menu "Which platform are you installing on?" false "macOS" "Linux" "Windows"
case $ECLIPSE_MENU_SELECTION in
0) ECLIPSE_SELECTED_PLATFORM=macos ;;
1) ECLIPSE_SELECTED_PLATFORM=linux ;;
2) ECLIPSE_SELECTED_PLATFORM=windows ;;
esac
}
run_step() {
local label=$1
shift
local log
local pid
local frame=0
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
if [[ "$ECLIPSE_DEMO" == true ]]; then
if [[ -t 1 ]]; then
while [[ $frame -lt 8 ]]; do
printf '\r%s%s%s %s' "$ECLIPSE_BLUE" "${frames[$frame]}" "$ECLIPSE_RESET" "$label"
sleep 0.08
frame=$((frame + 1))
done
printf '\r\033[2K'
fi
success "$label"
return 0
fi
log=$(mktemp "${TMPDIR:-/tmp}/eclipse-install.XXXXXX")
ECLIPSE_LOG=$log
"$@" >"$log" 2>&1 &
pid=$!
ECLIPSE_STEP_PID=$pid
if [[ -t 1 ]]; then
while kill -0 "$pid" 2>/dev/null; do
printf '\r%s%s%s %s' "$ECLIPSE_BLUE" "${frames[$frame]}" "$ECLIPSE_RESET" "$label"
frame=$(((frame + 1) % ${#frames[@]}))
sleep 0.1
done
printf '\r\033[2K'
fi
if wait "$pid"; then
ECLIPSE_STEP_PID=""
success "$label"
rm -f "$log"
ECLIPSE_LOG=""
return 0
fi
ECLIPSE_STEP_PID=""
failure "$label failed."
if [[ -s "$log" ]]; then
printf '\n%sDiagnostic output:%s\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET" >&2
tail -n 30 "$log" >&2
fi
printf '\n%sFull log:%s %s\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET" "$log" >&2
return 1
}
command_available() {
command -v "$1" >/dev/null 2>&1
}
add_running_pid() {
local candidate=$1
local existing
candidate=${candidate//$'\r'/}
[[ "$candidate" =~ ^[0-9]+$ ]] || return 0
for existing in "${ECLIPSE_RUNNING_PIDS[@]:-}"; do
[[ "$existing" == "$candidate" ]] && return 0
done
ECLIPSE_RUNNING_PIDS+=("$candidate")
}
ensure_lifecycle_log() {
[[ "$ECLIPSE_DEMO" == false ]] || return 0
[[ -z "$ECLIPSE_LIFECYCLE_LOG" ]] || return 0
mkdir -p "$ECLIPSE_RUNTIME_DIR/logs"
ECLIPSE_LIFECYCLE_LOG=$(mktemp "$ECLIPSE_RUNTIME_DIR/logs/install-lifecycle.XXXXXX.log")
}
lifecycle_debug() {
[[ -n "$ECLIPSE_LIFECYCLE_LOG" ]] || return 0
printf '%s\n' "$*" >> "$ECLIPSE_LIFECYCLE_LOG"
}
surface_lifecycle_diagnostics() {
[[ -n "$ECLIPSE_LIFECYCLE_LOG" && -s "$ECLIPSE_LIFECYCLE_LOG" ]] || return 0
[[ "$ECLIPSE_LIFECYCLE_DIAGNOSTICS_SHOWN" == false ]] || return 0
ECLIPSE_LIFECYCLE_DIAGNOSTICS_SHOWN=true
printf '\n%sProcess lifecycle diagnostic:%s\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET" >&2
tail -n 40 "$ECLIPSE_LIFECYCLE_LOG" >&2
printf '%sFull lifecycle log:%s %s\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET" "$ECLIPSE_LIFECYCLE_LOG" >&2
}
canonical_existing_file() {
local path=$1
[[ -e "$path" ]] || return 1
(cd "$(dirname "$path")" && printf '%s/%s\n' "$PWD" "$(basename "$path")")
}
process_matches_unix_runtime() {
local pid=$1
local eclipse_binary=$2
local legacy_binary=$3
local executable=""
local command_line=""
if [[ -e "/proc/$pid/exe" ]]; then
executable=$(readlink "/proc/$pid/exe" 2>/dev/null || true)
executable=${executable% (deleted)}
[[ "$executable" == "$eclipse_binary" || "$executable" == "$legacy_binary" ]]
return
fi
command_line=$(ps -p "$pid" -o command= 2>/dev/null || true)
[[ "$command_line" == "$eclipse_binary" || "$command_line" == "$eclipse_binary "* ||
"$command_line" == "$legacy_binary" || "$command_line" == "$legacy_binary "* ]]
}
detect_windows_runtime_processes() {
local eclipse_binary=$1
local legacy_binary=$2
local targets
local detector_error_log=${ECLIPSE_LIFECYCLE_LOG:-/dev/null}
local recorded_pid=""
local pid
if command_available cygpath; then
eclipse_binary=$(cygpath -w "$eclipse_binary")
[[ -z "$legacy_binary" ]] || legacy_binary=$(cygpath -w "$legacy_binary")
fi
targets="$eclipse_binary"
[[ -z "$legacy_binary" ]] || targets="$targets;$legacy_binary"
if [[ -f "$ECLIPSE_RUNTIME_DIR/eclipse.pid" ]]; then
recorded_pid=$(tr -dc '0-9' < "$ECLIPSE_RUNTIME_DIR/eclipse.pid")
fi
lifecycle_debug "detect targets=$targets recorded_pid=${recorded_pid:-none}"
while IFS= read -r pid; do
add_running_pid "$pid"
done < <(
ECLIPSE_PROCESS_TARGETS="$targets" \
ECLIPSE_RECORDED_PID="$recorded_pid" \
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
$comparison = [StringComparison]::OrdinalIgnoreCase
$targets = @($env:ECLIPSE_PROCESS_TARGETS.Split(";") |
Where-Object { $_ } |
ForEach-Object { [IO.Path]::GetFullPath($_) })
$recordedPid = 0
[void][int]::TryParse($env:ECLIPSE_RECORDED_PID, [ref]$recordedPid)
function Add-LifecycleTrace([string] $message) {
[Console]::Error.WriteLine($message)
}
function Find-CommandTarget([string] $commandLine) {
if (-not $commandLine) { return $null }
$commandLine = $commandLine.Trim()
foreach ($target in $targets) {
if ($commandLine.Equals($target, $comparison) -or
$commandLine.StartsWith($target + " ", $comparison) -or
$commandLine.Equals("`"$target`"", $comparison) -or
$commandLine.StartsWith("`"$target`" ", $comparison)) {
return $target
}
}
return $null
}
Add-LifecycleTrace("windows process scan started targets=" + ($targets -join ";"))
Get-CimInstance Win32_Process -ErrorAction SilentlyContinue |
ForEach-Object {
$process = $_
$normalizedExecutable = $null
if ($process.ExecutablePath) {
try {
$normalizedExecutable = [IO.Path]::GetFullPath($process.ExecutablePath)
} catch {
$normalizedExecutable = $null
}
}
$executableTarget = $targets | Where-Object {
$normalizedExecutable -and $_.Equals($normalizedExecutable, $comparison)
} | Select-Object -First 1
$commandTarget = Find-CommandTarget $process.CommandLine
$namedCandidate = $process.Name -and
($process.Name.Equals("eclipse.exe", $comparison) -or
$process.Name.Equals("dim.exe", $comparison))
$recordedCandidate = $recordedPid -gt 0 -and $process.ProcessId -eq $recordedPid
if (-not ($namedCandidate -or $recordedCandidate -or $executableTarget -or $commandTarget)) {
return
}
$accepted = [bool]($executableTarget -or $commandTarget)
$kind = if ($executableTarget) {
[IO.Path]::GetFileName($executableTarget)
} elseif ($commandTarget) {
[IO.Path]::GetFileName($commandTarget)
} else {
"another path"
}
$reason = if ($executableTarget) {
"exact normalized ExecutablePath"
} elseif ($commandTarget) {
"exact command-line executable"
} elseif ($recordedCandidate) {
"recorded PID lacks exact path evidence"
} else {
"process name only"
}
$executableDisplay = if ($process.ExecutablePath) {
$process.ExecutablePath
} else {
"<unavailable>"
}
$normalizedDisplay = if ($normalizedExecutable) {
$normalizedExecutable
} else {
"<unavailable>"
}
$commandDisplay = if ($process.CommandLine) {
$process.CommandLine
} else {
"<unavailable>"
}
Add-LifecycleTrace(
"candidate pid=$($process.ProcessId) name=$($process.Name) kind=$kind " +
"executable=$executableDisplay normalized=$normalizedDisplay " +
"accepted=$accepted reason=$reason command=$commandDisplay"
)
if ($accepted) {
[Console]::Out.Write("$($process.ProcessId)`n")
}
}
' 2>>"$detector_error_log" || lifecycle_debug "windows process scan command failed"
)
lifecycle_debug "detect accepted_pids=${ECLIPSE_RUNNING_PIDS[*]:-none}"
}
detect_unix_runtime_processes() {
local eclipse_binary=$1
local legacy_binary=$2
local pid=""
local command_line=""
if [[ -f "$ECLIPSE_RUNTIME_DIR/eclipse.pid" ]]; then
pid=$(tr -dc '0-9' < "$ECLIPSE_RUNTIME_DIR/eclipse.pid")
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null &&
process_matches_unix_runtime "$pid" "$eclipse_binary" "$legacy_binary"; then
add_running_pid "$pid"
fi
fi
while read -r pid command_line; do
[[ -n "$pid" ]] || continue
if [[ "$command_line" == "$eclipse_binary" || "$command_line" == "$eclipse_binary "* ||
"$command_line" == "$legacy_binary" || "$command_line" == "$legacy_binary "* ]]; then
add_running_pid "$pid"
fi
done < <(ps -ax -o pid= -o command= 2>/dev/null || true)
}
detect_running_eclipse() {
local eclipse_binary="$ECLIPSE_RUNTIME_DIR/eclipse$ECLIPSE_BINARY_SUFFIX"
local legacy_binary="$ECLIPSE_RUNTIME_DIR/dim$ECLIPSE_BINARY_SUFFIX"
local canonical
ECLIPSE_RUNNING_PIDS=()
if [[ "$ECLIPSE_DEMO" == true && "$ECLIPSE_DEMO_SCENARIO" != fresh ]]; then
ECLIPSE_RUNNING_PIDS=(4242)
return 0
fi
[[ "$ECLIPSE_DEMO" == false ]] || return 1
canonical=$(canonical_existing_file "$eclipse_binary" 2>/dev/null || true)
[[ -n "$canonical" ]] && eclipse_binary=$canonical
canonical=$(canonical_existing_file "$legacy_binary" 2>/dev/null || true)
[[ -n "$canonical" ]] && legacy_binary=$canonical
if [[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]]; then
detect_windows_runtime_processes "$eclipse_binary" "$legacy_binary"
else
detect_unix_runtime_processes "$eclipse_binary" "$legacy_binary"
fi
[[ ${#ECLIPSE_RUNNING_PIDS[@]} -gt 0 ]]
}
detect_existing_installation() {
if [[ "$ECLIPSE_DEMO" == true ]]; then
[[ "$ECLIPSE_DEMO_SCENARIO" != fresh ]]
return
fi
[[ -f "$ECLIPSE_RUNTIME_DIR/eclipse$ECLIPSE_BINARY_SUFFIX" ||
-f "$ECLIPSE_RUNTIME_DIR/dim$ECLIPSE_BINARY_SUFFIX" ||
-f "$ECLIPSE_RUNTIME_DIR/config/config.toml" ||
-f "$ECLIPSE_RUNTIME_DIR/config/dim.db" ||
-d "$ECLIPSE_RUNTIME_DIR/metadata" ||
-d "$ECLIPSE_RUNTIME_DIR/streaming_cache" ]] && return 0
detect_running_eclipse
}
exit_without_changes() {
success "No changes made"
exit 0
}
prepare_installation_lifecycle() {
local selection=0
ECLIPSE_BINARY_SUFFIX=""
[[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]] && ECLIPSE_BINARY_SUFFIX=".exe"
detect_existing_installation || return 0
ECLIPSE_EXISTING_INSTALLATION=true
printf '%sExisting Eclipse installation detected.%s\n\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET"
if [[ -n "$ECLIPSE_EXISTING_ACTION" ]]; then
case "$ECLIPSE_EXISTING_ACTION" in
reinstall) ECLIPSE_NEXT_MENU_SELECTION=0 ;;
reset) ECLIPSE_NEXT_MENU_SELECTION=1 ;;
clean) ECLIPSE_NEXT_MENU_SELECTION=2 ;;
exit) ECLIPSE_NEXT_MENU_SELECTION=3 ;;
esac
elif [[ "$ECLIPSE_DEMO" == true ]]; then
case "$ECLIPSE_DEMO_SCENARIO" in
reinstall) ECLIPSE_NEXT_MENU_SELECTION=0 ;;
reset) ECLIPSE_NEXT_MENU_SELECTION=1 ;;
clean) ECLIPSE_NEXT_MENU_SELECTION=2 ;;
exit) ECLIPSE_NEXT_MENU_SELECTION=3 ;;
esac
fi
select_menu "What would you like to do?" true \
"Reinstall / update Eclipse" "Reset Eclipse" "Clean install" "Exit"
selection=$ECLIPSE_MENU_SELECTION
case $selection in
0)
ECLIPSE_INSTALL_MODE=reinstall
printf 'Configuration, accounts, libraries, metadata, and other persistent state will be preserved.\n'
;;
1)
ECLIPSE_INSTALL_MODE=reset
printf 'Reset removes host settings, streaming cache, and logs.\n'
printf 'Accounts, libraries, indexed media state, watch progress, and metadata are preserved.\n'
printf 'A new host secret is generated, so existing browser sessions must sign in again.\n'
confirm "Continue with Reset Eclipse?" || exit_without_changes
;;
2)
ECLIPSE_INSTALL_MODE=clean
printf 'Clean install permanently removes Eclipse-managed configuration, accounts, libraries,\n'
printf 'indexed media state, watch progress, sessions, metadata, streaming cache, and logs.\n'
printf 'Media source files and the source repository are not removed.\n'
confirm "Permanently remove this Eclipse installation's managed data?" || exit_without_changes
;;
3) exit_without_changes ;;
esac
if [[ "$ECLIPSE_INSTALL_MODE" == clean ]]; then
ensure_lifecycle_log
lifecycle_debug "clean install confirmed runtime=${ECLIPSE_RUNTIME_DIR} platform=${ECLIPSE_SELECTED_PLATFORM}"
fi
if detect_running_eclipse; then
warning "Running Eclipse detected (PID(s): ${ECLIPSE_RUNNING_PIDS[*]})."
printf 'Eclipse must be stopped before its runtime files can be changed.\n'
fi
}
wait_for_processes_to_stop() {
local attempts=0
local pid
lifecycle_debug "waiting for verified process exit pids=${ECLIPSE_RUNNING_PIDS[*]:-none} timeout_seconds=20"
while [[ $attempts -lt 80 ]]; do
if [[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]]; then
if ! detect_running_eclipse; then
lifecycle_debug "verified process exited during graceful wait attempt=$attempts"
return 0
fi
attempts=$((attempts + 1))
sleep 0.25
continue
fi
local alive=false
for pid in "${ECLIPSE_RUNNING_PIDS[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
alive=true
break
fi
done
if [[ "$alive" == false ]]; then
lifecycle_debug "verified process exited during graceful wait attempt=$attempts"
return 0
fi
attempts=$((attempts + 1))
sleep 0.25
done
lifecycle_debug "verified process remained alive through graceful timeout pids=${ECLIPSE_RUNNING_PIDS[*]:-none}"
return 1
}
format_elapsed() {
local seconds=$1
printf '%02d:%02d' "$((seconds / 60))" "$((seconds % 60))"
}
run_installation() {
local log
local stage_file
local pid
local frame=0
local current_stage=""
local shown_stage=""
local started=$SECONDS
local label
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
if [[ "$ECLIPSE_DEMO" == true ]]; then
for current_stage in \
"Installing frontend dependencies" \
"Building frontend" \
"Building Eclipse backend… 01:42" \
"Preparing runtime"; do
printf '%s⠋%s %s\n' "$ECLIPSE_BLUE" "$ECLIPSE_RESET" "$current_stage"
done
success "Eclipse installed"
return 0
fi
log=$(mktemp "${TMPDIR:-/tmp}/eclipse-install.XXXXXX")
stage_file=$(mktemp "${TMPDIR:-/tmp}/eclipse-stage.XXXXXX")
ECLIPSE_LOG=$log
"$ECLIPSE_ROOT/scripts/bootstrap.sh" --release --stage-file "$stage_file" >"$log" 2>&1 &
pid=$!
ECLIPSE_STEP_PID=$pid
while kill -0 "$pid" 2>/dev/null; do
if [[ -s "$stage_file" ]]; then
current_stage=$(head -n 1 "$stage_file")
fi
label=$current_stage
if [[ "$current_stage" == "Building Eclipse backend" ]]; then
label="${current_stage}… $(format_elapsed "$((SECONDS - started))")"
fi
if [[ -t 1 ]]; then
printf '\r%s%s%s %s' "$ECLIPSE_BLUE" "${frames[$frame]}" "$ECLIPSE_RESET" "${label:-Preparing installation}"
frame=$(((frame + 1) % ${#frames[@]}))
elif [[ -n "$label" && "$label" != "$shown_stage" ]]; then
notice "$label"
shown_stage=$label
fi
sleep 0.1
done
[[ ! -t 1 ]] || printf '\r\033[2K'
if wait "$pid"; then
ECLIPSE_STEP_PID=""
rm -f "$log" "$stage_file"
ECLIPSE_LOG=""
success "Eclipse installed"
return 0
fi
ECLIPSE_STEP_PID=""
failure "Eclipse installation failed."
if [[ -s "$log" ]]; then
printf '\n%sDiagnostic output:%s\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET" >&2
tail -n 30 "$log" >&2
fi
printf '\n%sFull log:%s %s\n' "$ECLIPSE_BOLD" "$ECLIPSE_RESET" "$log" >&2
rm -f "$stage_file"
return 1
}
force_stop_windows_processes() {
local joined=""
local pid
for pid in "${ECLIPSE_RUNNING_PIDS[@]}"; do
joined="${joined:+$joined,}$pid"
done
ECLIPSE_PROCESS_IDS="$joined" powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
$ids = $env:ECLIPSE_PROCESS_IDS.Split(",") | ForEach-Object { [int]$_ }
Get-Process -Id $ids -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction Stop
'
}
stop_running_eclipse() {
local context=${1:-replace}
local pid
[[ ${#ECLIPSE_RUNNING_PIDS[@]} -gt 0 ]] || return 0
confirm "Stop the running Eclipse process now?" || exit_without_changes
ECLIPSE_SHUTDOWN_ATTEMPTED=true
lifecycle_debug "shutdown confirmed for verified pids=${ECLIPSE_RUNNING_PIDS[*]}"
if [[ "$ECLIPSE_DEMO" == true ]]; then
if [[ "$context" == clean ]]; then
success "Eclipse stopped"
else
success "Running Eclipse stopped before replacement"
fi
ECLIPSE_RUNNING_PIDS=()
return 0
fi
if [[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]]; then
lifecycle_debug "sending runtime-local graceful shutdown request path=$ECLIPSE_RUNTIME_DIR/eclipse.shutdown"
if ! printf '%s\n' "shutdown" > "$ECLIPSE_RUNTIME_DIR/eclipse.shutdown"; then
failure "The runtime-local Eclipse shutdown request could not be written."
lifecycle_debug "runtime-local graceful shutdown request write failed"
surface_lifecycle_diagnostics
return 1
fi
lifecycle_debug "runtime-local graceful shutdown request written successfully"
else
for pid in "${ECLIPSE_RUNNING_PIDS[@]}"; do
kill -TERM "$pid" 2>/dev/null || true
done
fi
if wait_for_processes_to_stop; then
if [[ "$context" == clean ]]; then
success "Eclipse stopped"
else
success "Running Eclipse stopped before replacement"
fi
return 0
fi
warning "Eclipse did not finish shutting down within 20 seconds."
lifecycle_debug "graceful shutdown timed out; explicit force-stop confirmation required"
confirm "Force stop only the verified Eclipse process(es) for this installation?" || {
failure "Eclipse is still running; installation cannot safely continue."
lifecycle_debug "force-stop declined; destructive lifecycle aborted"
surface_lifecycle_diagnostics
return 1
}
if ! detect_running_eclipse; then
lifecycle_debug "verified process exited before force-stop was issued"
return 0
fi
lifecycle_debug "force-stopping reverified pids=${ECLIPSE_RUNNING_PIDS[*]}"
if [[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]]; then
if ! force_stop_windows_processes; then
failure "The verified Eclipse process could not be force-stopped."
lifecycle_debug "verified force-stop command failed pids=${ECLIPSE_RUNNING_PIDS[*]}"
surface_lifecycle_diagnostics
return 1
fi
else
for pid in "${ECLIPSE_RUNNING_PIDS[@]}"; do
kill -KILL "$pid" 2>/dev/null || true
done
fi
wait_for_processes_to_stop || {
failure "The verified Eclipse process could not be stopped."
lifecycle_debug "verified process still alive after force-stop"
surface_lifecycle_diagnostics
return 1
}
lifecycle_debug "verified process exited after force-stop"
if [[ "$context" == clean ]]; then
success "Eclipse stopped"
else
success "Running Eclipse stopped before replacement"
fi
}
read_runtime_setting() {
local key=$1
local config="$ECLIPSE_RUNTIME_DIR/config/config.toml"
[[ -f "$config" ]] || return 1
awk -F= -v key="$key" '
$1 ~ "^[[:space:]]*" key "[[:space:]]*$" {
value = $2
sub(/#.*/, "", value)
gsub(/^[[:space:]\"]+|[[:space:]\"]+$/, "", value)
print value
exit
}
' "$config"
}
configured_runtime_path() {
local value=$1
if [[ "$value" == /* ]]; then
printf '%s\n' "$value"
elif [[ "$value" =~ ^[A-Za-z]:[\\/] ]]; then
if command_available cygpath; then cygpath -u "$value"; else printf '%s\n' "$value"; fi
else
printf '%s/%s\n' "$ECLIPSE_RUNTIME_DIR" "$value"
fi
}
remove_managed_path() {
local path=$1
local runtime_absolute
local parent_absolute
local absolute
[[ -e "$path" || -L "$path" ]] || return 0
runtime_absolute=$(cd "$ECLIPSE_RUNTIME_DIR" && pwd -P)
parent_absolute=$(cd "$(dirname "$path")" 2>/dev/null && pwd -P) || {
warning "Preserved unresolvable path: $path"
return 0
}
absolute="$parent_absolute/$(basename "$path")"
case "$absolute" in
"$runtime_absolute"/*)
[[ "$absolute" != "$runtime_absolute" ]] || {
failure "Refusing to remove the runtime root."
return 1
}
rm -rf -- "$absolute"
;;
*) warning "Preserved externally configured path: $path" ;;
esac
}
queue_managed_path() {
local path=$1
local runtime_absolute
local parent_absolute
local absolute
local queued
[[ -e "$path" || -L "$path" ]] || return 0
runtime_absolute=$(cd "$ECLIPSE_RUNTIME_DIR" && pwd -P)
parent_absolute=$(cd "$(dirname "$path")" 2>/dev/null && pwd -P) || {
warning "Preserved unresolvable path: $path"
return 0
}
absolute="$parent_absolute/$(basename "$path")"
case "$absolute" in
"$runtime_absolute"/*)
[[ "$absolute" != "$runtime_absolute" ]] || {
failure "Refusing to remove the runtime root."
return 1
}
if [[ ${#ECLIPSE_MANAGED_PATHS[@]} -gt 0 ]]; then
for queued in "${ECLIPSE_MANAGED_PATHS[@]}"; do
[[ "$queued" == "$absolute" ]] && return 0
done
fi
ECLIPSE_MANAGED_PATHS+=("$absolute")
;;
*) warning "Preserved externally configured path: $path" ;;
esac
}
collect_reset_boundary() {
local configured_cache
local config_temp
configured_cache=$(read_runtime_setting cache_dir 2>/dev/null || true)
queue_managed_path "$ECLIPSE_RUNTIME_DIR/config/config.toml"
for config_temp in "$ECLIPSE_RUNTIME_DIR"/config/.config.toml.tmp-*; do
queue_managed_path "$config_temp"
done
[[ -n "$configured_cache" ]] && queue_managed_path "$(configured_runtime_path "$configured_cache")"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/streaming_cache"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/logs"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/eclipse.log"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/eclipse.pid"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/eclipse.shutdown"
}
collect_clean_boundary() {
local configured_metadata
local configured_cache
configured_metadata=$(read_runtime_setting metadata_dir 2>/dev/null || true)
configured_cache=$(read_runtime_setting cache_dir 2>/dev/null || true)
collect_reset_boundary
queue_managed_path "$ECLIPSE_RUNTIME_DIR/config/dim.db"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/config/dim.db-journal"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/config/dim.db-wal"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/config/dim.db-shm"
[[ -n "$configured_metadata" ]] && queue_managed_path "$(configured_runtime_path "$configured_metadata")"
[[ -n "$configured_cache" ]] && queue_managed_path "$(configured_runtime_path "$configured_cache")"
queue_managed_path "$ECLIPSE_RUNTIME_DIR/metadata"
}
verify_windows_managed_paths_released() {
local joined=""
local path
local windows_path
local diagnostic
if [[ ${#ECLIPSE_MANAGED_PATHS[@]} -gt 0 ]]; then
for path in "${ECLIPSE_MANAGED_PATHS[@]}"; do
windows_path=$path
if command_available cygpath; then
windows_path=$(cygpath -w "$path")
fi
joined="${joined}${joined:+$'\n'}$windows_path"
done
fi
[[ -n "$joined" ]] || return 0
if ! diagnostic=$(ECLIPSE_CLEAN_TARGETS="$joined" powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
$failed = $false
foreach ($target in ($env:ECLIPSE_CLEAN_TARGETS -split "`n")) {
$item = Get-Item -LiteralPath $target -Force -ErrorAction SilentlyContinue
if ($null -eq $item) { continue }
if (($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { continue }
$files = if ($item.PSIsContainer) {
Get-ChildItem -LiteralPath $item.FullName -File -Force -Recurse -ErrorAction Stop |
Where-Object {
($_.Attributes -band [IO.FileAttributes]::ReparsePoint) -eq 0
}
} else {
@($item)
}
foreach ($file in $files) {
$stream = $null
try {
$stream = [IO.File]::Open(
$file.FullName,
[IO.FileMode]::Open,
[IO.FileAccess]::ReadWrite,
[IO.FileShare]::None
)
} catch {
[Console]::Error.WriteLine("$($file.FullName): $($_.Exception.Message)")
$failed = $true
} finally {
if ($null -ne $stream) { $stream.Dispose() }
}
}
}
if ($failed) { exit 1 }
' 2>&1); then
if [[ "$ECLIPSE_SHUTDOWN_ATTEMPTED" == true ]]; then
failure "Existing Eclipse data is still in use after the verified process exited; no files were removed."
else
failure "No exact Eclipse process could be verified, but existing Eclipse data is locked; no files were removed."
fi
while IFS= read -r path; do
[[ -z "$path" ]] || printf ' %s\n' "$path" >&2
done <<< "$diagnostic"
lifecycle_debug "exclusive-lock preflight failed shutdown_attempted=$ECLIPSE_SHUTDOWN_ATTEMPTED"
while IFS= read -r path; do
[[ -z "$path" ]] || lifecycle_debug "locked path=$path"
done <<< "$diagnostic"
surface_lifecycle_diagnostics
return 1
fi
lifecycle_debug "exclusive-lock preflight succeeded for all managed files"
}
verify_clean_boundary_ready() {
if detect_running_eclipse; then
failure "Verified Eclipse process is still running (PID(s): ${ECLIPSE_RUNNING_PIDS[*]}). No files were removed."
lifecycle_debug "clean preflight blocked by running verified pids=${ECLIPSE_RUNNING_PIDS[*]}"
surface_lifecycle_diagnostics
return 1
fi
lifecycle_debug "no exact Eclipse process remains before exclusive-lock preflight"
if [[ "$ECLIPSE_SELECTED_PLATFORM" == windows ]]; then
verify_windows_managed_paths_released
fi
}
remove_collected_managed_paths() {
local path
[[ ${#ECLIPSE_MANAGED_PATHS[@]} -gt 0 ]] || return 0
for path in "${ECLIPSE_MANAGED_PATHS[@]}"; do
rm -rf -- "$path"
done
}
apply_reset_boundary() {
ECLIPSE_MANAGED_PATHS=()
collect_reset_boundary
remove_collected_managed_paths
}
apply_clean_boundary() {
ECLIPSE_MANAGED_PATHS=()
collect_clean_boundary
notice "Checking existing data"
verify_clean_boundary_ready
success "Existing data ready for removal"
notice "Removing existing Eclipse data"
remove_collected_managed_paths
success "Existing Eclipse data removed"
}