macbook-setup/setup-base.sh
rene 6a6acca19f Repos lokal klonen vor Setup, WireGuard automatisch deployen
- setup.sh klont macbook-setup + dotfiles-rene lokal (Credentials
  einmalig im interaktiven Terminal statt im Autostart)
- setup-base.sh nutzt lokale Dateien wenn vorhanden (wget-Fallback
  fuer Autoinstall bleibt erhalten), deployed WireGuard-Config
- wireguard/ aus .gitignore entfernt, Configs werden getrackt
- WireGuard aus manueller Checkliste entfernt
2026-03-12 16:52:48 +01:00

298 lines
12 KiB
Bash
Executable file

#!/bin/bash
# macbook-setup/setup-base.sh
# System-Setup: Pakete, Konfiguration, Locale, Services
# Verwendung: curl ... | sudo bash -s -- 16
# Kann mehrfach ausgeführt werden (idempotent)
FORGEJO="https://git.motocamp.de"
SETUP_RAW="$FORGEJO/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}"; }
fail() { echo -e "${RED}$*${NC}"; }
# ── Lokales Repo erkennen (falls nicht via curl|bash) ─────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
if [[ -n "$SCRIPT_DIR" && -f "$SCRIPT_DIR/mbpfan-13.conf" ]]; then
REPO_DIR="$SCRIPT_DIR"
ok "Lokales Repo erkannt: $REPO_DIR"
else
REPO_DIR=""
fi
# ── Modell ermitteln ─────────────────────────────────────────────────────
if [[ "$1" == "13" || "$1" == "16" ]]; then
MODEL="$1"
else
echo ""
echo "Welches MacBook Pro?"
echo " 13 = MBP 13\" Late 2013"
echo " 16 = MBP 16\" Mid 2014 (Intel + AMD Radeon)"
read -rp "Modell [13/16]: " MODEL < /dev/tty
[[ "$MODEL" != "13" && "$MODEL" != "16" ]] && { fail "Ungültiges Modell: $MODEL"; exit 1; }
fi
ok "Modell: MacBook Pro $MODEL\""
echo ""
echo "════════════════════════════════════════════"
echo " setup-base.sh für MBP $MODEL\" startet"
echo "════════════════════════════════════════════"
# ── 1. Kritische Hardware-Fixes ZUERST (vor allem anderen) ───────────────
echo -e "\n=== 1/11 Hardware-Fixes ==="
# GPU: AMD Radeon blacklisten (MBP 16")
if [[ "$MODEL" == "16" ]]; then
cat > /etc/modprobe.d/blacklist-radeon.conf <<EOF
blacklist radeon
blacklist amdgpu
EOF
ok "AMD Radeon/amdgpu geblockt — nur Intel i915"
else
ok "MBP 13\": nur Intel-GPU, kein Blacklisting nötig"
fi
# Fn-Tasten + ISO-Layout-Fix (iso_layout=1 korrigiert ^/< auf Apple ISO-Keyboards)
echo 'options hid_apple fnmode=2 iso_layout=1' > /etc/modprobe.d/hid_apple.conf
ok "hid_apple: fnmode=2, iso_layout=1"
# Tastaturbelegung (nodeadkeys + lv3:lalt_switch: @=Alt+Q, |=Alt+<)
cat > /etc/default/keyboard <<EOF
XKBMODEL="macbook79"
XKBLAYOUT="de"
XKBVARIANT="nodeadkeys"
XKBOPTIONS="lv3:lalt_switch,terminate:ctrl_alt_bksp"
EOF
dpkg-reconfigure -f noninteractive keyboard-configuration 2>/dev/null || true
ok "Tastatur: mac_nodeadkeys"
# cloud-init deaktivieren (blockiert Boot ohne Cloud-Provider)
if command -v cloud-init &>/dev/null; then
touch /etc/cloud/cloud-init.disabled
ok "cloud-init deaktiviert"
fi
# initramfs aktualisieren (GPU-Blacklist + hid_apple wirksam machen)
update-initramfs -u 2>/dev/null || true
ok "initramfs aktualisiert"
# ── 2. Sleep/Suspend verhindern während Installation ─────────────────────
echo -e "\n=== 2/11 Sleep verhindern ==="
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target 2>/dev/null || true
ok "Sleep/Suspend deaktiviert (für Installation)"
# ── 3. Eventuelle unterbrochene Installationen reparieren ────────────────
echo -e "\n=== 3/11 dpkg reparieren ==="
dpkg --configure -a 2>/dev/null || true
apt install -f -y 2>/dev/null || true
ok "dpkg/apt repariert"
# ── 4. System aktualisieren ──────────────────────────────────────────────
echo -e "\n=== 4/11 System aktualisieren ==="
apt update && apt upgrade -y || warn "apt upgrade hatte Probleme"
ok "System aktuell"
# ── 5. Pakete installieren ───────────────────────────────────────────────
echo -e "\n=== 5/11 Pakete installieren ==="
apt install -y \
xubuntu-core \
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 \
openssh-server \
libheif-examples imagemagick \
pipx \
zoxide \
micro \
flatpak \
thunderbird thunderbird-locale-de \
keepassxc \
htop btop \
timeshift \
vlc \
language-pack-de \
wngerman \
bc \
xfce4-terminal \
|| { fail "apt install fehlgeschlagen"; dpkg --configure -a; apt install -f -y; }
ok "Pakete installiert (apt)"
# FreeCAD + LibreOffice via Snap
snap install freecad 2>/dev/null || warn "FreeCAD Snap uebersprungen"
snap install libreoffice 2>/dev/null || warn "LibreOffice Snap uebersprungen"
# ── 6. Brave Browser (wird in setup-desktop.sh als Flatpak installiert) ──
echo -e "\n=== 6/11 Brave Browser ==="
ok "Brave wird als Flatpak in setup-desktop.sh installiert"
# ── 7. Systemkonfigurationen ─────────────────────────────────────────────
echo -e "\n=== 7/11 Systemkonfigurationen ==="
# mbpfan (modellabhängig)
if [[ -n "$REPO_DIR" && -f "$REPO_DIR/mbpfan-${MODEL}.conf" ]]; then
cp "$REPO_DIR/mbpfan-${MODEL}.conf" /etc/mbpfan.conf
ok "mbpfan.conf (lokal)"
else
wget -q -O /etc/mbpfan.conf "$SETUP_RAW/mbpfan-${MODEL}.conf" || warn "mbpfan.conf Download fehlgeschlagen"
fi
# Temperatur-Watch-Skript
if [[ -n "$REPO_DIR" && -f "$REPO_DIR/temp-watch.sh" ]]; then
cp "$REPO_DIR/temp-watch.sh" /usr/local/bin/temp-watch.sh
chmod +x /usr/local/bin/temp-watch.sh
ok "temp-watch.sh (lokal)"
else
wget -q -O /usr/local/bin/temp-watch.sh "$SETUP_RAW/temp-watch.sh" && \
chmod +x /usr/local/bin/temp-watch.sh || warn "temp-watch.sh Download fehlgeschlagen"
fi
# WireGuard-Config
if [[ -n "$REPO_DIR" && -f "$REPO_DIR/wireguard/m${MODEL}.conf" ]]; then
mkdir -p /etc/wireguard
cp "$REPO_DIR/wireguard/m${MODEL}.conf" /etc/wireguard/wg0.conf
chmod 600 /etc/wireguard/wg0.conf
systemctl enable wg-quick@wg0 2>/dev/null || true
ok "WireGuard m${MODEL}.conf → /etc/wireguard/wg0.conf"
else
warn "WireGuard: keine lokale Config gefunden — manuell einrichten"
fi
ok "Systemkonfigurationen gesetzt"
# ── 8. XFCE-Konfiguration (MBP 16": Compositor aus, Display-Skalierung) ─
if [[ "$MODEL" == "16" ]]; then
echo -e "\n=== 8/11 XFCE-Konfiguration (MBP 16\") ==="
XFCE_XML_DIR="/home/rene/.config/xfce4/xfconf/xfce-perchannel-xml"
mkdir -p "$XFCE_XML_DIR"
# Compositor deaktivieren + HiDPI-Theme + Titelschrift
cat > "$XFCE_XML_DIR/xfwm4.xml" <<XFEOF
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfwm4" version="1.0">
<property name="general" type="empty">
<property name="use_compositing" type="bool" value="false"/>
<property name="theme" type="string" value="Default-xhdpi"/>
<property name="title_font" type="string" value="Sans Bold 9"/>
</property>
</channel>
XFEOF
# Display-Skalierung für Retina (2x)
cat > "$XFCE_XML_DIR/xsettings.xml" <<XSEOF
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="1.0">
<property name="Gdk" type="empty">
<property name="WindowScalingFactor" type="int" value="2"/>
</property>
<property name="Xft" type="empty">
<property name="DPI" type="int" value="96"/>
</property>
<property name="Gtk" type="empty">
<property name="CursorThemeSize" type="int" value="48"/>
</property>
</channel>
XSEOF
# xfce4-display-settings deaktivieren (Endlosschleife)
dpkg-divert --local --rename --divert /usr/bin/xfce4-display-settings.real /usr/bin/xfce4-display-settings 2>/dev/null || true
ln -sf /usr/bin/true /usr/bin/xfce4-display-settings
chown -R 1000:1000 /home/rene/.config/xfce4
ok "XFCE: Compositor aus, Retina-Skalierung, Display-Settings deaktiviert"
else
echo -e "\n=== 8/11 XFCE-Konfiguration — Standard (MBP 13\") ==="
fi
# ── 9. Netzwerk: NetworkManager statt netplan ─────────────────────────────
echo -e "\n=== 9/11 Netzwerk ==="
# WLAN-Zugangsdaten aus bestehender netplan-Config übernehmen (falls vorhanden)
WLAN_SSID=""
WLAN_PASS=""
for npfile in /etc/netplan/*.yaml; do
if [[ -f "$npfile" ]] && grep -q "wifis:" "$npfile" 2>/dev/null; then
WLAN_SSID=$(grep -A5 'wifis:' "$npfile" | grep -oP '"\K[^"]+' | head -1)
WLAN_PASS=$(grep -oP 'password:\s*"\K[^"]+' "$npfile" | head -1)
[[ -n "$WLAN_SSID" ]] && ok "WLAN-Config gefunden: $WLAN_SSID"
fi
done
cat > /etc/netplan/01-network-manager.yaml <<NMEOF
network:
version: 2
renderer: NetworkManager
NMEOF
# Cloud-init netplan-Config entfernen (blockiert NetworkManager)
rm -f /etc/netplan/50-cloud-init.yaml
# Boot nicht auf Netzwerk warten lassen
systemctl disable systemd-networkd-wait-online.service 2>/dev/null || true
systemctl enable NetworkManager-wait-online.service 2>/dev/null || true
ok "NetworkManager als Netzwerk-Renderer"
# ── 10. Energieeinstellungen & Lokalisierung ─────────────────────────────
echo -e "\n=== 10/11 Energie & Lokalisierung ==="
tee /etc/systemd/sleep.conf > /dev/null <<EOF
[Sleep]
HibernateDelaySec=1800
EOF
tee -a /etc/systemd/logind.conf > /dev/null <<EOF
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=ignore
EOF
locale-gen de_DE.UTF-8
update-locale LANG=de_DE.UTF-8 LC_ALL=de_DE.UTF-8
timedatectl set-timezone Europe/Berlin 2>/dev/null || ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
ok "Energie & Lokalisierung gesetzt"
# ── 11. Services aktivieren ──────────────────────────────────────────────
echo -e "\n=== 11/11 Services & Shell ==="
systemctl enable mbpfan 2>/dev/null || true
systemctl enable thermald 2>/dev/null || true
systemctl enable tlp 2>/dev/null || true
systemctl enable ssh 2>/dev/null || true
# Services starten (nur wenn nicht in chroot)
if [[ "$(stat -c %d:%i /)" == "$(stat -c %d:%i /proc/1/root/.)" ]] 2>/dev/null; then
systemctl start mbpfan 2>/dev/null || true
systemctl start thermald 2>/dev/null || true
systemctl start ssh 2>/dev/null || true
sensors-detect --auto 2>/dev/null || true
fi
# WLAN-Verbindung in NetworkManager einrichten (aus gesicherter netplan-Config)
if [[ -n "$WLAN_SSID" && -n "$WLAN_PASS" ]]; then
nmcli device wifi connect "$WLAN_SSID" password "$WLAN_PASS" 2>/dev/null || true
ok "WLAN wiederhergestellt: $WLAN_SSID"
fi
# zsh als Standard-Shell
chsh -s /bin/zsh rene 2>/dev/null || true
# Sleep wieder erlauben
systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target 2>/dev/null || true
ok "Services aktiviert, zsh als Standard-Shell"
# ── Zusammenfassung ──────────────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════════"
echo -e " ${GREEN}setup-base.sh abgeschlossen!${NC}"
echo "════════════════════════════════════════════"
echo ""
echo "Nächste Schritte:"
echo " 1. sudo reboot"
echo " 2. In XFCE einloggen"
echo " 3. Terminal öffnen und setup-desktop.sh starten:"
echo " curl -fsSL $SETUP_RAW/setup-desktop.sh | bash"