Last active
October 9, 2023 21:23
-
-
Save adamboutcher/886ab539ad23042fb5fdf48b5d3ab8b6 to your computer and use it in GitHub Desktop.
Discord Linux Installer/Updater for Discord tar (tgz)
This file contains hidden or 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 | |
# Install/Update Discord | |
# v1 | |
# Adam Boutcher - 2021 - IPPP, Durham Uni (UKI-SCOTGRID-DURHAM) | |
URL="https://discord.com/api/download?platform=linux&format=tar.gz" | |
LOC="/opt" | |
#Function: Check that a binary exists | |
#Usage: check_bin command | |
function check_bin() { | |
which $1 1>/dev/null 2>&1 | |
if [[ $? -ne 0 ]]; then | |
echo "$1 cannot be found. Please install it or add it to the path. Exiting." | |
exit 1 | |
fi | |
} | |
check_bin which | |
check_bin echo | |
check_bin rm | |
check_bin mkdir | |
check_bin tar | |
check_bin curl | |
check_bin cat | |
check_bin awk | |
check_bin tr | |
if [ -d ${LOC}/Discord ]; then | |
echo "Updating Discord - ${LOC}/Discord" | |
curver=$(cat ${LOC}/Discord/resources/build_info.json | grep version | awk '{print $2}' | tr -d '"' 2>/dev/null) | |
latver=$(curl -Ls ${URL} -w %{url_effective} -o /dev/null -I | awk -F '/' '{print $6}' 2>/dev/null) | |
if [ $curver != $latver ]; then | |
rm -rf ${LOC}/Discord >/dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Cannot remove old Discord" | |
exit 2 | |
fi | |
else | |
echo "Already Latest" | |
exit 0 | |
fi | |
else | |
echo "Installing Discord - ${LOC}/Discord" | |
fi | |
mkdir -p /tmp/discord_download/ >/dev/null 2>&1 | |
if [ ! -d ${LOC} ]; then | |
mkdir -p ${LOC} >/dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Cannot create ${LOC}" | |
exit 2 | |
fi | |
fi | |
curl -s -L ${URL} -o /tmp/discord_download/discord.tgz >/dev/null 2>&1 | |
tar -xf /tmp/discord_download/discord.tgz -C ${LOC} >/dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Cannot extract Discord to ${LOC}" | |
exit 2 | |
fi | |
rm -rf /tmp/discord_download/ >/dev/null 2>&1 | |
if [ ! -f /usr/share/applications/discord.desktop ]; then | |
cat > /usr/share/applications/discord.desktop << EOF | |
[Desktop Entry] | |
Name=Discord | |
StartupWMClass=discord | |
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone. | |
GenericName=Internet Messenger | |
Exec=${LOC}/Discord/Discord | |
Icon=${LOC}/Discord/discord.png | |
Type=Application | |
Categories=Network;InstantMessaging; | |
Path=/usr/bin | |
EOF | |
#update-desktop-database >/dev/null 2>&1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could make this test for root/userspace?