setup-kurs.sh
Server-Vorbereitung – einmalig vor dem Kurs als root ausführen.
Download und ausführen:
Was das Skript macht: - Docker stoppen - Podman und Tools installieren - Proxy-Konfiguration prüfen und eintragen - SSH Passwort-Authentifizierung sicherstellen - Images als root pullen
setup-kurs.sh
#!/bin/bash
# =============================================================================
# setup-kurs.sh – Podman Kurs Server-Vorbereitung (Trainer)
# Führt alle Schritte aus um den Server für den Kurs bereitzumachen.
# Verwendung: sudo ./setup-kurs.sh
# =============================================================================
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
ok() { echo -e "${GREEN}[OK]${NC} $1"; }
info() { echo -e "${YELLOW}[INFO]${NC} $1"; }
err() { echo -e "${RED}[FEHLER]${NC} $1"; exit 1; }
section() { echo -e "\n${BLUE}==== $1 ====${NC}\n"; }
# --- Root-Check ---
if [[ $EUID -ne 0 ]]; then
err "Dieses Skript muss als root ausgeführt werden (sudo)."
fi
echo ""
echo "=============================================="
echo " Podman Kurs – Server Setup (Trainer)"
echo "=============================================="
echo ""
# =============================================================================
# SCHRITT 1 – Docker stoppen
# =============================================================================
section "Schritt 1 – Docker stoppen"
if systemctl is-active --quiet docker; then
systemctl stop docker
ok "Docker gestoppt."
else
ok "Docker läuft bereits nicht."
fi
if systemctl is-active --quiet docker.socket; then
systemctl stop docker.socket
ok "Docker Socket gestoppt."
else
ok "Docker Socket bereits inaktiv."
fi
# =============================================================================
# SCHRITT 2 – Podman installieren
# =============================================================================
section "Schritt 2 – Podman installieren"
if command -v podman &>/dev/null; then
ok "Podman bereits installiert ($(podman --version))."
else
info "Installiere Podman und Tools..."
dnf install -y podman podman-compose container-tools podman-docker
ok "Podman installiert ($(podman --version))."
fi
# Versionen ausgeben
info "Installierte Versionen:"
podman --version
podman-compose --version 2>/dev/null || true
# =============================================================================
# SCHRITT 3 – Proxy-Konfiguration für Registry-Zugriff
# =============================================================================
section "Schritt 3 – Proxy-Konfiguration"
# Proxy-Einstellungen prüfen
if [[ -z "${http_proxy:-}" && -z "${https_proxy:-}" && -z "${HTTP_PROXY:-}" && -z "${HTTPS_PROXY:-}" ]]; then
echo -e "${YELLOW}[ACHTUNG]${NC} Keine Proxy-Umgebungsvariablen gesetzt."
echo " Registry-Zugriff läuft über Proxy – bitte sicherstellen dass"
echo " folgende Variablen gesetzt sind (z.B. in /etc/environment):"
echo ""
echo " http_proxy=http://<proxy-host>:<port>"
echo " https_proxy=http://<proxy-host>:<port>"
echo " no_proxy=localhost,127.0.0.1"
echo ""
echo " Für Podman/systemd-Dienste zusätzlich in:"
echo " /etc/systemd/system/podman.service.d/proxy.conf"
echo ""
else
ok "Proxy-Variablen gefunden:"
[[ -n "${http_proxy:-}" ]] && echo " http_proxy=${http_proxy}"
[[ -n "${https_proxy:-}" ]] && echo " https_proxy=${https_proxy}"
[[ -n "${no_proxy:-}" ]] && echo " no_proxy=${no_proxy}"
fi
# Proxy in /etc/containers/containers.conf eintragen falls gesetzt
PROXY_VAL="${https_proxy:-${http_proxy:-${HTTPS_PROXY:-${HTTP_PROXY:-}}}}"
if [[ -n "$PROXY_VAL" ]]; then
CONTAINERS_CONF="/etc/containers/containers.conf"
if ! grep -q "^http_proxy" "$CONTAINERS_CONF" 2>/dev/null; then
mkdir -p /etc/containers
cat >> "$CONTAINERS_CONF" << EOF
# Proxy-Konfiguration für Registry-Zugriff
[engine]
env = ["http_proxy=${PROXY_VAL}", "https_proxy=${PROXY_VAL}"]
EOF
ok "Proxy in ${CONTAINERS_CONF} eingetragen."
else
ok "Proxy bereits in ${CONTAINERS_CONF} konfiguriert."
fi
fi
# =============================================================================
# SCHRITT 4 – SSH konfigurieren
# =============================================================================
section "Schritt 4 – SSH Passwort-Authentifizierung prüfen"
SSHD_CONFIG="/etc/ssh/sshd_config"
if grep -qE "^PasswordAuthentication yes" "$SSHD_CONFIG"; then
ok "SSH Passwort-Authentifizierung bereits aktiv."
else
info "Aktiviere SSH Passwort-Authentifizierung..."
# Kommentierte oder 'no' Zeile ersetzen
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' "$SSHD_CONFIG"
systemctl restart sshd
ok "SSH neu gestartet mit Passwort-Authentifizierung."
fi
# =============================================================================
# SCHRITT 5 – Images als root pullen
# =============================================================================
section "Schritt 5 – Images pullen (als root)"
info "Verbindung zu Registry wird über Proxy hergestellt..."
echo ""
IMAGES=(
"docker.io/library/nginx:latest"
"docker.io/library/nginx:1.24"
"docker.io/library/hello-world:latest"
"docker.io/library/httpd:latest"
)
for IMAGE in "${IMAGES[@]}"; do
if podman image exists "$IMAGE" 2>/dev/null; then
ok "Bereits vorhanden: ${IMAGE}"
else
info "Pulle ${IMAGE}..."
if podman pull "$IMAGE"; then
ok "Gepullt: ${IMAGE}"
else
echo -e "${YELLOW}[WARN]${NC} Konnte ${IMAGE} nicht pullen – Proxy/Netzwerk prüfen."
fi
fi
done
echo ""
info "Lokale Images (root-Store):"
podman images
# =============================================================================
# ABSCHLUSS
# =============================================================================
section "Setup abgeschlossen"
SERVER_IP=$(hostname -I | awk '{print $1}')
ok "Docker gestoppt"
ok "Podman installiert"
ok "SSH konfiguriert"
ok "Images im Root-Store vorhanden"
echo ""
echo " Server-IP: ${SERVER_IP}"
echo ""
echo " Nächster Schritt: Teilnehmer einrichten mit:"
echo " sudo ./setup-teilnehmer.sh teilnehmer01"
echo " sudo ./setup-teilnehmer.sh teilnehmer02"
echo " ..."
echo ""
echo -e "${YELLOW} Wichtig:${NC} Proxy-Einstellungen vor dem Kurs testen:"
echo " podman pull docker.io/library/hello-world"
echo ""