Setup/4_ZshRegister.sh

63 lines
2.0 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

#!/bin/bash
# Sicherstellen, dass das Skript mit Root-Rechten ausgeführt wird
if [[ $EUID -ne 0 ]]; then
echo "Dieses Skript muss als root ausgeführt werden."
exit 1
fi
# Tatsächlichen Benutzer ermitteln (nicht root)
if [[ -z "$SUDO_USER" || "$SUDO_USER" == "root" ]]; then
echo "Fehler: Das Skript muss mit 'sudo' von einem normalen Benutzer ausgeführt werden."
exit 1
fi
USER_NAME="$SUDO_USER"
USER_HOME=$(eval echo ~$USER_NAME)
# Eintrag aus getent passwd holen
USER_ENTRY=$(getent passwd "$USER_NAME")
# Backup der passwd Datei
cp /etc/passwd /etc/passwd.bak
if grep -q "^$USER_NAME:" /etc/passwd; then
# Existierenden Eintrag aktualisieren
sed -i "/^$USER_NAME:/s|[^:]*$|/bin/zsh|" /etc/passwd
echo "Shell für $USER_NAME wurde auf zsh aktualisiert."
else
# Neuen Eintrag hinzufügen
UPDATED_ENTRY=$(echo "$USER_ENTRY" | awk -F: -v OFS=: '{ $NF="/bin/zsh"; print }')
echo "$UPDATED_ENTRY" >>/etc/passwd
echo "Eintrag für $USER_NAME wurde in /etc/passwd geschrieben mit zsh als Shell."
fi
# Repository klonen
REPO_DIR="$USER_HOME/Ubuntu-Hyprland"
sudo -u "$USER_NAME" git clone -b 24.04 https://github.com/JaKooLit/Ubuntu-Hyprland.git "$REPO_DIR"
# Ordner nach ~/.oh-my-zsh/themes kopieren
THEME_SRC="$REPO_DIR/assets/add_zsh_theme"
THEME_DEST="$USER_HOME/.oh-my-zsh/themes"
if [[ -d "$THEME_SRC" ]]; then
sudo -u "$USER_NAME" mkdir -p "$THEME_DEST"
sudo -u "$USER_NAME" cp -r "$THEME_SRC"/* "$THEME_DEST/"
echo "🎨 ZSH-Theme wurde nach $THEME_DEST kopiert."
else
echo "⚠️ Fehler: Theme-Ordner wurde nicht gefunden!"
fi
# Repository löschen
rm -rf "$REPO_DIR"
# /etc/profile in /etc/zsh/zprofile einfügen, falls nicht bereits vorhanden
if ! grep -q "source /etc/profile" /etc/zsh/zprofile; then
echo "source /etc/profile" >>/etc/zsh/zprofile
echo "🔧 'source /etc/profile' wurde in /etc/zsh/zprofile hinzugefügt."
else
echo " 'source /etc/profile' ist bereits in /etc/zsh/zprofile vorhanden."
fi
echo "✅ Installation abgeschlossen!"