Skip to content

Instantly share code, notes, and snippets.

@makandz
Created June 7, 2022 02:46
Show Gist options
  • Save makandz/2be23b59ad288ca79cd65fc4ac20e1ab to your computer and use it in GitHub Desktop.
Save makandz/2be23b59ad288ca79cd65fc4ac20e1ab to your computer and use it in GitHub Desktop.
A script to automatically update packages and notify you on Discord
#!/bin/bash
# Base Source: https://gist.github.com/mckinnon81/45f5cec4aacb04b5ba347e27d5bb7717
DISCORD=""
# Check if the script is being run as root exit if it is not.
if [ $(id -u) -ne 0 ]
then
echo "You need to be root to run this script."
exit 1
fi
check_return() {
if [ "$?" -ne "0" ]
then
./discord.sh \
--webhook-url="$DISCORD" \
--username "Ignis" \
--color "0xf05545" \
--title "Server updates failed" \
--field "Something went wrong.. check the server for details?" \
--timestamp
exit 1
fi
}
apt-get clean
check_return "apt-get clean"
apt-get update
check_return "apt-get update"
PACKAGES=$(apt-get -Vs upgrade | perl -ne 'print if /upgraded:/ .. /upgraded,/')
if [ -z "$PACKAGES" ]
then
PACKAGES="Nothing to update!"
fi
check_return "apt-get -yq upgrade"
sudo apt autoremove -y
./discord.sh \
--webhook-url="$DISCORD" \
--username "Ignis" \
--color "0x5eb8ff" \
--title "Server updates completed" \
--field "Packages;$PACKAGES" \
--timestamp
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment