Skip to content

Instantly share code, notes, and snippets.

@sgatu
Created June 26, 2024 21:24
Show Gist options
  • Select an option

  • Save sgatu/d60072d8afefcd50ab37b3f0a7e5660b to your computer and use it in GitHub Desktop.

Select an option

Save sgatu/d60072d8afefcd50ab37b3f0a7e5660b to your computer and use it in GitHub Desktop.
Discord app auto-updater for Debian
#!/bin/bash
#
# Discord App auto-updater for Debian
#
# This script is responsible for managing the Discord application on a system.
# It performs the following tasks:
# 1. Checks if Discord is currently installed on the system.
# 2. If Discord is not installed, the script downloads and installs the latest version.
# 3. If Discord is already installed, the script checks for the latest version online.
# 4. If a newer version of Discord is available, the script downloads and updates Discord to the latest version.
# The script ensures that the user always has the most recent version of Discord installed.
if [ -f "/usr/share/discord/resources/build_info.json" ]; then
installed_version=$(cat "/usr/share/discord/resources/build_info.json" | jq -r ".version")
else
installed_version="not installed"
read -p $'No discord version found. Do you want to install the last version? (y/n)\n' -n 1 -r
echo
if ! [[ $REPLY =~ ^[Yy] ]]; then
exit 0
fi
fi
deb_url=$(curl -s -I "https://discord.com/api/download/stable?platform=linux&format=deb" | grep location | awk -F': ' '{print $2}' | tr -d '\r' | tr -d '\n')
current_version=$(echo $deb_url | awk -F'/' '{print $6}')
if [[ "$installed_version" != "$current_version" ]]; then
echo "Installed version not the same as current. Downloading current version $current_version..."
file_name="discord-$current_version.deb"
curl -s "$deb_url" -o "/tmp/$file_name"
install_command="yes | dpkg -i /tmp/$file_name"
sudo sh -c "$install_command"
rm "/tmp/$file_name"
else
echo "Good news everyone! No new version of Discord available."
sleep 1
fi
nohup discord >/dev/null 2>&1 &
@axelsegebrecht
Copy link

Thanks @sgatu - appreciate it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment