Skip to content

Instantly share code, notes, and snippets.

@franga2000
Created February 21, 2022 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franga2000/12e87b39707c25ad455f5425b2116626 to your computer and use it in GitHub Desktop.
Save franga2000/12e87b39707c25ad455f5425b2116626 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Discord will not launch if it detects it's outdated.
# Since packages sometimes take a day or two to get updated, this script will trick it into launching anyways.
# Of course, you should still install an update as soon as it0s available.
#
# This script requires: curl, jq
# optional: sudo or polkit
#
set -e
discord_dir="$(dirname "$(realpath "$(which discord)")")"
echo Detected discord dir: $discord_dir
if [[ ! -d "$discord_dir" ]]; then
echo "Invalid!"
exit -1
fi
channel="$(jq -r .releaseChannel <$discord_dir/resources/build_info.json)"
current_version="$(jq -r .version <$discord_dir/resources/build_info.json)"
echo Current build: $channel @ $current_version
new_version=$(curl -s 'https://discord.com/api/updates/'$channel'?platform=linux' | jq -r .name)
echo Newest version is $new_version
if [[ "$current_version" = "$new_version" ]]; then
echo Version already newest!
exit 0
fi
sudo=""
if [[ ! -w "$discord_dir/resources/build_info.json" ]]; then
echo Need elevated privileges to modify program files
if command -v pkexec &> /dev/null; then
sudo="pkexec"
else
sudo="sudo"
fi
fi
$sudo tee $discord_dir/resources/build_info.json <<EOF
{
"releaseChannel": "$channel",
"version": "$new_version"
}
EOF
echo Version updated!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment