Created
April 17, 2024 03:58
-
-
Save brandonhs/f026a6238b5f3f174c613cb6a9ded6dc to your computer and use it in GitHub Desktop.
This script is intended to keep you up to date with discord. It keeps track of old versions in dummy text files for simplicity and storage saving purposes. Discord often makes linux users download the deb file every time a new update is available which is a waste of the valuable time of a Linux power user.
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 | |
get_redirected_url() { | |
local url="$1" | |
final_url=$(curl -s -L -o /dev/null -w '%{url_effective}' "$url") | |
echo "$final_url" | |
} | |
extract_version() { | |
local url="$1" | |
if [[ $url =~ /([0-9]+\.[0-9]+\.[0-9]+)/ ]]; then | |
version="${BASH_REMATCH[1]}" | |
echo "$version" | |
else | |
echo "Version number not found" | |
fi | |
} | |
echo "Checking version information." | |
url="https://discord.com/api/download/stable?platform=linux&format=deb" | |
final_url=$(get_redirected_url "$url") | |
version=$(extract_version $final_url) | |
filename="discord-${version}.deb" | |
filepath="discord_versions/${filename}" | |
echo "Final URL: $final_url" | |
echo "Version: $version" | |
# Check if directory exists | |
if [ ! -d "discord_versions" ]; then | |
echo "Creating directory: discord_versions" | |
mkdir "discord_versions" | |
fi | |
if find discord_versions -type f -name "${filename}.txt" | grep -q .; then | |
echo "Version file exists, you are likely up to date." | |
else | |
echo "Version does not exist, downloading and installing." | |
# Delete real file and replace with dummy | |
wget $final_url && sudo apt install "${PWD}/${filename}" && rm "${PWD}/${filename}" && touch "${PWD}/${filepath}.txt" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment