Files
Boilerplates/Linux/SSH/colorscheme.sh

114 lines
3.7 KiB
Bash

#!/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 Bash-Installation/-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
# 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."