73 lines
3.1 KiB
Fish
73 lines
3.1 KiB
Fish
function update-system --description "Update system packages depending on OS"
|
|
# Detect operating system
|
|
set -l os (uname -s)
|
|
|
|
# Helper function to run commands with sudo password retry
|
|
function run_with_sudo
|
|
set -l cmd $argv
|
|
while true
|
|
# Trigger sudo verification. If it succeeds, run the actual command.
|
|
if sudo -v
|
|
sudo $cmd
|
|
return $status
|
|
else
|
|
echo (set_color red)"Passwort war inkorrekt oder sudo wurde abgebrochen."(set_color normal)
|
|
read -l -p "echo 'Möchten Sie es erneut versuchen? (j/N): '" confirm
|
|
if not string match -ri '^(j|ja|y|yes)$' "$confirm"
|
|
echo "Abgebrochen."
|
|
return 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
if test "$os" = "Darwin"
|
|
echo (set_color blue)"[Update-System] macOS erkannt. Starte Homebrew Update..."(set_color normal)
|
|
brew update && brew upgrade
|
|
|
|
# Optional global npm packages update if npm is installed
|
|
if type -q npm
|
|
echo (set_color blue)"[Update-System] Aktualisiere globale npm-Pakete..."(set_color normal)
|
|
npm update -g
|
|
end
|
|
else if test -f /etc/arch-release
|
|
echo (set_color blue)"[Update-System] Arch Linux erkannt. Starte vollständiges System-Update..."(set_color normal)
|
|
if type -q yay
|
|
yay -Syu
|
|
set -l orphans (pacman -Qtdq 2>/dev/null)
|
|
if test -n "$orphans"
|
|
echo (set_color blue)"[Update-System] Entferne ungenutzte Abhängigkeiten (autoremove)..."(set_color normal)
|
|
yay -Rns --noconfirm $orphans
|
|
end
|
|
else
|
|
run_with_sudo pacman -Syu
|
|
set -l orphans (pacman -Qtdq 2>/dev/null)
|
|
if test -n "$orphans"
|
|
echo (set_color blue)"[Update-System] Entferne ungenutzte Abhängigkeiten (autoremove)..."(set_color normal)
|
|
run_with_sudo pacman -Rns --noconfirm $orphans
|
|
end
|
|
end
|
|
else if test -f /etc/debian_version
|
|
echo (set_color blue)"[Update-System] Debian/Ubuntu-basiertes System erkannt. Starte vollständiges System-Update..."(set_color normal)
|
|
run_with_sudo apt update
|
|
and run_with_sudo apt upgrade -y
|
|
and run_with_sudo apt dist-upgrade -y
|
|
and run_with_sudo apt autoremove -y
|
|
and run_with_sudo apt autoclean
|
|
else if test -f /etc/fedora-release
|
|
echo (set_color blue)"[Update-System] Fedora erkannt. Starte vollständiges System-Update..."(set_color normal)
|
|
run_with_sudo dnf upgrade --refresh -y
|
|
and run_with_sudo dnf autoremove -y
|
|
else
|
|
echo (set_color red)"[Update-System] Unbekanntes Betriebssystem. Keine automatische Aktualisierung möglich."(set_color normal)
|
|
return 1
|
|
end
|
|
|
|
# Optional: Flatpak-Pakete aktualisieren und ungenutzte Runtimes entfernen
|
|
if test "$os" != "Darwin"; and type -q flatpak
|
|
echo (set_color blue)"[Update-System] Aktualisiere Flatpaks..."(set_color normal)
|
|
flatpak update -y
|
|
flatpak uninstall --unused -y
|
|
end
|
|
end
|