1. Ersteinrichtung

Wechsle als Erstes mit su - zum Root-Benutzer, installiere sudo und füge deinen Benutzer zur sudo-Gruppe hinzu:

BASH
su -

(Gib hier das Root-Passwort deiner VM ein)

Führe danach diese Befehle aus, um die Grundlagen einzurichten und das Skript korrekt auszuführen:

BASH
# 1. sudo installieren und Benutzer zur sudo-Gruppe hinzufügen
apt update && apt install -y sudo
usermod -aG sudo USER

(Hinweis: Damit die Gruppenzuweisung sudo für deinen normalen Benutzer USER nach dem Skript greift, einmal kurz per exit aus- und wieder einloggen.)

Install Script

BASH
nano ./setup.sh
BASH
#!/usr/bin/env bash

# Target FQDN required by Netcup
TARGET_HOSTNAME="debian"

echo "===================================================="
echo " Starting System Validation & Tool-Installation"
echo "===================================================="

# 1. Verify hostname
CURRENT_HOSTNAME=$(hostname -f 2>/dev/null)
if [ "$CURRENT_HOSTNAME" != "$TARGET_HOSTNAME" ]; then
    echo "[-] ERROR: Hostname mismatch!"
    echo "    Current FQDN: $CURRENT_HOSTNAME"
    echo "    Expected:     $TARGET_HOSTNAME"
    echo "    Please run: 'hostnamectl set-hostname $TARGET_HOSTNAME'"
    exit 1
fi
echo "[+] Hostname verification successful: $CURRENT_HOSTNAME"

# 2. System updates
echo "[*] Updating package repositories..."
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get upgrade -y

# 3. Install core utilities
echo "[*] Installing standard tools..."
apt-get install -y sudo curl wget git zsh tmux htop btop fastfetch micro python3 uv needrestart

# 3.1 Install uv
echo "[*] Installing Python uv ..."
curl -LsSf https://astral.sh/uv/install.sh | sh

# 4. Install OhMyZsh (Non-Interactive)
if [ ! -d "$HOME/.oh-my-zsh" ]; then
    echo "[*] Installing OhMyZsh..."
    RUNZSH=no CHSH=no sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --keep-zsh-rc
fi

# 5. Clone Zsh plugins
ZSH_CUSTOM_PLUGINS="$HOME/.oh-my-zsh/custom/plugins"
mkdir -p "$ZSH_CUSTOM_PLUGINS"

echo "[*] Cloning Zsh plugins..."
declare -A plugins=(
    ["zsh-autosuggestions"]="https://github.com/zsh-users/zsh-autosuggestions"
    ["zsh-syntax-highlighting"]="https://github.com/zsh-users/zsh-syntax-highlighting.git"
    ["zsh-autocomplete"]="https://github.com/marlonrichert/zsh-autocomplete.git"
)

for plugin in "${!plugins[@]}"; do
    if [ ! -d "$ZSH_CUSTOM_PLUGINS/$plugin" ]; then
        git clone "${plugins[$plugin]}" "$ZSH_CUSTOM_PLUGINS/$plugin"
    fi
done

# 6. Write .zshrc configuration
echo "[*] Writing configuration to ~/.zshrc..."
cat << 'EOF' > ~/.zshrc
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="agnoster"
zstyle ':omz:update' mode auto
HIST_STAMPS="yyyy-mm-dd"

plugins=(
  alias-finder
  aliases
  colored-man-pages
  colorize
  dirhistory
  debian
  git
  history
  ssh-agent
  sudo
  systemd
  tailscale
  zsh-autosuggestions
  zsh-autocomplete
  zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh

fastfetch

# --- CUSTOM ALIASES ---
alias hst='/usr/local/hestia/bin/'
alias v-list-users='/usr/local/hestia/bin/v-list-users'
alias ..='cd ..'
alias ll='ls -lah'
alias update='sudo apt update && sudo apt upgrade -y && needrestart'
alias cls='clear'
alias f2b='uv run ~/scripts/f2b_stats.py'
alias banstatus="sudo fail2ban-client status | awk -F':\t' '/Jail list/ {print \$2}' | sed 's/,//g' | xargs -n1 sudo fail2ban-client status"
alias ports='sudo ss -tulpn | grep LISTEN'
alias myip='curl -4 icanhazip.com'
alias h-logs='sudo tail -f /var/log/hestia/system.log'
alias h-restart='sudo systemctl restart hestia'
alias ta='tmux attach || tmux new-session'
alias tls='tmux ls'
alias del-mail='echo "d 1-1000" | mail -N > /dev/null'
alias logs='sudo ~/scripts/check_logs.sh'
alias mqtt='sudo tail -f /var/log/mosquitto/mosquitto.log'
alias mqtt_logger='sudo journalctl -u mqtt-logger.service -f'
alias venv='source .venv/bin/activate'
alias health='sudo ~/scripts/health-check.sh'
alias sudo='sudo env PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin'

# Exports
export EDITOR=micro
export VISUAL=micro
EOF

# 7. Set default shell to Zsh
if [ "$SHELL" != "/bin/zsh" ]; then
    echo "[*] Changing default shell to Zsh..."
    chsh -s $(which zsh) root
fi

# 8. Seamlessly transition to the new Zsh environment
echo "[+] Spawning interactive Zsh login shell..."
exec zsh -l

TXT
chmod +x setup.sh
sudo ./setup.sh