Last active
February 15, 2023 20:20
-
-
Save andrewmackrodt/97a42ceb82c46643eaa5859c41c4fd8a to your computer and use it in GitHub Desktop.
Updates an existing discord installation to the latest version on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo -n "detecting installed version: " | |
installed=$(dpkg -l | awk '$1 == "ii" && $2 == "discord" { print $3 }') | |
if [[ "$installed" == "" ]]; then | |
echo "error" | |
exit 1 | |
fi | |
echo "$installed" | |
echo -n "detecting latest version: " | |
url=$( \ | |
curl --head 'https://discord.com/api/download?platform=linux&format=deb' 2>&1 \ | |
| sed -nE 's#^location: (.+/discord-([^/]+)\.deb)#\1#ip' \ | |
| sed -E 's/\r//g' \ | |
) | |
latest=$(echo "$url" | sed -nE 's#.+/discord-([^/]+)\.deb#\1#p') | |
if [[ "$latest" == "" ]]; then | |
echo "error" | |
exit 2 | |
fi | |
echo "$latest" | |
echo -n "updated required: " | |
if [[ "$installed" == "$latest" ]]; then | |
echo "no" | |
exit 0 | |
fi | |
echo "yes" | |
file="$HOME/Downloads/$(basename "$url")" | |
echo "download location: $url" | |
echo "download path: file://$file" | |
echo -n "download path exists: " | |
if [[ ! -f "$file" ]]; then | |
echo "no" | |
echo -n "download status: " | |
curl -fsSL -o "$file" "$url" | |
if [[ $? -ne 0 ]]; then | |
echo "error" | |
exit 3 | |
fi | |
echo "ok" | |
else | |
echo "yes" | |
fi | |
echo "install required: yes" | |
sudo apt install -qqy "$file" | |
if [[ $? -ne 0 ]]; then | |
echo "update successful: no" | |
exit 4 | |
fi | |
echo "update successful: yes" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment