feat: Add Komodo Periphery installer script
- Interactive bash script for easy periphery deployment - Prompts for Core domain, passkey, server name - Creates docker-compose.yml, config.toml, systemd service - Auto-starts periphery after installation - Includes logging and status commands Usage: ./komodo-periphery-install.sh (run as root)
This commit is contained in:
parent
90aacb08e6
commit
bbe69bc61d
1 changed files with 305 additions and 0 deletions
305
komodo-periphery-install.sh
Executable file
305
komodo-periphery-install.sh
Executable file
|
|
@ -0,0 +1,305 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Komodo Periphery Installer
|
||||
# Installiert und konfiguriert Komodo Periphery auf einem Client-Server
|
||||
#
|
||||
# Usage: ./komodo-periphery-install.sh
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
# Helper functions (no colors to avoid Unicode warnings)
|
||||
print_header() {
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo "$1"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo "[OK] $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo "[ERROR] $1"
|
||||
}
|
||||
|
||||
print_info() {
|
||||
echo "[INFO] $1"
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
check_root() {
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
print_error "Please run as root (sudo ./komodo-periphery-install.sh)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check for Docker
|
||||
check_docker() {
|
||||
if ! command -v docker &> /dev/null; then
|
||||
print_error "Docker is not installed. Installing..."
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
print_success "Docker installed"
|
||||
else
|
||||
print_success "Docker is installed ($(docker --version))"
|
||||
fi
|
||||
}
|
||||
|
||||
# Interactive input
|
||||
get_user_input() {
|
||||
print_header "Komodo Periphery Configuration"
|
||||
|
||||
# Core Domain
|
||||
while true; do
|
||||
read -p "Enter Komodo Core Domain (e.g., https://komodo.example.com): " CORE_DOMAIN
|
||||
if [[ -z "$CORE_DOMAIN" ]]; then
|
||||
print_error "Core domain cannot be empty"
|
||||
continue
|
||||
fi
|
||||
# Remove trailing slash if present
|
||||
CORE_DOMAIN="${CORE_DOMAIN%/}"
|
||||
print_info "Core Domain: $CORE_DOMAIN"
|
||||
read -p "Is this correct? (y/n): " confirm
|
||||
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Passkey
|
||||
while true; do
|
||||
read -sp "Enter Komodo Passkey: " PASSKEY
|
||||
echo ""
|
||||
if [[ -z "$PASSKEY" ]]; then
|
||||
print_error "Passkey cannot be empty"
|
||||
continue
|
||||
fi
|
||||
read -sp "Confirm Passkey: " PASSKEY_CONFIRM
|
||||
echo ""
|
||||
if [[ "$PASSKEY" != "$PASSKEY_CONFIRM" ]]; then
|
||||
print_error "Passkeys do not match"
|
||||
continue
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
# Server Name (optional)
|
||||
read -p "Enter a name for this Periphery (default: $(hostname)): " SERVER_NAME
|
||||
SERVER_NAME="${SERVER_NAME:-$(hostname)}"
|
||||
print_info "Server Name: $SERVER_NAME"
|
||||
|
||||
# Install Directory
|
||||
read -p "Enter install directory (default: /opt/komodo-periphery): " INSTALL_DIR
|
||||
INSTALL_DIR="${INSTALL_DIR:-/opt/komodo-periphery}"
|
||||
print_info "Install Directory: $INSTALL_DIR"
|
||||
}
|
||||
|
||||
# Create directory structure
|
||||
create_directories() {
|
||||
print_header "Creating Directory Structure"
|
||||
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
mkdir -p "$INSTALL_DIR/config"
|
||||
mkdir -p "$INSTALL_DIR/logs"
|
||||
mkdir -p "$INSTALL_DIR/data"
|
||||
|
||||
print_success "Directories created"
|
||||
}
|
||||
|
||||
# Create configuration file
|
||||
create_config() {
|
||||
print_header "Creating Configuration"
|
||||
|
||||
cat > "$INSTALL_DIR/config/config.toml" << EOF
|
||||
# Komodo Periphery Configuration
|
||||
# Generated: $(date -Iseconds)
|
||||
|
||||
title = "$SERVER_NAME"
|
||||
core_url = "$CORE_DOMAIN"
|
||||
passkey = "$PASSKEY"
|
||||
listen_port = 8120
|
||||
bind_address = "0.0.0.0"
|
||||
|
||||
# Logging
|
||||
log_level = "info"
|
||||
log_file = "/opt/komodo-periphery/logs/periphery.log"
|
||||
|
||||
# Data directory
|
||||
data_directory = "/opt/komodo-periphery/data"
|
||||
|
||||
# Optional: Enable terminal access
|
||||
enable_terminal = true
|
||||
|
||||
# Optional: Custom websocket settings
|
||||
# websocket_timeout = 30
|
||||
# websocket_ping_interval = 10
|
||||
EOF
|
||||
|
||||
print_success "Configuration created at $INSTALL_DIR/config/config.toml"
|
||||
|
||||
# Set secure permissions
|
||||
chmod 600 "$INSTALL_DIR/config/config.toml"
|
||||
print_success "Configuration file permissions set (600)"
|
||||
}
|
||||
|
||||
# Create docker-compose.yml
|
||||
create_docker_compose() {
|
||||
print_header "Creating Docker Compose File"
|
||||
|
||||
cat > "$INSTALL_DIR/docker-compose.yml" << 'EOF'
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
komodo-periphery:
|
||||
image: ghcr.io/moghtech/komodo-periphery:latest
|
||||
container_name: komodo-periphery
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
volumes:
|
||||
- ./config:/config:ro
|
||||
- ./data:/data
|
||||
- ./logs:/logs
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- /:/host:ro
|
||||
cap_add:
|
||||
- SYS_PTRACE
|
||||
- NET_RAW
|
||||
- NET_ADMIN
|
||||
security_opt:
|
||||
- apparmor:unconfined
|
||||
environment:
|
||||
- TZ=UTC
|
||||
labels:
|
||||
- "com.komodo.type=periphery"
|
||||
EOF
|
||||
|
||||
print_success "Docker Compose file created"
|
||||
}
|
||||
|
||||
# Create systemd service
|
||||
create_systemd_service() {
|
||||
print_header "Creating Systemd Service"
|
||||
|
||||
cat > /etc/systemd/system/komodo-periphery.service << EOF
|
||||
[Unit]
|
||||
Description=Komodo Periphery Agent
|
||||
Documentation=https://docs.komodo.dev
|
||||
After=network.target docker.service
|
||||
Requires=docker.service
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
WorkingDirectory=$INSTALL_DIR
|
||||
ExecStart=/usr/bin/docker compose up -d
|
||||
ExecStop=/usr/bin/docker compose down
|
||||
TimeoutStartSec=300
|
||||
TimeoutStopSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
print_success "Systemd service created"
|
||||
|
||||
# Reload systemd and enable service
|
||||
systemctl daemon-reload
|
||||
systemctl enable komodo-periphery
|
||||
print_success "Systemd service enabled"
|
||||
}
|
||||
|
||||
# Start the service
|
||||
start_service() {
|
||||
print_header "Starting Komodo Periphery"
|
||||
|
||||
cd "$INSTALL_DIR"
|
||||
|
||||
# Pull latest image
|
||||
print_info "Pulling latest Docker image..."
|
||||
docker compose pull
|
||||
|
||||
# Start the service
|
||||
print_info "Starting Periphery..."
|
||||
docker compose up -d
|
||||
|
||||
# Wait for startup
|
||||
sleep 5
|
||||
|
||||
# Check status
|
||||
if docker ps | grep -q komodo-periphery; then
|
||||
print_success "Komodo Periphery is running!"
|
||||
else
|
||||
print_error "Periphery failed to start. Check logs:"
|
||||
print_info "docker logs komodo-periphery"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Show status
|
||||
show_status() {
|
||||
print_header "Installation Complete!"
|
||||
|
||||
echo "Komodo Periphery has been successfully installed!"
|
||||
echo ""
|
||||
|
||||
echo "Configuration:"
|
||||
echo " Core Domain: $CORE_DOMAIN"
|
||||
echo " Server Name: $SERVER_NAME"
|
||||
echo " Install Dir: $INSTALL_DIR"
|
||||
echo ""
|
||||
|
||||
echo "Service Status:"
|
||||
systemctl status komodo-periphery --no-pager -l || true
|
||||
echo ""
|
||||
|
||||
echo "Container Status:"
|
||||
docker ps --filter name=komodo-periphery --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||
echo ""
|
||||
|
||||
echo "Useful Commands:"
|
||||
echo " View logs: docker logs komodo-periphery -f"
|
||||
echo " Restart: systemctl restart komodo-periphery"
|
||||
echo " Stop: systemctl stop komodo-periphery"
|
||||
echo " Status: systemctl status komodo-periphery"
|
||||
echo " Config location: $INSTALL_DIR/config/config.toml"
|
||||
echo ""
|
||||
|
||||
echo "Next Steps:"
|
||||
echo " 1. Go to your Komodo Core UI"
|
||||
echo " 2. Navigate to 'Peripheries' or 'Servers'"
|
||||
echo " 3. This Periphery should appear automatically"
|
||||
echo " 4. If not, check the logs for connection errors"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Cleanup on error
|
||||
cleanup() {
|
||||
if [ $? -ne 0 ]; then
|
||||
print_error "Installation failed. Cleaning up..."
|
||||
docker compose down 2>/dev/null || true
|
||||
print_info "Check logs at: $INSTALL_DIR/logs/"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main installation
|
||||
main() {
|
||||
print_header "Komodo Periphery Installer"
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
check_root
|
||||
check_docker
|
||||
get_user_input
|
||||
create_directories
|
||||
create_config
|
||||
create_docker_compose
|
||||
create_systemd_service
|
||||
start_service
|
||||
show_status
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue