Skip to content

Instantly share code, notes, and snippets.

@quonic
Last active April 11, 2025 01:21
Show Gist options
  • Save quonic/5a5424aaadfa494c0fa1b886805a29bd to your computer and use it in GitHub Desktop.
Save quonic/5a5424aaadfa494c0fa1b886805a29bd to your computer and use it in GitHub Desktop.
#!/bin/bash
# License: MIT
# Author: Quonic/Spyingwind
# Description: This script installs or updates Discord on Linux.
# Version: 1.0
# Usage: ./update_discord.sh
# Dependencies: wget, tar
# Script to install or update Discord on Linux
# This script will download the latest version of Discord from the official website,
# extract it, and replace the existing installation.
# Note: If installing you will still need to create a desktop entry manually or
# copy the one from the previous version and modify it accordingly.
install_dir="/home/$USER/Applications/Discord"
install_url="https://discord.com/api/download?platform=linux&format=tar.gz"
archive_file="discord.tar.gz"
temp_archive="/tmp/${archive_file}"
temp_dir="/tmp/Discord"
isUpdate="false"
# Check if the installation directory exists
if [ ! -d "${install_dir}" ]; then
echo "[Info] Installation directory does not exist: ${install_dir}"
echo "[Info] Creating directory..."
if mkdir -p "${install_dir}"; then
echo "[Info] Directory created successfully: ${install_dir}"
echo "[Info] Proceeding with installation..."
else
echo "[Error] Failed to create directory: ${install_dir}"
exit 1
fi
else
isUpdate="true"
echo "[Info] Installation directory exists: ${install_dir}"
echo "[Info] Proceeding with update..."
fi
# Go to the temp folder
pushd /tmp || exit
# Download the latest Discord source archive
if wget "${install_url}" -O "${archive_file}"; then
echo "[Info] Discord source archive downloaded successfully from ${install_url} to ${temp_archive}"
else
echo "[Error] Failed to download Discord source archive: ${install_url}"
exit 1
fi
# Extract the Discord source archive
if tar -xzf "${archive_file}" -C /tmp/; then
echo "[Info] Discord source archive extracted successfully to ${temp_dir}"
else
echo "[Error] Failed to extract Discord source archive: ${temp_archive}"
exit 1
fi
# Replace the existing Discord installation with the new one
if cp -r /tmp/Discord/* "${install_dir}"; then
echo "[Info] Discord updated successfully."
else
echo "[Error] Failed to update Discord."
exit 1
fi
# Remove the old Discord source archive
if rm "${temp_archive}"; then
echo "[Info] Discord source archive removed successfully from ${temp_archive}"
else
echo "[Error] Failed to remove Discord source archive: ${temp_archive}"
exit 1
fi
if rm -rf "${temp_dir}"; then
echo "[Info] Discord source archive removed successfully from ${temp_dir}"
else
echo "[Error] Failed to remove Discord source directory: ${temp_dir}"
exit 1
fi
if [[ "${isUpdate}" == "true" ]]; then
echo "[Info] Discord installed successfully."
echo "[Info] You can now run Discord from ${install_dir}."
else
echo "[Info] Discord updated successfully."
echo "[Info] You can now run Discord from ${install_dir}."
fi
# Return to the previous directory
popd || exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment