Split setup.sh in chroot-sicheren und Desktop-Teil

setup.sh rief bisher alles in einem Skript auf, was in der
Autoinstall-ISO (curtin in-target/chroot) teilweise fehlschlaegt:
xfconf-query, npm, oh-my-zsh, PrusaSlicer brauchen eine laufende
Desktop-Session.

Neuer Aufbau:
- setup-base.sh: Pakete, Configs, Locale, Services (laeuft in chroot)
- setup-desktop.sh: oh-my-zsh, Claude Code, PrusaSlicer, Dotfiles,
  XFCE-Einstellungen (laeuft beim ersten Desktop-Login)
- setup.sh: Wrapper fuer Option A (manuelles curl | bash nach Install)

user-data ruft jetzt setup-base.sh in late-commands auf und richtet
einen XFCE-Autostart fuer setup-desktop.sh beim ersten Login ein.
This commit is contained in:
rene 2026-03-07 16:41:22 +01:00
parent d507df6123
commit d6af10d780
5 changed files with 299 additions and 224 deletions

205
setup.sh
View file

@ -1,21 +1,22 @@
#!/bin/bash
# macbook-setup/setup.sh
# Vollautomatisches Post-Install-Skript für Linux auf MacBook Pro
# Ruft setup-base.sh (als root) und setup-desktop.sh (als User) auf
#
# Verwendung: curl -fsSL https://git.motocamp.de/rene/macbook-setup/raw/branch/main/setup.sh | bash
# Oder: bash setup.sh [13|16] (Modell optional, wird sonst abgefragt)
set -e
FORGEJO="https://git.motocamp.de"
DOTFILES_REPO="$FORGEJO/rene/dotfiles-rene.git"
SETUP_REPO="$FORGEJO/rene/macbook-setup.git"
SETUP_RAW="$FORGEJO/rene/macbook-setup/raw/branch/main"
SETUP_RAW="https://git.motocamp.de/rene/macbook-setup/raw/branch/main"
# ── Farben ──────────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
ok() { echo -e "${GREEN}$*${NC}"; }
warn() { echo -e "${YELLOW}$*${NC}"; }
err() { echo -e "${RED}$*${NC}"; exit 1; }
# ── Root-Check ───────────────────────────────────────────────────────────
[[ $EUID -eq 0 ]] && err "Nicht als root ausführen. sudo wird intern verwendet."
# ── Modell ermitteln ─────────────────────────────────────────────────────
if [[ "$1" == "13" || "$1" == "16" ]]; then
MODEL="$1"
@ -27,197 +28,25 @@ else
read -rp "Modell [13/16]: " MODEL
[[ "$MODEL" != "13" && "$MODEL" != "16" ]] && err "Ungültiges Modell: $MODEL"
fi
ok "Modell: MacBook Pro $MODEL\""
# ── Root-Check ───────────────────────────────────────────────────────────
[[ $EUID -eq 0 ]] && err "Nicht als root ausführen. sudo wird intern verwendet."
echo ""
echo "════════════════════════════════════════════"
echo " macbook-setup für MBP $MODEL\" startet"
echo " macbook-setup für MBP $MODEL\" (komplett)"
echo "════════════════════════════════════════════"
# ── 1. System aktualisieren ──────────────────────────────────────────────
echo -e "\n=== 1/12 System aktualisieren ==="
sudo apt update && sudo apt upgrade -y
ok "System aktuell"
# ── Phase 1: System-Setup (als root) ────────────────────────────────────
echo -e "\n>>> Phase 1: setup-base.sh (System)"
curl -fsSL "$SETUP_RAW/setup-base.sh" | sudo bash -s -- "$MODEL"
ok "Phase 1 abgeschlossen"
# ── 2. Pakete installieren ───────────────────────────────────────────────
echo -e "\n=== 2/12 Pakete installieren ==="
sudo apt install -y \
xubuntu-desktop \
bcmwl-kernel-source \
mbpfan thermald \
lm-sensors xfce4-sensors-plugin \
tlp tlp-rdw \
git curl wget stow \
zsh neovim \
build-essential \
python3 python3-pip python3-venv \
nodejs npm \
wireguard wireguard-tools \
libreoffice libreoffice-l10n-de \
thunderbird thunderbird-locale-de \
freecad \
keepassxc \
htop btop \
timeshift \
vlc \
language-pack-de \
wngerman \
bc \
xfce4-terminal
ok "Pakete installiert"
# ── Phase 2: Desktop-Setup (als User) ───────────────────────────────────
echo -e "\n>>> Phase 2: setup-desktop.sh (Desktop)"
curl -fsSL "$SETUP_RAW/setup-desktop.sh" | bash
ok "Phase 2 abgeschlossen"
# ── 3. Nvidia (nur MBP 16") ──────────────────────────────────────────────
if [[ "$MODEL" == "16" ]]; then
echo -e "\n=== 3/12 Nvidia Optimus (MBP 16\") ==="
sudo apt install -y nvidia-driver-535 nvidia-prime bbswitch-dkms
sudo prime-select intel
ok "Nvidia installiert, Intel als Standard-GPU gesetzt"
else
echo -e "\n=== 3/12 Nvidia (MBP 13\") — übersprungen ==="
ok "Kein Nvidia auf MBP 13\""
fi
# ── 4. Brave Browser ─────────────────────────────────────────────────────
echo -e "\n=== 4/12 Brave Browser ==="
sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg \
https://brave-keyring.s3.brave.com/brave-browser-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] \
https://brave-releases.s3.brave.com/ stable main" \
| sudo tee /etc/apt/sources.list.d/brave-browser-release.list
sudo apt update && sudo apt install -y brave-browser
ok "Brave installiert"
# ── 5. PrusaSlicer ───────────────────────────────────────────────────────
echo -e "\n=== 5/12 PrusaSlicer AppImage ==="
mkdir -p ~/Applications
PRUSA_URL="https://github.com/prusa3d/PrusaSlicer/releases/download/version_2.8.1/PrusaSlicer-2.8.1+linux-x64-GTK3-202410181354.AppImage"
wget -q --show-progress -O ~/Applications/PrusaSlicer.AppImage "$PRUSA_URL"
chmod +x ~/Applications/PrusaSlicer.AppImage
# Desktop-Eintrag
cat > ~/.local/share/applications/prusaslicer.desktop <<EOF
[Desktop Entry]
Name=PrusaSlicer
Exec=$HOME/Applications/PrusaSlicer.AppImage
Icon=prusaslicer
Type=Application
Categories=Graphics;
EOF
ok "PrusaSlicer installiert"
# ── 6. oh-my-zsh + zsh als Standard-Shell ────────────────────────────────
echo -e "\n=== 6/12 oh-my-zsh ==="
if [[ ! -d ~/.oh-my-zsh ]]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
fi
sudo chsh -s "$(which zsh)" "$USER"
ok "oh-my-zsh installiert, zsh als Standard-Shell"
# ── 7. npm global + Claude Code ──────────────────────────────────────────
echo -e "\n=== 7/12 Claude Code ==="
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH="$HOME/.npm-global/bin:$PATH"
npm install -g @anthropic-ai/claude-code
ok "Claude Code installiert"
# ── 8. Dot-Files ─────────────────────────────────────────────────────────
echo -e "\n=== 8/12 Dot-Files ==="
if [[ ! -d ~/dotfiles ]]; then
git clone "$DOTFILES_REPO" ~/dotfiles
fi
cd ~/dotfiles
# Vorhandene stow-Pakete erkennen und einspielen
for pkg in zsh nvim git ssh; do
[[ -d "$pkg" ]] && stow "$pkg" && ok "Dot-Files: $pkg"
done
cd ~
# ── 9. Konfigurationsdateien aus Setup-Repo ──────────────────────────────
echo -e "\n=== 9/12 Systemkonfigurationen ==="
# Tastaturbelegung
sudo tee /etc/default/keyboard > /dev/null <<EOF
XKBMODEL="macbook79"
XKBLAYOUT="de"
XKBVARIANT="mac"
XKBOPTIONS="lv3:lalt_switch,terminate:ctrl_alt_bksp"
EOF
# Fn-Tasten
echo 'options hid_apple fnmode=2' | sudo tee /etc/modprobe.d/hid_apple.conf > /dev/null
# mbpfan (modellabhängig)
wget -q -O /tmp/mbpfan.conf "$SETUP_RAW/mbpfan-${MODEL}.conf"
sudo cp /tmp/mbpfan.conf /etc/mbpfan.conf
# Temperatur-Watch-Skript
wget -q -O /tmp/temp-watch.sh "$SETUP_RAW/temp-watch.sh"
sudo cp /tmp/temp-watch.sh /usr/local/bin/temp-watch.sh
sudo chmod +x /usr/local/bin/temp-watch.sh
# Nvidia blacklist (nur MBP 16", optional)
if [[ "$MODEL" == "16" ]]; then
wget -q -O /tmp/blacklist-nvidia.conf "$SETUP_RAW/blacklist-nvidia.conf"
warn "MBP 16\": blacklist-nvidia.conf liegt in /tmp — nur aktivieren wenn Nvidia nicht gebraucht wird"
fi
sudo update-initramfs -u
ok "Systemkonfigurationen gesetzt"
# ── 10. Energieeinstellungen ─────────────────────────────────────────────
echo -e "\n=== 10/12 Energieeinstellungen ==="
# XFCE Power Manager (Akku)
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-on-ac-off -s 0 --create -t int
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-on-ac-sleep -s 0 --create -t int
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/blank-on-ac -s 0 --create -t int
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-on-battery-off -s 10 --create -t int
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-on-battery-sleep -s 10 --create -t int
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/blank-on-battery -s 10 --create -t int
# systemd sleep + logind
sudo tee /etc/systemd/sleep.conf > /dev/null <<EOF
[Sleep]
HibernateDelaySec=1800
EOF
sudo tee -a /etc/systemd/logind.conf > /dev/null <<EOF
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=ignore
EOF
ok "Energieeinstellungen gesetzt"
# ── 11. Lokalisierung ────────────────────────────────────────────────────
echo -e "\n=== 11/12 Lokalisierung ==="
sudo locale-gen de_DE.UTF-8
sudo update-locale LANG=de_DE.UTF-8 LC_ALL=de_DE.UTF-8
sudo timedatectl set-timezone Europe/Berlin
ok "Lokalisierung: Deutsch / Berlin"
# ── 12. Services aktivieren ──────────────────────────────────────────────
echo -e "\n=== 12/12 Services aktivieren ==="
sudo sensors-detect --auto 2>/dev/null || true
sudo systemctl enable --now mbpfan
sudo systemctl enable --now thermald
sudo systemctl enable tlp
ok "mbpfan, thermald, tlp aktiv"
# ── Zusammenfassung ──────────────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════════"
echo -e " ${GREEN}Setup abgeschlossen!${NC}"
echo -e " ${GREEN}Komplett-Setup abgeschlossen!${NC}"
echo "════════════════════════════════════════════"
echo ""
warn "Noch manuell erledigen:"
echo " 1. WireGuard-Config einspielen:"
echo " sudo cp wg0.conf /etc/wireguard/ && sudo systemctl enable --now wg-quick@wg0"
echo " 2. Synology Drive Client installieren (.deb von synology.com)"
echo " 3. Thunderbird starten → Profil aus Synology Drive einbinden"
echo " 4. Brave starten → Synchronisation einrichten"
echo ""
warn "Neustart empfohlen!"
echo " sudo reboot"
echo "Neustart empfohlen: sudo reboot"