#!/usr/bin/env bash # ============================================================================= # Koapanel — installer online. # # curl -fsSL https://get.koapanel.app | sudo bash # # Su un server Ubuntu 24.04 LTS appena creato (x86_64 o arm64), come root: # 1. controlla sistema, architettura e che il server sia "pulito"; # 2. scarica dal canale ufficiale (console.koapanel.app/updates) il # manifest firmato, ne verifica la firma ed25519 con la chiave pubblica # scritta qui sotto, poi scarica il pannello e lo script di installazione # e ne verifica lo SHA-256; # 3. esegue l'installazione (deploy/install.sh): nginx, PHP-FPM, MariaDB, # certbot, firewall, phpMyAdmin, strumenti WordPress, ClamAV, pannello; # 4. collega il pannello a console.koapanel.app (licenze e aggiornamenti). # Parte con il piano Gratuito (fino a 3 siti, uso personale). # # Variabili facoltative: # KOAPANEL_EMAIL=tu@dominio.it email per Let's Encrypt # KOAPANEL_MAIL=1 attiva subito anche la posta # KOAPANEL_PORT=8443 porta del pannello # KOAPANEL_FORCE=1 installa anche se il server non sembra nuovo # KOAPANEL_DOWNLOAD_ONLY=1 scarica e verifica soltanto (nessuna modifica) # KOAPANEL_CHANNEL=URL canale (solo per prove) # ============================================================================= set -Eeuo pipefail umask 077 CHANNEL="${KOAPANEL_CHANNEL:-https://console.koapanel.app/updates/stable.json}" CONSOLE="https://console.koapanel.app" URL_PREFIX="${CONSOLE}/updates/" if [[ -n "${KOAPANEL_CHANNEL:-}" ]]; then URL_PREFIX="${KOAPANEL_CHANNEL%/stable.json}/"; fi # Chiave pubblica degli aggiornamenti (agent/pkg/licproto UpdatePublicKeys). UPDATE_PUBKEY='-----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAlxlyG0YNNSkuMDAf4Hh8dit7MXc01J+PNfP5BNvrA0U= -----END PUBLIC KEY-----' if [[ -t 1 ]]; then B=$'\033[1m'; G=$'\033[1;32m'; Y=$'\033[1;33m'; R=$'\033[1;31m'; N=$'\033[0m'; else B= G= Y= R= N=; fi say() { printf '%s==>%s %s\n' "$G" "$N" "$*"; } warn() { printf '%s[!]%s %s\n' "$Y" "$N" "$*" >&2; } die() { printf '%s[x]%s %s\n' "$R" "$N" "$*" >&2; exit 1; } main() { printf '\n%sKoapanel%s — installazione\n\n' "$B" "$N" # ------------------------------------------------------------- controlli [[ $EUID -eq 0 ]] || die "serve root: curl -fsSL https://get.koapanel.app | sudo bash" [[ -r /etc/os-release ]] || die "sistema non riconosciuto" . /etc/os-release [[ "${ID:-}" == "ubuntu" && "${VERSION_ID:-}" == "24.04" ]] || die "serve Ubuntu 24.04 LTS (trovato: ${PRETTY_NAME:-sconosciuto})" local arch case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) die "architettura non supportata: $(uname -m) (servono x86_64 o arm64)" ;; esac if [[ -f /etc/panel/agent.yaml ]]; then die "Koapanel è già installato su questo server (/etc/panel/agent.yaml). Per aggiornarlo usa la pagina Aggiornamenti del pannello." fi local found=() [[ -d /usr/local/cpanel ]] && found+=("cPanel") [[ -d /usr/local/psa ]] && found+=("Plesk") [[ -d /usr/local/directadmin ]] && found+=("DirectAdmin") command -v apache2 >/dev/null 2>&1 && found+=("Apache") [[ -d /etc/nginx/sites-enabled ]] && [[ -n "$(ls -A /etc/nginx/sites-enabled 2>/dev/null | grep -v '^default$' || true)" ]] && found+=("siti nginx") command -v mysqld >/dev/null 2>&1 && found+=("MySQL/MariaDB") if ((${#found[@]})); then warn "Questo server non sembra nuovo: ${found[*]}." warn "Koapanel va installato su un server Ubuntu 24.04 appena creato: potrebbe sovrascrivere configurazioni esistenti." [[ "${KOAPANEL_FORCE:-0}" == "1" ]] || die "installazione annullata (per procedere comunque: KOAPANEL_FORCE=1)" fi local mem_mb mem_mb=$(awk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo 2>/dev/null || echo 0) if ((mem_mb > 0 && mem_mb < 1800)); then warn "Memoria: ${mem_mb} MB. Consigliati almeno 2 GB (sotto ~1,5 GB l'antivirus ClamAV non viene installato)." fi # ------------------------------------------------------------- strumenti local need=() for c in curl openssl sha256sum python3 base64; do command -v "$c" >/dev/null 2>&1 || need+=("$c"); done if ((${#need[@]})); then say "Installo gli strumenti mancanti: ${need[*]}" export DEBIAN_FRONTEND=noninteractive apt-get update -q >/dev/null apt-get install -y -q --no-install-recommends curl ca-certificates openssl coreutils python3 >/dev/null fi # ------------------------------------------------------------- download WORKDIR="$(mktemp -d /tmp/koapanel.XXXXXX)" trap 'rm -rf "${WORKDIR:-}"' EXIT cd "$WORKDIR" say "Scarico il manifest firmato da ${CHANNEL}" curl -fsSL --proto '=https' --tlsv1.2 --retry 3 -o stable.json "$CHANNEL" || die "canale non raggiungibile: $CHANNEL" curl -fsSL --proto '=https' --tlsv1.2 --retry 3 -o stable.json.sig "${CHANNEL}.sig" || die "firma del manifest non raggiungibile" say "Verifico la firma ed25519 del manifest" printf '%s\n' "$UPDATE_PUBKEY" > update.pub base64 -d stable.json.sig > stable.sig 2>/dev/null || die "firma del manifest non leggibile" openssl pkeyutl -verify -pubin -inkey update.pub -rawin -in stable.json -sigfile stable.sig >/dev/null 2>&1 \ || die "FIRMA NON VALIDA: il manifest non è stato firmato da Koapanel. Installazione annullata." local info version bin_url bin_sha bin_size inst_url inst_sha inst_size info="$(python3 - "$arch" "$URL_PREFIX" <<'PY' import json, sys arch, prefix = sys.argv[1], sys.argv[2] m = json.load(open("stable.json")) if m.get("product") != "panel": sys.exit("prodotto inatteso") arts = m.get("artifacts", {}) out = [m["version"]] for key in ("linux-" + arch, "linux-installer"): a = arts.get(key) if not a: sys.exit("il manifest non contiene " + key) if not a["url"].startswith(prefix): sys.exit("indirizzo inatteso: " + a["url"]) out += [a["url"], a["sha256"].lower(), str(a["size"])] print(" ".join(out)) PY )" || die "manifest non valido" read -r version bin_url bin_sha bin_size inst_url inst_sha inst_size <<<"$info" [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "versione non valida nel manifest" say "Versione ${B}${version}${N} (${arch})" local bar=(-s) [[ -t 2 ]] && bar=(--progress-bar) fetch() { # url sha size out curl -fSL "${bar[@]}" --proto '=https' --tlsv1.2 --retry 3 -o "$4" "$1" || die "download non riuscito: $1" [[ "$(stat -c %s "$4")" == "$3" ]] || die "dimensione errata: $1" echo "$2 $4" | sha256sum -c --status - || die "SHA-256 errato: $1 (file alterato o corrotto)" } say "Scarico il pannello" fetch "$bin_url" "$bin_sha" "$bin_size" panel-agent say "Scarico lo script di installazione" fetch "$inst_url" "$inst_sha" "$inst_size" install.sh chmod 755 panel-agent install.sh say "File verificati: firma del manifest e SHA-256 corretti." if [[ "${KOAPANEL_DOWNLOAD_ONLY:-0}" == "1" ]]; then ./panel-agent version 2>/dev/null || true say "Solo download (KOAPANEL_DOWNLOAD_ONLY=1): nessuna modifica al server." return 0 fi # ------------------------------------------------------------- installazione local log=/root/koapanel-install.log say "Installo Koapanel ${version}: servono di solito 5-10 minuti." : > "$log" chmod 600 "$log" if ! PANEL_BINARY=./panel-agent PANEL_LE_EMAIL="${KOAPANEL_EMAIL:-}" PANEL_MAIL="${KOAPANEL_MAIL:-0}" PANEL_PORT="${KOAPANEL_PORT:-8443}" \ bash ./install.sh &1 | tee -a "$log"; then die "installazione non riuscita: guarda $log" fi # ------------------------------------------------------------- collegamento alla console say "Collego il pannello a console.koapanel.app (licenze e aggiornamenti)" local st=/var/lib/panel install -d -m 700 "$st/license" "$st/update" if [[ ! -s "$st/license/settings.json" ]]; then printf '{"checkoutUrl":"%s/checkout","adminUpgradeUrl":"","licenseServerUrl":"%s"}\n' "$CONSOLE" "$CONSOLE" > "$st/license/settings.json" chmod 600 "$st/license/settings.json" fi if [[ ! -s "$st/update/settings.json" ]]; then printf '{"mode":"notify","windowStart":"03:00","windowEnd":"05:00","channelUrl":"%s"}\n' "$CHANNEL" > "$st/update/settings.json" chmod 600 "$st/update/settings.json" fi systemctl restart panel-agent.service 2>/dev/null || true local ip port ip="$(hostname -I 2>/dev/null | awk '{print $1}')" port="${KOAPANEL_PORT:-8443}" printf '\n%s============================================================%s\n' "$G" "$N" printf ' %sKoapanel %s è installato.%s\n\n' "$B" "$version" "$N" printf ' Pannello: https://%s:%s/ (certificato autofirmato al primo accesso)\n' "$ip" "$port" printf ' Credenziali: nome utente e password dell'"'"'amministratore sono qui sopra\n' printf ' e in %s (leggibile solo da root):\n' "$log" printf ' salvale in un gestore di password, poi cancella il file.\n' printf ' Piano: Gratuito (fino a 3 siti, uso personale).\n' printf ' Per più siti: nel pannello, Piano e licenza › Passa a…\n' printf ' Manuale: https://koapanel.app/documentazione/\n' printf '%s============================================================%s\n\n' "$G" "$N" } main "$@"