Skip to content

Instantly share code, notes, and snippets.

@svandragt
Last active January 10, 2024 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svandragt/9776828a64d6eba0f19dfd604fbbd94e to your computer and use it in GitHub Desktop.
Save svandragt/9776828a64d6eba0f19dfd604fbbd94e to your computer and use it in GitHub Desktop.
One stop "system and various dev software" updates shop
#!/usr/bin/env bash
update_apt() {
if ! command -v apt-get &> /dev/null
then
return
fi
echo;
echo ">>> Updating apt-get packages..."
sudo apt-get update -qq
sudo apt-get full-upgrade -y
echo ">>> Updating missing linux headers..."
sudo apt-get install linux-headers-$(uname -r) -y
}
update_cargo() {
if ! command -v cargo &> /dev/null
then
return
fi
echo;
echo ">>> Updating cargo global packages..."
cargo install-update --all
}
update_composer() {
if ! command -v composer &> /dev/null
then
return
fi
echo;
echo ">>> Updating composer global packages..."
sudo composer self-update
composer global update
}
update_flatpak() {
if ! command -v flatpak &> /dev/null
then
return
fi
echo;
echo ">>> Updating flatpaks..."
sudo flatpak update -y
flatpak update --user -y
echo ">>> Removing unused flatpaks..."
flatpak uninstall --unused -y
}
update_nvm() {
if ! command -v nvm &> /dev/null
then
return
fi
echo;
echo ">>> Updating nvm lts..."
update-nvm.sh
nvm install "lts/*" --reinstall-packages-from="$(nvm current)"
nvm install "lts/gallium"
nvm list
}
update_pipx() {
if ! command -v pipx &> /dev/null
then
return
fi
echo;
echo ">>> Updating pipx packages..."
pipx upgrade-all
}
update_pyenv() {
if ! command -v pyenv &> /dev/null
then
return
fi
echo;
echo ">>> Updating pyenv packages..."
pyenv update
}
update_snap() {
if ! command -v snap &> /dev/null
then
return
fi
echo;
echo ">>> Updating snaps..."
sudo snap refresh
}
update_zypper() {
if ! command -v zypper &> /dev/null
then
return
fi
echo;
echo ">>> Updating zypper packages..."
sudo zypper dup
sudo zypper ps -s
}
# sys
update_apt
update_zypper
update_snap
update_flatpak
if [[ "$1" == "--full" || "$1" == "-f" ]]; then
sudo apt-get autoremove -y
# web
update_pipx
update_pyenv
update_nvm
update_composer
update_cargo
fi
if [ -f "/var/run/reboot-required" ]; then
echo
echo "Reboot is required."
# Prompt for confirmation
read -p "Do you want to reboot now? (y/N): " answer
# Check the user's response
if [ "$answer" == "y" ]; then
shutdown -r -t now
else
echo "Reboot canceled."
fi
fi
@svandragt
Copy link
Author

svandragt commented Jan 10, 2024

I run this every weekday. Every Monday I run it with the --full switch so that it updates any global tooling.

  • The script checks if any software is installed before calling its update routine.
  • This script has been testing on Ubuntu derivatives (current) and OpenSUSE (past).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment