refactor: simplify localagi.sh by removing redundant variables and streamlining update_script function

This commit is contained in:
John Doe
2026-03-04 10:16:45 -05:00
parent 6261ee8c34
commit 521c74d2ba

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
COMMUNITY_SCRIPTS_URL="${COMMUNITY_SCRIPTS_URL:-${COMMUNITY_SCRIPT_URL:-https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main}}" source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
source <(curl -fsSL "$COMMUNITY_SCRIPTS_URL/misc/build.func")
# Copyright (c) 2021-2026 community-scripts ORG # Copyright (c) 2021-2026 community-scripts ORG
# Author: GitHub Copilot # Author: GitHub Copilot
@@ -32,10 +31,7 @@ function update_script() {
exit 1 exit 1
fi fi
local update_performed="no"
if check_for_gh_release "localagi" "mudler/LocalAGI"; then if check_for_gh_release "localagi" "mudler/LocalAGI"; then
update_performed="yes"
msg_info "Stopping LocalAGI Service" msg_info "Stopping LocalAGI Service"
systemctl stop localagi systemctl stop localagi
msg_ok "Stopped LocalAGI Service" msg_ok "Stopped LocalAGI Service"
@@ -57,10 +53,8 @@ function update_script() {
rm -f "$env_backup" rm -f "$env_backup"
msg_ok "Restored Environment" msg_ok "Restored Environment"
fi fi
fi
BACKEND="external-llm" msg_ok "Configured LocalAGI backend mode: external-llm"
msg_ok "Configured LocalAGI backend mode: ${BACKEND}"
if [[ ! -f /opt/localagi/.env ]]; then if [[ ! -f /opt/localagi/.env ]]; then
msg_warn "Missing /opt/localagi/.env. Recreate by running install script again." msg_warn "Missing /opt/localagi/.env. Recreate by running install script again."
exit 1 exit 1
@@ -76,37 +70,32 @@ function update_script() {
fi fi
NODE_VERSION="24" setup_nodejs NODE_VERSION="24" setup_nodejs
GO_VERSION="latest" setup_go setup_go
if ! command -v bun >/dev/null 2>&1; then
msg_info "Installing Bun" msg_info "Installing Bun"
$STD npm install -g bun $STD npm install -g bun
msg_ok "Installed Bun" msg_ok "Installed Bun"
fi
msg_info "Building LocalAGI from source" msg_info "Building LocalAGI from source"
if ! ( (
cd /opt/localagi/webui/react-ui && cd /opt/localagi/webui/react-ui &&
$STD bun install && $STD bun install &&
$STD bun run build && $STD bun run build &&
cd /opt/localagi && cd /opt/localagi &&
$STD go build -o /usr/local/bin/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 }
msg_ok "Built LocalAGI from source" msg_ok "Built LocalAGI from source"
msg_info "Starting LocalAGI Service" msg_info "Starting LocalAGI Service"
if ! systemctl restart localagi; then systemctl restart localagi || {
msg_error "Failed to start LocalAGI service" msg_error "Failed to start LocalAGI service"
exit 1 exit 1
fi }
msg_ok "Started LocalAGI (${BACKEND})" msg_ok "Started LocalAGI (external-llm)"
if [[ "$update_performed" == "yes" ]]; then
msg_ok "Updated successfully!" msg_ok "Updated successfully!"
else
msg_ok "No update required. Rebuilt source and restarted service."
fi fi
exit exit
} }