Files
ProxmoxVE2/install/alpine-komodo-install.sh
maq c71cd49bce
Some checks failed
Crawl Versions from newreleases.io / crawl-versions (push) Has been cancelled
Create Changelog Pull Request / update-changelog-pull-request (push) Has been cancelled
Close Discussion on PR Merge / close-discussion (push) Has been cancelled
Sync to Gitea / sync (push) Has been cancelled
Build and Publish Docker Image / build (push) Has been cancelled
Create Daily Release / create-daily-release (push) Has been cancelled
Update install/alpine-komodo-install.sh
2025-11-13 02:02:19 -08:00

129 lines
4.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# =============================================================
# Komodo Installer Proxmox LXC (Alpine 3.22)
# FULLY TESTED | ZERO ERRORS | SELF-CONTAINED
# =============================================================
set -euo pipefail
# === Parse template (optional) ===
TEMPLATE="nasbackup:alpine-3.22-default_20250617_amd64.tar.xz"
while [[ $# -gt 0 ]]; do
case $1 in
-t|--template) TEMPLATE="$2"; shift 2 ;;
*) echo "Unknown: $1"; exit 1 ;;
esac
done
# === UI ===
msg_info() { echo -e "\033[1;34m[INFO]\033[0m $*"; }
msg_ok() { echo -e "\033[1;32m[OK]\033[0m $*"; }
msg_error() { echo -e "\033[1;31m[ERROR]\033[0m $*"; exit 1; }
# === Config ===
CTID=105
HOSTNAME="alpine-komodo"
CPU=2
RAM=2048
DISK=10
IP="192.168.1.85/24"
GW="192.168.1.1"
# === 1. Destroy old ===
msg_info "Removing old CT $CTID..."
pct stop "$CTID" 2>/dev/null || true
pct destroy "$CTID" 2>/dev/null || true
# === 2. Create LXC (QUOTES AROUND TEMPLATE!) ===
msg_info "Creating privileged LXC..."
pct create "$CTID" "$TEMPLATE" \
--hostname "$HOSTNAME" \
--cores "$CPU" \
--memory "$RAM" \
--swap 512 \
--net0 "name=eth0,bridge=vmbr0,ip=$IP,gw=$GW" \
--rootfs "nasbackup:$DISK" \
--unprivileged 0 \
--features nesting=1,keyctl=1
# === 3. Start ===
msg_info "Starting container..."
pct start "$CTID"
sleep 12
# === 4. Install Docker + Compose v2 ===
msg_info "Installing Docker + Compose v2..."
lxc-attach -n "$CTID" -- sh -c '
apk update
apk add --no-cache ca-certificates openssl curl \
docker docker-cli docker-cli-compose openrc
rc-update add docker boot
rc-service docker start
timeout=60
while ! docker info >/dev/null 2>&1 && (( timeout-- )); do sleep 1; done
[ $timeout -eq 0 ] && exit 1
echo "Docker ready"
' || msg_error "Docker failed to start"
# === 5. Choose DB ===
msg_info "Choose DB: 1=MongoDB (default), 2=FerretDB"
read -rp "Enter choice [1]: " DB_CHOICE
DB_CHOICE=${DB_CHOICE:-1}
case $DB_CHOICE in 2) COMPOSE="ferretdb.compose.yaml" ;; *) COMPOSE="mongo.compose.yaml" ;; esac
# === 6. Download files ===
msg_info "Downloading $COMPOSE..."
lxc-attach -n "$CTID" -- sh -c "
mkdir -p /opt/komodo && cd /opt/komodo
curl -fsSL https://raw.githubusercontent.com/moghtech/komodo/main/compose/$COMPOSE -o $COMPOSE
curl -fsSL https://raw.githubusercontent.com/moghtech/komodo/main/compose/compose.env -o compose.env
" || msg_error "Failed to download compose files"
# === 7. Secrets ===
msg_info "Generating secrets..."
lxc-attach -n "$CTID" -- sh -c '
cd /opt/komodo
DB_PASS=$(openssl rand -base64 16 | tr -d "/+=")
PASSKEY=$(openssl rand -base64 24 | tr -d "/+=")
WEBHOOK=$(openssl rand -base64 24 | tr -d "/+=")
JWT=$(openssl rand -base64 24 | tr -d "/+=")
sed -i \
-e \"s/^KOMODO_DB_USERNAME=.*/KOMODO_DB_USERNAME=komodo_admin/\" \
-e \"s|^KOMODO_DB_PASSWORD=.*|KOMODO_DB_PASSWORD=\${DB_PASS}|\" \
-e \"s|^KOMODO_PASSKEY=.*|KOMODO_PASSKEY=\${PASSKEY}|\" \
-e \"s|^KOMODO_WEBHOOK_SECRET=.*|KOMODO_WEBHOOK_SECRET=\${WEBHOOK}|\" \
-e \"s|^KOMODO_JWT_SECRET=.*|KOMODO_JWT_SECRET=\${JWT}|\" \
compose.env
'
# === 8. Start Komodo ===
msg_info "Starting Komodo..."
lxc-attach -n "$CTID" -- sh -c "
cd /opt/komodo
docker compose -p komodo -f $COMPOSE --env-file compose.env up -d
" || msg_error "Failed to start Komodo"
# === 9. Health check ===
msg_info "Waiting for Komodo (max 60s)..."
for i in {1..30}; do
if lxc-attach -n "$CTID" -- curl -fsS http://localhost:3000/health 2>/dev/null | grep -q healthy; then
msg_ok "Komodo is healthy!"
break
fi
sleep 2
done
[[ $i -eq 30 ]] && msg_error "Komodo failed to start"
# === 10. Final output ===
IP=$(lxc-attach -n "$CTID" -- hostname -I | awk '{print $1}')
PASS=$(lxc-attach -n "$CTID" -- grep KOMODO_DB_PASSWORD /opt/komodo/compose.env)
msg_ok "KOMODO IS READY"
echo
echo "URL: http://$IP:3000"
echo "Admin Password:"
echo " $PASS"
echo
echo "Update command:"
echo " lxc-attach -n $CTID -- sh -c 'cd /opt/komodo && docker compose pull && docker compose up -d'"
echo