Skip to content

Instantly share code, notes, and snippets.

@kjartanhr
Created August 14, 2024 16:03
Show Gist options
  • Save kjartanhr/15ac77efdef82f68bbcc963168335fa9 to your computer and use it in GitHub Desktop.
Save kjartanhr/15ac77efdef82f68bbcc963168335fa9 to your computer and use it in GitHub Desktop.
automatically update discord on debian/ubuntu systems
#!/bin/bash
URL="https://discord.com/api/download?platform=linux&format=deb"
DL=$(curl -w "%{url_effective}" -I -L -s -S $URL -o /dev/null)
DEB=$(echo $DL | grep -o 'discord-.*\.deb$')
VER=$(echo $DEB | grep -o '[0-9]*\.[0-9]*\.[0-9]*')
INSTALLED=$(ls ~/.config/discord/ | grep '[0-9]*\.[0-9]*\.[0-9]*' | head -1)
if [ "$VER" = "$INSTALLED" ]; then
echo "Running latest Discord version ($VER), skipping update."
exit 0
else
echo "Automatically updating Discord from $INSTALLED to $VER..."
if ! wget "$DL" -P ~/Downloads/; then
echo "Failed to download deb package."
exit 1
fi
if ! sudo dpkg -i "~/Downloads/$DEB"; then
echo "Failed to install $DEB."
exit 2
fi
echo "Automatically updated Discord to version $VER."
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment