Update Linux/SSH/colorscheme.sh
This commit is contained in:
@@ -1,43 +1,113 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
# Dieses Skript muss als root laufen.
|
||||
|
||||
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\\] # '
|
||||
else\n PS1='\\[\\e[1;32m\\]\\u\\[\\e[0;33m\\]@\\[\\e[1;95m\\]\\h \\\[\\e[1;34m\\]\\w\\[\\e[0m\\] \\\$ '
|
||||
fi\n"
|
||||
|
||||
# Sicherstellen, dass die Datei ~/.dircolors erstellt wird
|
||||
dircolors -p > ~/.dircolors
|
||||
|
||||
# Funktion, um die .bashrc Datei zu aktualisieren
|
||||
update_bashrc() {
|
||||
local user_home=$1
|
||||
local bashrc_file="$user_home/.bashrc"
|
||||
|
||||
# Sicherstellen, dass die Datei existiert
|
||||
touch "$bashrc_file"
|
||||
|
||||
# Prüfen, ob der Inhalt bereits existiert, wenn nicht, hinzufügen
|
||||
if ! grep -q "Farbiges ls und grep" "$bashrc_file"; then
|
||||
echo -e "$BASHRC_CONTENT" >> "$bashrc_file"
|
||||
echo "$bashrc_file wurde aktualisiert."
|
||||
else
|
||||
echo "$bashrc_file ist bereits aktuell."
|
||||
fi
|
||||
|
||||
# .dircolors in das Benutzerverzeichnis kopieren (außer für root)
|
||||
if [ "$user_home" != "/root" ]; then
|
||||
cp ~/.dircolors "$user_home/.dircolors"
|
||||
chown $(basename $user_home):$(basename $user_home) "$user_home/.dircolors"
|
||||
fi
|
||||
# --- Distros erkennen ---
|
||||
is_alpine() {
|
||||
[ -f /etc/alpine-release ] || grep -Eq '^ID="?alpine"?$' /etc/os-release 2>/dev/null
|
||||
}
|
||||
is_debian() {
|
||||
grep -Eq '^(ID|ID_LIKE)=.*(debian|ubuntu)' /etc/os-release 2>/dev/null
|
||||
}
|
||||
is_arch() {
|
||||
grep -Eq '^ID="?arch"?$' /etc/os-release 2>/dev/null
|
||||
}
|
||||
is_rhel() {
|
||||
grep -Eq '^(ID|ID_LIKE)=.*(rhel|fedora|centos)' /etc/os-release 2>/dev/null
|
||||
}
|
||||
|
||||
# Aktualisiere die .bashrc Datei für root
|
||||
update_bashrc /root
|
||||
# --- 1) Bash-Teil: nur auf Alpine ---
|
||||
if is_alpine; then
|
||||
echo "Alpine Linux erkannt – führe Bash‑Installation/-Konfig durch."
|
||||
|
||||
# Aktualisiere die .bashrc Datei für alle Benutzer im /home Verzeichnis
|
||||
for dir in /home/*; do
|
||||
if [ -d "$dir" ]; then
|
||||
update_bashrc "$dir"
|
||||
# Bash installieren, falls nicht vorhanden
|
||||
if ! command -v bash >/dev/null 2>&1; then
|
||||
echo " → Bash nicht gefunden, installiere mit apk..."
|
||||
apk update
|
||||
apk add --no-cache bash
|
||||
else
|
||||
echo " → Bash bereits installiert."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Skriptausführung abgeschlossen."
|
||||
# /bin/bash in /etc/shells eintragen
|
||||
if ! grep -Fxq "/bin/bash" /etc/shells; then
|
||||
echo "/bin/bash" >> /etc/shells
|
||||
echo " → /bin/bash zu /etc/shells hinzugefügt."
|
||||
fi
|
||||
|
||||
# Default‑Shell aller User (UID≥1000 und root) auf /bin/bash 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
|
||||
if [ "$shell" != "/bin/bash" ]; then
|
||||
echo " $user: $shell → /bin/bash"
|
||||
usermod -s /bin/bash "$user"
|
||||
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 ---
|
||||
echo "Installiere/configuriere Nano + Syntax‑Highlighting…"
|
||||
|
||||
if is_alpine; then
|
||||
apk update
|
||||
apk add --no-cache nano nano-syntax
|
||||
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
|
||||
yum install -y nano
|
||||
elif command -v pacman >/dev/null; then
|
||||
pacman -Syu --noconfirm nano
|
||||
fi
|
||||
fi
|
||||
|
||||
# ensure include line in /etc/nanorc
|
||||
NANORC=/etc/nanorc
|
||||
INCLUDE='include "/usr/share/nano/*.nanorc"'
|
||||
if ! grep -Fxq "$INCLUDE" $NANORC; then
|
||||
echo "$INCLUDE" >> $NANORC
|
||||
echo " → Nano: Syntax‑Highlighting in $NANORC aktiviert."
|
||||
else
|
||||
echo " → Nano: Syntax‑Highlighting bereits aktiviert."
|
||||
fi
|
||||
|
||||
echo "Skript fertig."
|
||||
|
||||
Reference in New Issue
Block a user