#!/usr/bin/env bash set -euo pipefail PANEL_URL='' NODE_PUBLIC_KEY='' while [[ $# -gt 0 ]]; do case "$1" in --panel) PANEL_URL="${2:-}"; shift 2;; --key) NODE_PUBLIC_KEY="${2:-}"; shift 2;; *) echo 'Usage: bash install-node.sh --panel https://panel.example.com --key "ssh-ed25519 ..."' >&2; exit 1;; esac done [[ $EUID -eq 0 ]] || { echo 'Exécute ce script en root.' >&2; exit 1; } [[ "$PANEL_URL" =~ ^https://[a-zA-Z0-9.-]+(:[0-9]+)?$ ]] || { echo 'URL du panel HTTPS invalide.' >&2; exit 1; } [[ "$NODE_PUBLIC_KEY" =~ ^ssh-ed25519\ [A-Za-z0-9+/=]+(\ [a-zA-Z0-9@._-]+)?$ ]] || { echo 'Clé publique ED25519 invalide.' >&2; exit 1; } export DEBIAN_FRONTEND=noninteractive apt-get update NEEDRESTART_MODE=l apt-get install -y python3 sudo openssh-server ca-certificates curl e2fsprogs if ! command -v docker >/dev/null 2>&1; then NEEDRESTART_MODE=l apt-get install -y docker.io fi systemctl enable --now docker install -d -m 0755 /usr/local/lib/greenlight-panel STAGING_DIR=$(mktemp -d) trap 'rm -rf "$STAGING_DIR"' EXIT for ASSET in node.py runtime.py operations.py advanced.py minecraft.py Dockerfile Sftp.Dockerfile; do curl --proto '=https' --tlsv1.2 -fsS "$PANEL_URL/agent/$ASSET" -o "$STAGING_DIR/$ASSET" done python3 -m py_compile "$STAGING_DIR/node.py" "$STAGING_DIR/runtime.py" "$STAGING_DIR/operations.py" "$STAGING_DIR/advanced.py" "$STAGING_DIR/minecraft.py" install -o root -g root -m 0755 "$STAGING_DIR/node.py" /usr/local/sbin/greenlight-panel-node install -o root -g root -m 0644 "$STAGING_DIR/operations.py" /usr/local/lib/greenlight-panel/operations.py install -o root -g root -m 0644 "$STAGING_DIR/runtime.py" /usr/local/lib/greenlight-panel/runtime.py install -o root -g root -m 0644 "$STAGING_DIR/minecraft.py" /usr/local/lib/greenlight-panel/minecraft.py install -o root -g root -m 0644 "$STAGING_DIR/advanced.py" /usr/local/lib/greenlight-panel/advanced.py install -o root -g root -m 0644 "$STAGING_DIR/Sftp.Dockerfile" /usr/local/lib/greenlight-panel/Sftp.Dockerfile install -o root -g root -m 0644 "$STAGING_DIR/Dockerfile" /usr/local/lib/greenlight-panel/Dockerfile if ! id glp-node >/dev/null 2>&1; then useradd --system --create-home --home-dir /var/lib/glp-node --shell /bin/sh glp-node fi passwd -l glp-node >/dev/null install -d -o root -g root -m 0755 /var/lib/glp-node install -d -o root -g root -m 0755 /var/lib/glp-node/.ssh AUTH_FILE=/var/lib/glp-node/.ssh/authorized_keys KEY_LINE="restrict,command=\"sudo -n /usr/local/sbin/greenlight-panel-node\" $NODE_PUBLIC_KEY" touch "$AUTH_FILE" if ! grep -Fqx "$KEY_LINE" "$AUTH_FILE"; then printf '%s\n' "$KEY_LINE" >> "$AUTH_FILE" fi chown root:root "$AUTH_FILE" chmod 0644 "$AUTH_FILE" printf '%s\n' 'glp-node ALL=(root) NOPASSWD: /usr/local/sbin/greenlight-panel-node ""' > /etc/sudoers.d/greenlight-panel-node chmod 0440 /etc/sudoers.d/greenlight-panel-node visudo -cf /etc/sudoers.d/greenlight-panel-node cat > /etc/systemd/system/greenlight-panel-volumes.service <<'UNIT' [Unit] Description=Restore Greenlight Panel game volumes After=local-fs.target docker.service Requires=docker.service [Service] Type=oneshot ExecStart=/usr/local/sbin/greenlight-panel-node --restore-mounts RemainAfterExit=yes [Install] WantedBy=multi-user.target UNIT systemctl daemon-reload systemctl enable --now greenlight-panel-volumes.service printf '%s\n' 'Agent installé. Dans le panel, clique sur « Tester la connexion ». Ouvre aussi les ports des jeux dans ton pare-feu.'