refactor: streamline localagi-install.sh by removing redundant comments and simplifying build process
This commit is contained in:
@@ -7,99 +7,15 @@
|
|||||||
|
|
||||||
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
|
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
|
||||||
APP="LocalAGI"
|
APP="LocalAGI"
|
||||||
|
|
||||||
# Load common UI/helpers and perform standard container bootstrap lifecycle.
|
|
||||||
# - `color`, `verb_ip6`, `catch_errors`: logging/error behavior
|
|
||||||
# - `setting_up_container`, `network_check`, `update_os`: baseline prep/update
|
|
||||||
color
|
color
|
||||||
verb_ip6
|
verb_ip6
|
||||||
catch_errors
|
catch_errors
|
||||||
setting_up_container
|
setting_up_container
|
||||||
network_check
|
network_check
|
||||||
update_os
|
update_os
|
||||||
header_content=""
|
|
||||||
if declare -f get_header >/dev/null 2>&1; then
|
|
||||||
header_content=$(get_header 2>/dev/null || true)
|
|
||||||
fi
|
|
||||||
if [[ -n "$header_content" ]]; then
|
|
||||||
echo "$header_content"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build LocalAGI from source using upstream workflow:
|
|
||||||
# - Build frontend in `webui/react-ui` with Bun
|
|
||||||
# - Build backend binary with Go to `/usr/local/bin/localagi`
|
|
||||||
build_localagi_source() {
|
|
||||||
msg_info "Building LocalAGI from source"
|
|
||||||
cd /opt/localagi/webui/react-ui || return 1
|
|
||||||
$STD bun install || return 1
|
|
||||||
$STD bun run build || return 1
|
|
||||||
cd /opt/localagi || return 1
|
|
||||||
$STD go build -o /usr/local/bin/localagi || return 1
|
|
||||||
msg_ok "Built LocalAGI from source"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Generic command retry helper with linear backoff.
|
|
||||||
# Usage: retry_cmd <attempts> <base_delay_seconds> <command> [args...]
|
|
||||||
retry_cmd() {
|
|
||||||
local max_attempts="$1"
|
|
||||||
local base_delay="$2"
|
|
||||||
shift 2
|
|
||||||
local attempt=1
|
|
||||||
while [[ $attempt -le $max_attempts ]]; do
|
|
||||||
if "$@"; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [[ $attempt -lt $max_attempts ]]; then
|
|
||||||
msg_warn "Command failed (attempt ${attempt}/${max_attempts}): $*"
|
|
||||||
sleep $((base_delay * attempt))
|
|
||||||
fi
|
|
||||||
attempt=$((attempt + 1))
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Recovery path for transient apt repository/index failures.
|
|
||||||
# Especially useful for Hash Sum mismatch and stale list states.
|
|
||||||
apt_recover_indexes() {
|
|
||||||
rm -rf /var/lib/apt/lists/partial/* /var/lib/apt/lists/* 2>/dev/null || true
|
|
||||||
$STD apt clean
|
|
||||||
$STD apt update
|
|
||||||
}
|
|
||||||
|
|
||||||
# Small wrappers so retry helper executes apt commands in current shell context.
|
|
||||||
# This avoids subshell issues with helper wrappers like `$STD` (e.g. `silent`).
|
|
||||||
apt_update_cmd() {
|
|
||||||
$STD apt update
|
|
||||||
}
|
|
||||||
|
|
||||||
apt_install_cmd() {
|
|
||||||
$STD apt install -y "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
apt_install_fix_missing_cmd() {
|
|
||||||
$STD apt install -y --fix-missing "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Resilient package install flow:
|
|
||||||
# 1) Retry normal install
|
|
||||||
# 2) If still failing, clean apt state + refresh indexes
|
|
||||||
# 3) Retry with `--fix-missing`
|
|
||||||
install_apt_packages_resilient() {
|
|
||||||
if retry_cmd 3 5 apt_install_cmd "$@"; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
msg_warn "APT install failed; attempting index recovery and retry"
|
|
||||||
if ! retry_cmd 2 5 apt_recover_indexes; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
retry_cmd 2 5 apt_install_fix_missing_cmd "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install base tooling needed to fetch/build/run LocalAGI.
|
|
||||||
msg_info "Installing Dependencies"
|
msg_info "Installing Dependencies"
|
||||||
install_apt_packages_resilient \
|
$STD apt install -y \
|
||||||
curl \
|
curl \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
git \
|
git \
|
||||||
@@ -107,32 +23,21 @@ install_apt_packages_resilient \
|
|||||||
build-essential
|
build-essential
|
||||||
msg_ok "Installed Dependencies"
|
msg_ok "Installed Dependencies"
|
||||||
|
|
||||||
# Install language/runtime toolchains used by LocalAGI source build.
|
|
||||||
# - Node.js: frontend/Bun ecosystem compatibility
|
|
||||||
# - Go: backend binary build
|
|
||||||
NODE_VERSION="24" setup_nodejs
|
NODE_VERSION="24" setup_nodejs
|
||||||
GO_VERSION="latest" setup_go
|
GO_VERSION="latest" setup_go
|
||||||
|
|
||||||
# Install Bun package manager (if not already present).
|
|
||||||
msg_info "Installing Bun"
|
msg_info "Installing Bun"
|
||||||
if ! command -v bun >/dev/null 2>&1; then
|
$STD npm install -g bun
|
||||||
$STD npm install -g bun
|
|
||||||
fi
|
|
||||||
msg_ok "Installed Bun"
|
msg_ok "Installed Bun"
|
||||||
|
|
||||||
# Pull latest LocalAGI source snapshot from GitHub release tarball.
|
|
||||||
msg_info "Fetching LocalAGI Source"
|
msg_info "Fetching LocalAGI Source"
|
||||||
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
|
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
|
||||||
msg_ok "Fetched LocalAGI Source"
|
msg_ok "Fetched LocalAGI Source"
|
||||||
|
|
||||||
# Configure external-LLM mode and prepare persistent state directory.
|
|
||||||
BACKEND="external-llm"
|
BACKEND="external-llm"
|
||||||
mkdir -p /opt/localagi/pool
|
mkdir -p /opt/localagi/pool
|
||||||
msg_ok "Configured LocalAGI backend mode: ${BACKEND}"
|
msg_ok "Configured LocalAGI backend mode: ${BACKEND}"
|
||||||
|
|
||||||
# Generate runtime configuration file used by systemd service.
|
|
||||||
# Note: `LOCALAGI_LLM_API_URL` points to an OpenAI-compatible backend endpoint.
|
|
||||||
# Defaulting to Ollama's OpenAI-compatible API avoids a dead 127.0.0.1:8081 endpoint.
|
|
||||||
msg_info "Configuring LocalAGI"
|
msg_info "Configuring LocalAGI"
|
||||||
cat <<EOF >/opt/localagi/.env
|
cat <<EOF >/opt/localagi/.env
|
||||||
LOCALAGI_MODEL=gemma-3-4b-it-qat
|
LOCALAGI_MODEL=gemma-3-4b-it-qat
|
||||||
@@ -146,14 +51,19 @@ EOF
|
|||||||
chmod 600 /opt/localagi/.env
|
chmod 600 /opt/localagi/.env
|
||||||
msg_ok "Configured LocalAGI"
|
msg_ok "Configured LocalAGI"
|
||||||
|
|
||||||
# Build source tree into executable binary.
|
msg_info "Building LocalAGI from source"
|
||||||
if ! build_localagi_source; then
|
if ! (
|
||||||
|
cd /opt/localagi/webui/react-ui &&
|
||||||
|
$STD bun install &&
|
||||||
|
$STD bun run build &&
|
||||||
|
cd /opt/localagi &&
|
||||||
|
$STD go build -o /usr/local/bin/localagi
|
||||||
|
); then
|
||||||
msg_error "Failed to build LocalAGI from source"
|
msg_error "Failed to build LocalAGI from source"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
msg_ok "Built LocalAGI from source"
|
||||||
|
|
||||||
# Create and start systemd unit for LocalAGI.
|
|
||||||
# The service reads `/opt/localagi/.env` at runtime.
|
|
||||||
msg_info "Creating Service"
|
msg_info "Creating Service"
|
||||||
cat <<EOF >/etc/systemd/system/localagi.service
|
cat <<EOF >/etc/systemd/system/localagi.service
|
||||||
[Unit]
|
[Unit]
|
||||||
@@ -175,14 +85,12 @@ systemctl daemon-reload
|
|||||||
systemctl enable -q --now localagi
|
systemctl enable -q --now localagi
|
||||||
msg_ok "Created Service"
|
msg_ok "Created Service"
|
||||||
|
|
||||||
# Verify service health before exiting installer.
|
|
||||||
if ! systemctl is-active -q localagi; then
|
if ! systemctl is-active -q localagi; then
|
||||||
msg_error "Failed to start LocalAGI service"
|
msg_error "Failed to start LocalAGI service"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
msg_ok "Started LocalAGI (${BACKEND})"
|
msg_ok "Started LocalAGI (${BACKEND})"
|
||||||
|
|
||||||
# Standard post-install housekeeping from shared framework.
|
|
||||||
motd_ssh
|
motd_ssh
|
||||||
customize
|
customize
|
||||||
cleanup_lxc
|
cleanup_lxc
|
||||||
|
|||||||
Reference in New Issue
Block a user