commit f0e284138ac09f767475cc52919d9c8125b271e3 Author: Evan Date: Mon Jan 19 13:09:48 2026 -0600 publish discord auto updater diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7f61b7 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Discord Automatic Updater +This is a small shell script and systemd service that automatically check for discord updates in the background. It updates Discord by editing `/usr/share/discord/resources/build_info.json` to the most recent version number - the content of the updates are installed by Discord itself when launched. + +Currently, this has only been tested with the debian-based Discord package. It may work with the `.rpm` installer as well - let me know if you try it. Update the appropriate environment variables in `update-discord.sh`. + +## Setup +Run this from inside the Git repo: +```sh +# move the script to a system location and make it executable +sudo mkdir -p /usr/local/bin +sudo cp ./update-discord.sh /usr/local/bin/update-discord +sudo chmod 755 /usr/local/bin/update-discord + +# create the systemd service +sudo cp ./update-discord.service /etc/systemd/system/update-discord.service + +# create the systemd timer +sudo cp ./update-discord.timer /etc/systemd/system/update-discord.timer + +sudo systemctl daemon-reload +sudo systemctl enable --now update-discord.timer +``` +You can manually test it too: +```sh +# check schedule +systemctl list-timers | grep discord + +# manually trigger and check logs +sudo systemctl start update-discord.service +journalctl -u update-discord.service +``` + diff --git a/update-discord.service b/update-discord.service new file mode 100644 index 0000000..5fda526 --- /dev/null +++ b/update-discord.service @@ -0,0 +1,9 @@ +[Unit] +Description=Update Discord +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/update-discord +TimeoutSec=5min diff --git a/update-discord.sh b/update-discord.sh new file mode 100644 index 0000000..c735801 --- /dev/null +++ b/update-discord.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +################ +# CHANGE THESE # +################ + +# path to your build_info.json file; include the file name +DISCORD_BUILD_INFO_PATH="/usr/share/discord/resources/build_info.json" + +# for debian-based linux distributions (.deb installers) +DISCORD_PLATFORM="linux" +DISCORD_FORMAT="deb" + +########################### +# DON'T CHANGE THIS STUFF # +########################### + +# check for sudo +if [ $(id -g) -ne 0 ]; then + echo "Please run as sudo" + exit 2 +fi + +apt-get update && apt-get install -y jq + +# get currently installed version of Discord +ver_current=$(jq -r ".version" "$DISCORD_BUILD_INFO_PATH") +echo "Discord version $ver_current installed" + +# check latest available Discord version by looking at the headers of the latest Discord download URL +pre_ver_available=$(curl -s -I "https://discord.com/api/download?platform=$DISCORD_PLATFORM&format=$DISCORD_FORMAT" | grep location) + +# trim everything before and after the version number +ver_available="${pre_ver_available#*linux/}" +ver_available="${ver_available%/*}" + +echo "Discord version $ver_available available" + +if [ "$ver_current" = "$ver_available" ] ; then + echo "Discord is up to date!" + exit 0 +fi + +echo "Discord is not up to date, editing $DISCORD_BUILD_INFO_PATH" + +jq ".version = \"$ver_available\"" $DISCORD_BUILD_INFO_PATH > discord_build_info_tmp.json +chmod 644 discord_build_info_tmp.json +mv discord_build_info_tmp.json "$DISCORD_BUILD_INFO_PATH" + +killall Discord diff --git a/update-discord.timer b/update-discord.timer new file mode 100644 index 0000000..8803ff1 --- /dev/null +++ b/update-discord.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run Discord updater daily and after boot + +[Timer] +OnCalendar=*-*-* 03:00:00 +OnBootSec=1min +Persistent=true + +[Install] +WantedBy=timers.target