publish discord auto updater

This commit is contained in:
2026-01-19 13:09:48 -06:00
commit f0e284138a
4 changed files with 101 additions and 0 deletions

32
README.md Normal file
View File

@@ -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
```

9
update-discord.service Normal file
View File

@@ -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

50
update-discord.sh Normal file
View File

@@ -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

10
update-discord.timer Normal file
View File

@@ -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