Skip to content

Instantly share code, notes, and snippets.

@danilogco
Created November 19, 2024 17:46
Show Gist options
  • Save danilogco/76a12d031c4933ba87c7f420b7f5a727 to your computer and use it in GitHub Desktop.
Save danilogco/76a12d031c4933ba87c7f420b7f5a727 to your computer and use it in GitHub Desktop.
Discord Install / Update script for Linux (tar file)
import os
import requests
import tarfile
import shutil
def download_and_extract_discord():
# URL of the Discord tar.gz file
discord_url = "https://discord.com/api/download?platform=linux&format=tar.gz"
# Set paths
home_dir = os.path.expanduser("~")
apps_dir = os.path.join(home_dir, "Apps")
discord_dir = os.path.join(apps_dir, "Discord")
temp_file = os.path.join(home_dir, "discord.tar.gz")
# Remove the existing Discord directory
if os.path.exists(discord_dir):
print(f"Removing existing Discord directory: {discord_dir}")
shutil.rmtree(discord_dir)
print("Discord directory removed.")
# Ensure the Apps directory exists
if not os.path.exists(apps_dir):
os.makedirs(apps_dir)
print(f"Created directory: {apps_dir}")
# Download the file
print("Downloading Discord...")
response = requests.get(discord_url, stream=True)
if response.status_code == 200:
with open(temp_file, "wb") as f:
for chunk in response.iter_content(chunk_size=1024):
f.write(chunk)
print(f"Downloaded Discord to {temp_file}")
else:
print(f"Failed to download Discord. Status code: {response.status_code}")
return
# Extract the tar.gz file
print("Extracting Discord...")
with tarfile.open(temp_file, "r:gz") as tar:
tar.extractall(path=apps_dir)
print(f"Extracted Discord to {apps_dir}")
# Clean up the downloaded tar.gz file
os.remove(temp_file)
print(f"Removed temporary file: {temp_file}")
print("Discord is ready in your Apps directory!")
if __name__ == "__main__":
download_and_extract_discord()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment