tb-dotfiles/chezmoi/dot_zshrc.d/executable_upgrade_system.sh

97 lines
2 KiB
Bash
Raw Normal View History

#!/bin/bash
upgrade_system() {
(
set -euo pipefail
case "$(uname | tr '[:upper:]' '[:lower:]')" in
'darwin')
if command -v brew &> /dev/null; then
brew update
brew upgrade
fi
;;
'linux')
2021-12-16 09:47:24 -05:00
# Flatpak (could be just about any distro)
if command -v flatpak &> /dev/null; then
flatpak update
fi
# Debian/Ubuntu
if command -v apt &> /dev/null; then
sudo "$SHELL" -c 'apt update && apt upgrade'
fi
# Fedora
if command -v dnf &> /dev/null; then
sudo dnf upgrade
fi
# Arch
if command -v yay &> /dev/null; then
yay -Syu --devel --timeupdate
elif command -v pacman &> /dev/null; then
sudo pacman -Syu
fi
;;
esac
2022-06-24 20:38:28 -04:00
if command -v asdf &> /dev/null; then
2023-09-29 12:16:58 -04:00
asdf update || true
asdf plugin update --all
echo -e 'package\tversion\tlatest\tstatus'
awk '{
package = $1
if(package == "nodejs") {
next
}
installed_version = $2
"asdf latest " package | getline
latest_version = $0
printf package"\t"installed_version"\t"latest_version"\t"
if(installed_version == latest_version) {
print "up-to-date"
} else {
print "out-of-date"
}
}' "${HOME}/.tool-versions"
if grep -q '^nodejs' "${HOME}/.tool-versions"; then
2023-09-28 10:10:41 -04:00
asdf list all nodejs |
awk -v lts="$(asdf nodejs resolve lts)" \
2023-09-29 12:16:58 -04:00
-v current="$(asdf current nodejs | awk '{print $2}')" \
'index($0, lts) == 1 {latest=$0} END {
printf "nodejs\t"current"\t"latest"\t"
if(latest == current) {
print "up-to-date"
} else {
print "out-of-date"
}
}'
fi
2022-06-24 20:38:28 -04:00
fi
if command -v fwupdmgr &> /dev/null; then
(
# 2 is a valid exit code for the fwupdmgr where
# the operation was successful but did not require
# action
set +e
fwupdmgr refresh
STATUS=$?
if [ $STATUS -ne 0 ] && [ $STATUS -ne 2 ]; then
exit $STATUS
fi
fwupdmgr upgrade
STATUS=$?
if [ $STATUS -ne 0 ] && [ $STATUS -ne 2 ]; then
exit $STATUS
fi
)
fi
)
2020-05-25 13:56:17 -04:00
}