Files
Boilerplates/Linux/SSH/colorscheme.sh

114 lines
3.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
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/sh
# Dieses Skript muss als root laufen.
# --- 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
}
# --- 1) Bash-Teil: nur auf Alpine ---
if is_alpine; then
echo "Alpine Linux erkannt führe BashInstallation/-Konfig durch."
# 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
# /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
# DefaultShell aller User (UID≥1000 und root) auf /bin/bash setzen
echo " → Setze DefaultShell 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 "BashTeil auf Alpine abgeschlossen."
else
echo "Kein Alpine BashTeil übersprungen."
fi
# --- 2) Nano + SyntaxHighlighting für alle Distros ---
echo "Installiere/configuriere Nano + SyntaxHighlighting…"
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: SyntaxHighlighting in $NANORC aktiviert."
else
echo " → Nano: SyntaxHighlighting bereits aktiviert."
fi
echo "Skript fertig."