Skip to content

Instantly share code, notes, and snippets.

@FluffyPira
Last active April 26, 2025 16:49
Show Gist options
  • Save FluffyPira/6418c678fe986ebaf01be1eced94d599 to your computer and use it in GitHub Desktop.
Save FluffyPira/6418c678fe986ebaf01be1eced94d599 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Declare some variables. Who we wnat to mail, where we want to log.
user="pi"
log="/var/log/updates-$(date +%Y%m%d)"
message=""
# Fetch any system updates and apply them.
echo -e "\e[38;5;161mUPDATING SYSTEM:\e[0m"
message=$(apt-get update -y)
message="${message}$(apt-get upgrade -y)"
# Do some clean up for unused and depreciated packages.
echo -e "\e[38;5;161mCLEANING SYSTEM:\e[0m"
message="${message}$(apt-get autoremove -y)"
message="${message}$(apt-get clean -y)"
# Check to see if system has flatpak
if [ $(which flatpak &> /dev/null; echo $?) -eq 0 ]; then
echo -e "\e[38;5;161mUPDATING FLATPAK:\e[0m"
message="${message}$(flatpak update -y)"
fi
# Do the same for snap
if [ $(which snap &> /dev/null; echo $?) -eq 0 ]; then
echo -e "\e[38;5;161mUPDATING SNAP:\e[0m"
message="${message}$(snap refresh)"
fi
echo "$message" &> "$log"
echo "System Upated"
mail -s "System Update $(date +%Y%m%d)" pi@localhost <<< "$message"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment