-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
164 lines (134 loc) · 3.56 KB
/
install.sh
File metadata and controls
164 lines (134 loc) · 3.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
#!/usr/bin/env sh
set -eu
REPO="${AGENTOS_REPO:-SapienXai/AgentOS}"
INSTALL_ROOT="${AGENTOS_INSTALL_ROOT:-$HOME/.agentos}"
BIN_DIR="${AGENTOS_BIN_DIR:-$HOME/.local/bin}"
REQUESTED_VERSION="${AGENTOS_VERSION:-latest}"
ASSET_PLATFORM=""
ASSET_ARCH=""
require_command() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
detect_platform() {
case "$(uname -s)" in
Darwin)
ASSET_PLATFORM="darwin"
;;
Linux)
ASSET_PLATFORM="linux"
;;
*)
echo "Unsupported operating system: $(uname -s). Use install.ps1 on Windows." >&2
exit 1
;;
esac
case "$(uname -m)" in
arm64|aarch64)
ASSET_ARCH="arm64"
;;
x86_64|amd64)
ASSET_ARCH="x64"
;;
*)
echo "Unsupported CPU architecture: $(uname -m)" >&2
exit 1
;;
esac
}
assert_node_version() {
require_command node
if ! node -e 'const [major, minor] = process.versions.node.split(".").map(Number); process.exit(major > 20 || (major === 20 && minor >= 9) ? 0 : 1);'; then
echo "AgentOS requires Node.js 20.9 or newer." >&2
exit 1
fi
}
download_file() {
url="$1"
target="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$target"
return
fi
if command -v wget >/dev/null 2>&1; then
wget -qO "$target" "$url"
return
fi
echo "Missing downloader: install curl or wget first." >&2
exit 1
}
verify_checksum() {
checksum_file="$1"
artifact_file="$2"
if command -v shasum >/dev/null 2>&1; then
(
cd "$(dirname "$artifact_file")"
shasum -a 256 -c "$(basename "$checksum_file")"
)
return
fi
if command -v sha256sum >/dev/null 2>&1; then
(
cd "$(dirname "$artifact_file")"
sha256sum -c "$(basename "$checksum_file")"
)
return
fi
echo "No checksum tool found; skipping SHA-256 verification."
}
render_launcher() {
launcher_path="$1"
install_root="$2"
cat >"$launcher_path" <<EOF
#!/usr/bin/env sh
exec node "$install_root/package/bin/agentos.js" "\$@"
EOF
chmod +x "$launcher_path"
}
print_completion() {
launcher_path="$1"
echo "Installed AgentOS to $INSTALL_ROOT/package"
echo "Launcher: $launcher_path"
echo "Try: agentos doctor"
echo "Then: agentos start --open"
echo "Stop later: agentos stop"
echo "Remove later: agentos uninstall"
case ":$PATH:" in
*":$BIN_DIR:"*)
;;
*)
echo "Add $BIN_DIR to your PATH if 'agentos' is not found."
echo "Example:"
echo " export PATH=\"$BIN_DIR:\$PATH\""
;;
esac
}
detect_platform
assert_node_version
ARTIFACT_NAME="agentos-${ASSET_PLATFORM}-${ASSET_ARCH}.tgz"
CHECKSUM_NAME="${ARTIFACT_NAME}.sha256"
if [ "$REQUESTED_VERSION" = "latest" ]; then
RELEASE_PATH="latest/download"
else
RELEASE_PATH="download/agentos-v${REQUESTED_VERSION}"
fi
BASE_URL="https://github.com/${REPO}/releases/${RELEASE_PATH}"
ARTIFACT_URL="${BASE_URL}/${ARTIFACT_NAME}"
CHECKSUM_URL="${BASE_URL}/${CHECKSUM_NAME}"
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/agentos-install.XXXXXX")"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
ARTIFACT_FILE="$TMP_DIR/$ARTIFACT_NAME"
CHECKSUM_FILE="$TMP_DIR/$CHECKSUM_NAME"
LAUNCHER_PATH="$BIN_DIR/agentos"
echo "Downloading ${ARTIFACT_URL}"
download_file "$ARTIFACT_URL" "$ARTIFACT_FILE"
if download_file "$CHECKSUM_URL" "$CHECKSUM_FILE"; then
verify_checksum "$CHECKSUM_FILE" "$ARTIFACT_FILE"
fi
mkdir -p "$INSTALL_ROOT" "$BIN_DIR"
rm -rf "$INSTALL_ROOT/package"
tar -xzf "$ARTIFACT_FILE" -C "$INSTALL_ROOT"
render_launcher "$LAUNCHER_PATH" "$INSTALL_ROOT"
print_completion "$LAUNCHER_PATH"