danielnagel-site/setup.sh
2026-05-07 13:10:01 +00:00

99 lines
2.4 KiB
Bash
Executable File
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
set -euo pipefail
# Farben für lesbare Ausgabe
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
REQUIRED_MAJOR=3
REQUIRED_MINOR=11
check_python() {
# 1. Existiert python3 überhaupt?
if ! command -v python3 &> /dev/null; then
error "python3 ist nicht installiert!"
error "Installiere es z.B. mit: sudo apt install python3 python3-venv"
exit 1
fi
# 2. Version auslesen
local py_version
py_version=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
local py_major="${py_version%.*}"
local py_minor="${py_version#*.}"
info "Gefundene Python-Version: ${py_version}"
# 3. Vergleichen
if [ "$py_major" -lt "$REQUIRED_MAJOR" ] || \
{ [ "$py_major" -eq "$REQUIRED_MAJOR" ] && [ "$py_minor" -lt "$REQUIRED_MINOR" ]; }; then
error "Python ${REQUIRED_MAJOR}.${REQUIRED_MINOR}+ erforderlich, gefunden: ${py_version}"
exit 1
fi
}
check_venv_module() {
if ! python3 -c "import venv" &> /dev/null; then
error "Das 'venv' Modul fehlt!"
error "Auf Debian/Ubuntu: sudo apt install python3-venv"
exit 1
fi
}
VENV_DIR=".venv"
create_venv() {
if [ -d "$VENV_DIR" ]; then
warn "venv existiert bereits unter '${VENV_DIR}' wird übersprungen."
return 0
fi
info "Erstelle virtuelle Umgebung in '${VENV_DIR}'..."
python3 -m venv "$VENV_DIR"
info "venv erfolgreich erstellt."
}
REQUIREMENTS_FILE="requirements.txt"
install_dependencies() {
if [ ! -f "$REQUIREMENTS_FILE" ]; then
error "Datei '${REQUIREMENTS_FILE}' nicht gefunden!"
exit 1
fi
info "Aktiviere venv und installiere Dependencies..."
# venv-Python direkt verwenden (ohne activate)
"${VENV_DIR}/bin/pip" install --upgrade pip
"${VENV_DIR}/bin/pip" install -r "$REQUIREMENTS_FILE"
info "Dependencies installiert."
}
# --- Hauptablauf ---
info "Starte Setup für Pelican-Projekt..."
check_python
check_venv_module
create_venv
install_dependencies
info "Setup abgeschlossen! 🎉"
info ""
info "Aktiviere das venv mit:"
info " source ${VENV_DIR}/bin/activate"
info ""
info "Dann kannst du loslegen mit:"
info " pelican-quickstart"