Update Ansible/requirement-check.sh

This commit is contained in:
2025-05-07 09:03:13 +00:00
parent f91c5c3282
commit 69d2efc860

View File

@@ -106,9 +106,7 @@ if command -v python3 >/dev/null 2>&1; then
else else
printf "${RED}Nicht gefunden ✗${NC}\n" printf "${RED}Nicht gefunden ✗${NC}\n"
python_pkg="python3" python_pkg="python3"
if [ "$PKG_MANAGER" = "pacman" ]; then [ "$PKG_MANAGER" = "pacman" ] && python_pkg="python"
python_pkg="python"
fi
missing_packages="$missing_packages $python_pkg" missing_packages="$missing_packages $python_pkg"
fi fi
@@ -123,15 +121,17 @@ fi
# 4. Prüfe openssh-server # 4. Prüfe openssh-server
printf "Prüfe openssh-server... " printf "Prüfe openssh-server... "
if systemctl status sshd >/dev/null 2>&1 || service ssh status >/dev/null 2>&1 || ps aux | grep -v grep | grep -q sshd; then if systemctl status sshd >/dev/null 2>&1 \
|| service ssh status >/dev/null 2>&1 \
|| ps aux | grep -v grep | grep -q sshd; then
printf "${GREEN}Vorhanden ✓${NC}\n" printf "${GREEN}Vorhanden ✓${NC}\n"
else else
printf "${RED}Nicht gefunden ✗${NC}\n" printf "${RED}Nicht gefunden ✗${NC}\n"
missing_ssh=true missing_ssh=true
ssh_pkg="openssh-server" ssh_pkg="openssh-server"
if [ "$PKG_MANAGER" = "pacman" ] || [ "$PKG_MANAGER" = "apk" ]; then case $PKG_MANAGER in
ssh_pkg="openssh" pacman|apk) ssh_pkg="openssh" ;;
fi esac
missing_packages="$missing_packages $ssh_pkg" missing_packages="$missing_packages $ssh_pkg"
fi fi
@@ -141,6 +141,17 @@ if [ -n "$missing_packages" ]; then
printf "${BLUE}Starte Installation der fehlenden Pakete...${NC}\n\n" printf "${BLUE}Starte Installation der fehlenden Pakete...${NC}\n\n"
check_root check_root
# Bei Alpine: community-Repo für sudo aktivieren
if [ "$PKG_MANAGER" = "apk" ]; then
printf "${BLUE}Aktiviere community-Repository für sudo...${NC}\n"
# Alpine-Version ermitteln, z.B. "3.18"
ALPINE_VER=$(cut -d. -f1-2 /etc/alpine-release)
REPO_URL="http://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VER}/community"
# Falls noch nicht vorhanden, hinzufügen
grep -qxF "$REPO_URL" /etc/apk/repositories || \
echo "$REPO_URL" >> /etc/apk/repositories
fi
printf "${BLUE}Aktualisiere Paketlisten...${NC}\n" printf "${BLUE}Aktualisiere Paketlisten...${NC}\n"
case $PKG_MANAGER in case $PKG_MANAGER in
apt) apt)
@@ -165,6 +176,7 @@ if [ -n "$missing_packages" ]; then
install_package "$PKG_MANAGER" "$pkg" install_package "$PKG_MANAGER" "$pkg"
done done
# SSH-Server starten, falls nötig
if [ "$missing_ssh" = "true" ]; then if [ "$missing_ssh" = "true" ]; then
printf "${BLUE}Starte SSH-Server...${NC}\n" printf "${BLUE}Starte SSH-Server...${NC}\n"
if command -v systemctl >/dev/null 2>&1; then if command -v systemctl >/dev/null 2>&1; then
@@ -177,42 +189,33 @@ if [ -n "$missing_packages" ]; then
fi fi
fi fi
# Abschließende Überprüfung
echo echo
printf "${BLUE}=== Abschließende Überprüfung ===${NC}\n\n" printf "${BLUE}=== Abschließende Überprüfung ===${NC}\n\n"
all_requirements_met=true all_requirements_met=true
printf "bash: " printf "bash: "
if command -v bash >/dev/null 2>&1; then command -v bash >/dev/null 2>&1 \
printf "${GREEN}Vorhanden ✓${NC}\n" && printf "${GREEN}Vorhanden ✓${NC}\n" \
else || { printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"; all_requirements_met=false; }
printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"
all_requirements_met=false
fi
printf "python3: " printf "python3: "
if command -v python3 >/dev/null 2>&1; then command -v python3 >/dev/null 2>&1 \
printf "${GREEN}Vorhanden ✓${NC}\n" && printf "${GREEN}Vorhanden ✓${NC}\n" \
else || { printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"; all_requirements_met=false; }
printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"
all_requirements_met=false
fi
printf "sudo: " printf "sudo: "
if command -v sudo >/dev/null 2>&1; then command -v sudo >/dev/null 2>&1 \
printf "${GREEN}Vorhanden ✓${NC}\n" && printf "${GREEN}Vorhanden ✓${NC}\n" \
else || { printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"; all_requirements_met=false; }
printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"
all_requirements_met=false
fi
printf "openssh-server: " printf "openssh-server: "
if systemctl status sshd >/dev/null 2>&1 || service ssh status >/dev/null 2>&1 || ps aux | grep -v grep | grep -q sshd; then ( systemctl status sshd >/dev/null 2>&1 \
printf "${GREEN}Vorhanden ✓${NC}\n" || service ssh status >/dev/null 2>&1 \
else || ps aux | grep -v grep | grep -q sshd ) \
printf "${RED}Fehlt trotz Installationsversuch!${NC}\n" && printf "${GREEN}Vorhanden ✓${NC}\n" \
all_requirements_met=false || { printf "${RED}Fehlt trotz Installationsversuch!${NC}\n"; all_requirements_met=false; }
fi
echo echo
if $all_requirements_met; then if $all_requirements_met; then
@@ -222,6 +225,7 @@ if [ -n "$missing_packages" ]; then
echo "Bitte installiere die fehlenden Pakete manuell." echo "Bitte installiere die fehlenden Pakete manuell."
exit 1 exit 1
fi fi
else else
echo echo
printf "${GREEN}Alle Voraussetzungen sind bereits erfüllt. Keine Installation notwendig.${NC}\n" printf "${GREEN}Alle Voraussetzungen sind bereits erfüllt. Keine Installation notwendig.${NC}\n"