Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·100 lines (83 loc) · 2.64 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·100 lines (83 loc) · 2.64 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
#!/bin/bash
set -euo pipefail
REPO_SLUG="duducp/ai-memory-manager"
REF="${AI_MEMORY_MANAGER_REF:-main}"
BOOTSTRAP_TMP=""
SRC_DIR=""
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
BOOT_BLUE=$'\033[1;34m'
BOOT_RED=$'\033[1;31m'
BOOT_RESET=$'\033[0m'
else
BOOT_BLUE=""
BOOT_RED=""
BOOT_RESET=""
fi
boot_log() {
printf '%s[ai-memory]%s %s\n' "$BOOT_BLUE" "$BOOT_RESET" "$*"
}
boot_die() {
printf '%s[ai-memory]%s %s\n' "$BOOT_RED" "$BOOT_RESET" "$*" >&2
exit 1
}
cleanup_boot() {
if [[ -n "$BOOTSTRAP_TMP" && -d "$BOOTSTRAP_TMP" ]]; then
rm -rf "$BOOTSTRAP_TMP"
fi
}
trap cleanup_boot EXIT
resolve_platform() {
case "$(uname -s)" in
Darwin) PLATFORM="macos" ;;
Linux) PLATFORM="linux" ;;
*) boot_die "SO não suportado: $(uname -s). Suportados: macOS e Linux." ;;
esac
}
load_installer() {
local script_dir=""
if [[ -n "${BASH_SOURCE[0]:-}" && -f "${BASH_SOURCE[0]}" ]]; then
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
if [[ -n "$script_dir" && -f "$script_dir/src/main.sh" ]]; then
SRC_DIR="$script_dir/src"
return 0
fi
command -v curl >/dev/null 2>&1 || boot_die "curl é obrigatório."
command -v tar >/dev/null 2>&1 || boot_die "tar é obrigatório."
[[ "$REF" =~ ^[A-Za-z0-9._/-]+$ ]] || boot_die "AI_MEMORY_MANAGER_REF inválido: $REF"
BOOTSTRAP_TMP="$(mktemp -d -t ai-memory-manager.XXXXXX)"
local url="https://codeload.github.com/${REPO_SLUG}/tar.gz/${REF}"
# O snapshot do instalador vem por HTTPS do GitHub (mesma origem de confiança do
# próprio script). A release do ai-memory, que é executada, é validada por SHA-256.
boot_log "Baixando instalador (${REF})..."
curl -fsSL --retry 3 --retry-delay 1 --connect-timeout 10 --max-time 120 \
-A "ai-memory-manager-bootstrap" "$url" -o "${BOOTSTRAP_TMP}/src.tar.gz"
tar -xzf "${BOOTSTRAP_TMP}/src.tar.gz" -C "$BOOTSTRAP_TMP"
local extracted
extracted="$(find "$BOOTSTRAP_TMP" -maxdepth 1 -type d -name 'ai-memory-manager-*' -print -quit)"
[[ -n "$extracted" && -f "$extracted/src/main.sh" ]] ||
boot_die "Falha ao extrair o instalador."
SRC_DIR="$extracted/src"
}
cleanup_all() {
cleanup || true
cleanup_boot
}
resolve_platform
load_installer
# shellcheck source=/dev/null
source "${SRC_DIR}/common.sh"
# shellcheck source=/dev/null
source "${SRC_DIR}/release.sh"
# shellcheck source=/dev/null
source "${SRC_DIR}/agents.sh"
# shellcheck source=/dev/null
source "${SRC_DIR}/commands.sh"
# shellcheck source=/dev/null
source "${SRC_DIR}/platform/${PLATFORM}.sh"
# shellcheck source=/dev/null
source "${SRC_DIR}/main.sh"
trap cleanup_all EXIT
ARCH="$(arch_normalize "$(uname -m)")"
platform_init_paths
main "$@"