diff --git a/Linux/SSH/colorscheme.sh b/Linux/SSH/colorscheme.sh index 5ef8f87..1ff3a2e 100644 --- a/Linux/SSH/colorscheme.sh +++ b/Linux/SSH/colorscheme.sh @@ -15,11 +15,11 @@ is_rhel() { grep -Eq '^(ID|ID_LIKE)=.*(rhel|fedora|centos)' /etc/os-release 2>/dev/null } -# --- 1) Bash-Teil: nur auf Alpine --- -if is_alpine; then - echo "Alpine Linux erkannt - führe Bash-Installation/-Konfig durch." +# --- Bash-Setup für Debian und Alpine --- +echo "Führe Bash-Setup durch (Debian/Alpine)…" - # Bash installieren, falls nicht vorhanden +# Bash installieren auf Alpine +if is_alpine; then if ! command -v bash >/dev/null 2>&1; then echo " → Bash nicht gefunden, installiere mit apk..." apk update @@ -34,7 +34,7 @@ if is_alpine; then echo " → /bin/bash zu /etc/shells hinzugefügt." fi - # Default-Shell aller User (UID>=1000 und root) auf /bin/bash setzen + # Standard-Shell für alle Benutzer setzen echo " → Setze Default-Shell auf /bin/bash für alle User:" while IFS=: read -r user pass uid gid home shell; do if [ "$uid" -ge 1000 ] || [ "$uid" -eq 0 ]; then @@ -44,33 +44,41 @@ if is_alpine; then fi fi done < /etc/passwd - - # Setup for coloured LS/PS1 - BASHRC_CONTENT="\n# Farbiges ls und grep\nalias ls='ls --color=auto'\nalias grep='grep --color=auto'\nalias egrep='egrep --color=auto'\nalias fgrep='fgrep --color=auto'\neval \"\$(dircolors -b ~/.dircolors)\"\nif [ \"\$EUID\" -eq 0 ]; then\n PS1='\\[\\e[1;31m\\]\\u\\[\\e[0;33m\\]@\\[\\e[1;95m\\]\\h \\[\\e[1;33m\\]\\w\\[\\e[0m\\] # '\nelse\n PS1='\\[\\e[1;32m\\]\\u\\[\\e[0;33m\\]@\\[\\e[1;95m\\]\\h \\[\\e[1;34m\\]\\w\\[\\e[0m\\] \\$ '\nfi\n" - - # .dircolors ins Skeleton - dircolors -p > /etc/skel/.dircolors - - update_bashrc() { - home=$1; file="$home/.bashrc" - touch "$file" - chown "$(basename "$home")":"$(basename "$home")" "$file" - if ! grep -q "Farbiges ls und grep" "$file"; then - echo -e "$BASHRC_CONTENT" >> "$file" - echo " Aktualisiert: $file" - fi - cp /etc/skel/.dircolors "$home/.dircolors" - chown "$(basename "$home")":"$(basename "$home")" "$home/.dircolors" - } - update_bashrc "/root" - for d in /home/*; do [ -d "$d" ] && update_bashrc "$d"; done - - echo "Bash-Teil auf Alpine abgeschlossen." -else - echo "Kein Alpine - Bash-Teil übersprungen." fi -# --- 2) Nano + Syntax-Highlighting für alle Distros --- +# Bash-Setup (gemeinsam für Debian und Alpine) +BASHRC_CONTENT="\n# Farbiges ls und grep\nalias ls='ls --color=auto'\nalias grep='grep --color=auto'\nalias egrep='egrep --color=auto'\nalias fgrep='fgrep --color=auto'\neval \"\$(dircolors -b ~/.dircolors)\"\nif [ \"\$EUID\" -eq 0 ]; then\n PS1='\\[\\e[1;31m\\]\\u\\[\\e[0;33m\\]@\\[\\e[1;95m\\]\\h \\[\\e[1;33m\\]\\w\\[\\e[0m\\] # '\nelse\n PS1='\\[\\e[1;32m\\]\\u\\[\\e[0;33m\\]@\\[\\e[1;95m\\]\\h \\[\\e[1;34m\\]\\w\\[\\e[0m\\] \\$ '\nfi\n" + +dircolors -p > /etc/skel/.dircolors + +update_bashrc() { + home=$1; file="$home/.bashrc" + echo " → Bearbeite .bashrc für $home" + touch "$file" + chown "$(basename "$home")":"$(basename "$home")" "$file" + if ! grep -q "Farbiges ls und grep" "$file"; then + echo -e "$BASHRC_CONTENT" >> "$file" + echo " Aktualisiert: $file" + fi + cp /etc/skel/.dircolors "$home/.dircolors" + chown "$(basename "$home")":"$(basename "$home")" "$home/.dircolors" + + # sicherstellen, dass ~/.bashrc in ~/.profile geladen wird + prof="$home/.profile" + if ! grep -q '\.bashrc' "$prof" 2>/dev/null; then + echo 'if [ -n "$BASH_VERSION" ]; then' >> "$prof" + echo ' [ -f ~/.bashrc ] && . ~/.bashrc' >> "$prof" + echo 'fi' >> "$prof" + echo " ~/.profile angepasst zum Laden von .bashrc" + fi +} + +update_bashrc "/root" +for d in /home/*; do [ -d "$d" ] && update_bashrc "$d"; done + +echo "Bash-Konfiguration abgeschlossen." + +# --- Nano + Syntax-Highlighting für alle Distros --- echo "Installiere/configuriere Nano + Syntax-Highlighting…" if is_alpine; then @@ -79,18 +87,15 @@ if is_alpine; then elif is_debian; then apt update DEBIAN_FRONTEND=noninteractive apt install -y nano - # Debian liefert /usr/share/nano/*.nanorc meist schon mit elif is_arch; then pacman -Syu --noconfirm nano nano-syntax-highlighting elif is_rhel; then - # EPEL aktivieren, dann Nano-Paket if ! rpm -qa | grep -q epel-release; then yum install -y epel-release fi yum install -y nano nano-syntax-highlighting else echo "Unbekannte Distribution - versuche, Nano zu installieren…" - # Fallback: gängige Paketmanager testen if command -v apt >/dev/null; then apt update && apt install -y nano elif command -v yum >/dev/null; then @@ -100,7 +105,6 @@ else fi fi -# ensure include line in /etc/nanorc NANORC=/etc/nanorc INCLUDE='include "/usr/share/nano/*.nanorc"' if ! grep -Fxq "$INCLUDE" $NANORC; then @@ -110,4 +114,4 @@ else echo " → Nano: Syntax-Highlighting bereits aktiviert." fi -echo "Skript fertig." +echo "Skript vollständig abgeschlossen."