Discord Updater Script
So someone I know asked if anyone knew if there was a simple way to get Discord to automatically update on Linux. If you don’t know already, discord on Linux does not automatically update and prompts you to install a new .deb version or download the .tar.gz to update. This, admittedly, is quite annoying after the 4th or 5th time you update it.
I know Discord’s versioning is quite standard so I figured it would be an easy script to cook up. Since they already provide a .tar.gz, I decided that would be the simplest for the most machines and got to scripting.
In order to know if Discord needs to update, we first need to know what version we are on. There are two main ways (that I can tell) to do this:
- Check Discord’s version via the binary using
discord --version - Discord has a directory with the current version in
~/.config/discord/<version>/
The downside of option 1 is that it automatically starts the discord application instead of only returning the version.. which is quite annoying, actually. So, I went with option 2. Basically, all that’s happening here is find is finding the curent version directory and xargs is stripping it down to only the version. Then, it gets returned or if it isn’t found unknown is returned.
get_installed_version() {
local installed
installed=$(find "$HOME/.config/discord" -maxdepth 1 -mindepth 1 -type d \
-name '[0-9]*' 2>/dev/null | xargs basename 2>/dev/null || true)
echo "${installed:-unknown}"
}
Next, the latest version is retrieved. Discord’s download link is actually a redirect to the current version, but the first link does provide the current version for me to use. So, I use curl to grab it and then do some grep trickery to clean it up.
get_latest_version() {
local location
location=$(curl -sI --max-redirs 0 "$discord_url" 2>/dev/null \
| grep -i '^location:' | grep -oP '\d+\.\d+\.\d+' | tail -1 || true)
echo "${location:-unknown}"
}
For checking versions, originally I was going to check if the downloaded version is less than the current version, but I realized that’s just over-engineering it and I can just check if they’re the same or not. If they are the same, do nothing; if they aren’t the same, install the latest.
From there, it’s just the generic user install steps with a little bit of logging incase something breaks. I do add both a symlink for CLI startup and a .desktop for starting via tray, as well as some common error fixes regarding chrome-sandbox. This is intended to be run shortly after startup via a delayed cronjob or something similar, but I let the user choose and don’t automatically do it for them.
Check it out on my gitlab or on my github.