118 lines
3.8 KiB
Bash
118 lines
3.8 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
|
|
}
|
|
|
|
# --- Bash-Setup für Debian und Alpine ---
|
|
echo "Führe Bash-Setup durch (Debian/Alpine)…"
|
|
|
|
# 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
|
|
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
|
|
|
|
# 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
|
|
if [ "$shell" != "/bin/bash" ]; then
|
|
echo " $user: $shell → /bin/bash"
|
|
usermod -s /bin/bash "$user"
|
|
fi
|
|
fi
|
|
done < /etc/passwd
|
|
fi
|
|
|
|
# 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
|
|
apk update
|
|
apk add --no-cache nano nano-syntax
|
|
elif is_debian; then
|
|
apt update
|
|
DEBIAN_FRONTEND=noninteractive apt install -y nano
|
|
elif is_arch; then
|
|
pacman -Syu --noconfirm nano nano-syntax-highlighting
|
|
elif is_rhel; then
|
|
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…"
|
|
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
|
|
|
|
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 vollständig abgeschlossen."
|