Skip to content

Instantly share code, notes, and snippets.

@filipizydorczyk
Created January 13, 2023 19:21
Show Gist options
  • Save filipizydorczyk/08293b6c9c93d64bf7f94cce23671b74 to your computer and use it in GitHub Desktop.
Save filipizydorczyk/08293b6c9c93d64bf7f94cce23671b74 to your computer and use it in GitHub Desktop.

If you are using discord package from pacman from time to time you get message that you need to download discord extract the package and replace existing /opt/discord directory with new one.

This script is to automate this process. When you download discord archive (tar.gz) from the discord prompt it will be placed in ~/Downloads. This script will look for this archive, unpack it and place new archive in coorect place. Now discord should work when you open it again.

#!/bin/bash

NEW_DISORD_ARCHIVE=$(find ~/Downloads/ -name "discord-*.tar.gz" -printf '%T+ %p\n' | sort | tail -n 1 | cut -d' ' -f2)
DISCORD_LOCATION=/opt/discord
DISCORD_TMP_LOCATION=/tmp/Discord

if [ "$EUID" -eq 0 ]; then
    echo "Please run as regular user"
    exit
fi

if [ ! -f "$NEW_DISORD_ARCHIVE" ]; then
    echo "Please download discord archive first"
    exit
fi

rm -rf "$DISCORD_TMP_LOCATION"
tar -xf "$NEW_DISORD_ARCHIVE" -C /tmp/
sudo rm -rf "$DISCORD_LOCATION"
sudo mv "$DISCORD_TMP_LOCATION" "$DISCORD_LOCATION"
rm -rf "$NEW_DISORD_ARCHIVE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment