fix: update source URL and improve Bun installation in LocalAGI scripts

This commit is contained in:
John Doe
2026-03-04 20:58:03 -05:00
parent b844eab504
commit 8a3d6f3a2b
2 changed files with 84 additions and 223 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/BillyOutlast/ProxmoxVED/LocalAGI/misc/build.func) source <(curl -sSL https://raw.githubusercontent.com/asylumexp/ProxmoxVED/main/misc/build.func)
# Copyright (c) 2021-2026 community-scripts ORG # Copyright (c) 2021-2026 community-scripts ORG
# Author: BillyOutlast # Author: BillyOutlast
@@ -7,7 +7,7 @@ source <(curl -fsSL https://raw.githubusercontent.com/BillyOutlast/ProxmoxVED/Lo
# Source: https://github.com/mudler/LocalAGI # Source: https://github.com/mudler/LocalAGI
APP="LocalAGI" APP="LocalAGI"
var_tags="${var_tags:-ai;agents}" var_tags="${var_tags:-ai,agents}"
var_cpu="${var_cpu:-2}" var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-4096}" var_ram="${var_ram:-4096}"
var_disk="${var_disk:-20}" var_disk="${var_disk:-20}"
@@ -23,17 +23,14 @@ catch_errors
function health_check() { function health_check() {
header_info header_info
if [[ ! -d /opt/localagi ]]; then if [[ ! -d /opt/localagi ]]; then
msg_error "LocalAGI not found at /opt/localagi" msg_error "LocalAGI not found at /opt/localagi"
return 1 return 1
fi fi
if ! systemctl is-active --quiet localagi; then if ! systemctl is-active --quiet localagi; then
msg_error "LocalAGI service not running" msg_error "LocalAGI service not running"
return 1 return 1
fi fi
msg_ok "Health check passed: LocalAGI installed and service running" msg_ok "Health check passed: LocalAGI installed and service running"
return 0 return 0
} }
@@ -43,142 +40,48 @@ function update_script() {
check_container_storage check_container_storage
check_container_resources check_container_resources
if [[ ! -d /opt/localagi || ! -f /etc/systemd/system/localagi.service ]]; then if [[ ! -d /opt/localagi || ! -f /opt/localagi/LOCALAGI_VERSION.txt ]]; then
msg_error "No ${APP} Installation Found!" msg_error "No ${APP} Installation Found!"
exit 1 exit 1
fi fi
if check_for_gh_release "localagi" "mudler/LocalAGI"; then if ! check_for_gh_release "localagi" "mudler/LocalAGI"; then
exit 0
fi
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"
msg_info "Backing up Environment" msg_info "Backing up Environment"
local env_backup local env_backup_file
local env_backup_valid=0 env_backup_file=$(mktemp)
if [[ -s /opt/localagi/.env ]]; then if cp /opt/localagi/.env "$env_backup_file"; then
env_backup="$(mktemp /tmp/localagi.env.XXXXXX)"
chmod 600 "$env_backup"
if cp /opt/localagi/.env "$env_backup" 2>/dev/null && [[ -s "$env_backup" ]]; then
env_backup_valid=1
msg_ok "Backed up Environment" msg_ok "Backed up Environment"
else else
rm -f "$env_backup" msg_warn "Failed to back up environment file"
env_backup=""
msg_warn "Failed to create valid environment backup"
fi
else
msg_warn "Skipping environment backup: /opt/localagi/.env missing or empty"
fi fi
msg_info "Checking latest LocalAGI release" msg_info "Updating LocalAGI"
# Determine installed version (if recorded) cd /opt
installed_version="" rm -rf localagi
if [[ -f /opt/localagi/LOCALAGI_VERSION.txt ]]; then fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
installed_version=$(grep -E '^Version:' /opt/localagi/LOCALAGI_VERSION.txt 2>/dev/null | head -n1 | awk -F': ' '{print $2}') || installed_version=""
fi
# Fetch latest tag from GitHub
latest_tag=$(curl -fsSL "https://api.github.com/repos/mudler/LocalAGI/releases/latest" | grep -E '"tag_name"' | head -n1 | sed -E 's/[^\"]*"([^"]+)".*/\1/' 2>/dev/null || true)
if [[ -n "$installed_version" && -n "$latest_tag" && "$installed_version" == "$latest_tag" ]]; then
msg_ok "LocalAGI is already up-to-date (version: $installed_version). Skipping update."
else
msg_info "Updating LocalAGI to ${latest_tag:-latest}"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
msg_ok "Updated LocalAGI" msg_ok "Updated LocalAGI"
fi
msg_info "Recording installed LocalAGI release tag"
release_tag=$(curl -fsSL "https://api.github.com/repos/mudler/LocalAGI/releases/latest" | grep -E '"tag_name"' | head -n1 | sed -E 's/[^\"]*"([^"]+)".*/\1/' 2>/dev/null || true)
if [[ -n "$release_tag" ]]; then
cat >/opt/localagi/LOCALAGI_VERSION.txt <<EOF
Version: ${release_tag}
InstallDate: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
InstallMethod: ct
Source: mudler/LocalAGI
EOF
msg_ok "Recorded release: $release_tag"
else
msg_warn "Could not determine release tag for LocalAGI"
fi
# Running service as root per project guidelines (AI.md)
mkdir -p /etc/systemd/system/localagi.service.d
override_file=/etc/systemd/system/localagi.service.d/override.conf
if [[ ! -f "$override_file" ]]; then
msg_info "Creating systemd drop-in override for LocalAGI"
cat <<'EOF' >"$override_file"
[Service]
User=root
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
AmbientCapabilities=
StandardOutput=journal
StandardError=journal
EOF
systemctl daemon-reload
msg_ok "Installed systemd drop-in"
else
msg_info "Systemd drop-in exists; ensuring required directives"
for d in "User=root" "NoNewPrivileges=true" "PrivateTmp=true" "ProtectSystem=full" "ProtectHome=true" "AmbientCapabilities=" "StandardOutput=journal" "StandardError=journal"; do
if ! grep -q "^${d}" "$override_file" 2>/dev/null; then
echo "$d" >>"$override_file"
fi
done
systemctl daemon-reload
fi
if [[ "${env_backup_valid:-0}" == "1" && -n "${env_backup:-}" && -s "$env_backup" ]]; then
msg_info "Restoring Environment" msg_info "Restoring Environment"
cp "$env_backup" /opt/localagi/.env if [[ -f "$env_backup_file" ]]; then
rm -f "$env_backup" cp "$env_backup_file" /opt/localagi/.env
rm -f "$env_backup_file"
msg_ok "Restored Environment" msg_ok "Restored Environment"
fi fi
msg_ok "Backend mode: external-llm"
if [[ ! -f /opt/localagi/.env ]]; then
msg_warn "Missing /opt/localagi/.env. Recreate by running install script again."
exit 1
fi
if grep -q '^LOCALAGI_LLM_API_URL=http://127.0.0.1:8081$' /opt/localagi/.env; then
if grep -q '^LOCALAGI_LLM_API_URL=' /opt/localagi/.env; then
sed -i 's|^LOCALAGI_LLM_API_URL=.*|LOCALAGI_LLM_API_URL=http://127.0.0.1:11434/v1|' /opt/localagi/.env
else
echo "LOCALAGI_LLM_API_URL=http://127.0.0.1:11434/v1" >>/opt/localagi/.env
fi
msg_warn "Migrated LOCALAGI_LLM_API_URL from 127.0.0.1:8081 to 127.0.0.1:11434/v1"
fi
NODE_VERSION="24" setup_nodejs
setup_go
msg_info "Installing Bun"
if ! command -v bun >/dev/null 2>&1; then
if curl -fsSL https://bun.sh/install | bash -s -- --no-chmod >/dev/null 2>&1; then
msg_ok "Installed Bun (official installer)"
if [[ -x /root/.bun/bin/bun ]]; then
ln -sf /root/.bun/bin/bun /usr/local/bin/bun || msg_warn "Failed to symlink bun to /usr/local/bin"
fi
else
msg_warn "Official Bun installer failed, falling back to npm"
$STD npm install -g bun || { msg_error "Failed to install Bun"; exit 1; }
msg_ok "Installed Bun (npm)"
fi
else
msg_ok "Bun already installed"
fi
msg_info "Building LocalAGI from source" msg_info "Building LocalAGI from source"
( (
cd /opt/localagi/webui/react-ui && cd /opt/localagi/webui/react-ui &&
$STD bun install && bun install &&
$STD bun run build && bun run build &&
cd /opt/localagi && cd /opt/localagi &&
$STD go build -o /usr/local/bin/localagi go build -o /usr/local/bin/localagi
) || { ) || {
msg_error "Failed to build LocalAGI from source" msg_error "Failed to build LocalAGI from source"
exit 1 exit 1
@@ -186,19 +89,12 @@ EOF
msg_ok "Built LocalAGI from source" msg_ok "Built LocalAGI from source"
msg_info "Starting LocalAGI Service" msg_info "Starting LocalAGI Service"
systemctl restart localagi || { systemctl restart localagi
msg_error "Failed to start LocalAGI service" msg_ok "Started LocalAGI"
exit 1
}
msg_ok "Started LocalAGI (external-llm)"
# Run health check after start health_check
health_check || {
msg_warn "Health check failed after update; check service logs"
}
msg_ok "Updated successfully!" msg_ok "Updated Successfully"
fi
exit exit
} }

View File

@@ -14,7 +14,6 @@ setting_up_container
network_check network_check
update_os update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt install -y build-essential $STD apt install -y build-essential
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
@@ -24,15 +23,14 @@ setup_go
msg_info "Installing Bun" msg_info "Installing Bun"
if ! command -v bun >/dev/null 2>&1; then if ! command -v bun >/dev/null 2>&1; then
msg_info "Installing Bun (official installer)"
if curl -fsSL https://bun.sh/install | bash -s -- --no-chmod >/dev/null 2>&1; then if curl -fsSL https://bun.sh/install | bash -s -- --no-chmod >/dev/null 2>&1; then
msg_ok "Installed Bun (official installer)" msg_ok "Installed Bun (official installer)"
if [[ -x /root/.bun/bin/bun ]]; then if [[ -x /root/.bun/bin/bun ]]; then
ln -sf /root/.bun/bin/bun /usr/local/bin/bun || msg_warn "Failed to symlink bun to /usr/local/bin" ln -sf /root/.bun/bin/bun /usr/local/bin/bun
fi fi
else else
msg_warn "Official Bun installer failed, falling back to npm" msg_warn "Official Bun installer failed, falling back to npm"
$STD npm install -g bun || { msg_error "Failed to install Bun"; exit 1; } $STD npm install -g bun
msg_ok "Installed Bun (npm)" msg_ok "Installed Bun (npm)"
fi fi
else else
@@ -41,29 +39,11 @@ fi
fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi" fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
if [[ ! -d /opt/localagi/webui/react-ui ]]; then msg_info "Recording installed version"
msg_error "Unexpected release layout: /opt/localagi/webui/react-ui not found" record_gh_release_version "localagi" "mudler/LocalAGI"
exit 1 msg_ok "Recorded installed version"
fi
# Record installed release tag for update checks (full metadata)
msg_info "Recording installed LocalAGI release tag"
release_tag=$(curl -fsSL "https://api.github.com/repos/mudler/LocalAGI/releases/latest" | grep -E '"tag_name"' | head -n1 | sed -E 's/[^\"]*"([^"]+)".*/\1/' 2>/dev/null || true)
if [[ -n "$release_tag" ]]; then
cat >/opt/localagi/LOCALAGI_VERSION.txt <<EOF
Version: ${release_tag}
InstallDate: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
InstallMethod: ${METHOD:-install}
Source: mudler/LocalAGI
EOF
msg_ok "Recorded release: $release_tag"
else
msg_warn "Could not determine release tag for LocalAGI"
fi
mkdir -p /opt/localagi/pool mkdir -p /opt/localagi/pool
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
LOCALAGI_MULTIMODAL_MODEL=moondream2-20250414 LOCALAGI_MULTIMODAL_MODEL=moondream2-20250414
@@ -77,30 +57,32 @@ chmod 600 /opt/localagi/.env
msg_ok "Configured LocalAGI" msg_ok "Configured LocalAGI"
msg_info "Building LocalAGI from source" msg_info "Building LocalAGI from source"
(
# Running service as root per project guidelines (AI.md) cd /opt/localagi/webui/react-ui &&
bun install &&
cd /opt/localagi/webui/react-ui || { msg_error "Missing webui/react-ui directory"; exit 1; } bun run build &&
cd /opt/localagi &&
msg_info "Running bun install" go build -o /usr/local/bin/localagi
$STD bun install || { msg_error "bun install failed"; exit 1; } ) || exit 1
msg_info "Building web UI"
$STD bun run build || { msg_error "bun build failed"; exit 1; }
cd /opt/localagi || { msg_error "Missing /opt/localagi"; exit 1; }
msg_info "Building Go binary"
$STD go build -o /usr/local/bin/localagi || { msg_error "go build failed"; exit 1; }
chmod 755 /usr/local/bin/localagi || msg_warn "Failed to chmod /usr/local/bin/localagi"
msg_ok "Built LocalAGI from source" msg_ok "Built LocalAGI from source"
msg_info "Creating Service" msg_info "Creating Service"
service_path="/etc/systemd/system/localagi.service"
cat <<EOF >"$service_path"
[Unit]
Description=LocalAGI
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/localagi
ExecStart=/usr/local/bin/localagi
[Install]
WantedBy=multi-user.target
EOF
mkdir -p /etc/systemd/system/localagi.service.d mkdir -p /etc/systemd/system/localagi.service.d
override_file=/etc/systemd/system/localagi.service.d/override.conf override_file=/etc/systemd/system/localagi.service.d/override.conf
if [[ ! -f "$override_file" ]]; then cat <<'EOF' >"$override_file"
msg_info "Creating systemd drop-in override for LocalAGI"
cat <<'EOF' >"$override_file"
[Service] [Service]
User=root User=root
NoNewPrivileges=true NoNewPrivileges=true
@@ -111,32 +93,15 @@ AmbientCapabilities=
StandardOutput=journal StandardOutput=journal
StandardError=journal StandardError=journal
EOF EOF
systemctl daemon-reload systemctl daemon-reload
else systemd-analyze verify localagi.service
msg_info "Systemd drop-in exists; ensuring required directives" msg_ok "Created Service"
# Ensure required directives present; add if missing
for d in "User=root" "NoNewPrivileges=true" "PrivateTmp=true" "ProtectSystem=full" "ProtectHome=true" "AmbientCapabilities=" "StandardOutput=journal" "StandardError=journal"; do
if ! grep -q "^${d}" "$override_file" 2>/dev/null; then
echo "$d" >>"$override_file"
fi
done
systemctl daemon-reload
fi
LOCALAGI_SERVICE_NEEDS_RECOVERY=1 msg_info "Starting LocalAGI Service"
systemctl enable -q --now localagi systemctl enable -q --now localagi
msg_ok "Created Service (drop-in override)" msg_ok "Started LocalAGI Service"
if ! systemctl is-active -q localagi; then
msg_error "Failed to start LocalAGI service"
exit 1
fi
msg_info "Cleaning up package cache"
$STD apt-get -y autoremove || msg_warn "apt autoremove failed"
$STD apt-get -y autoclean || msg_warn "apt autoclean failed"
msg_ok "Cleaned package cache"
cleanup
motd_ssh motd_ssh
customize customize
cleanup_lxc cleanup_lxc