Created
February 25, 2022 22:58
-
-
Save aurieh/4ae8e5dfdb2f31b5e9eb6435a15e5662 to your computer and use it in GitHub Desktop.
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/sh | |
set -eux | |
BRANCH=canary | |
ICONDIR="${XDG_DATA_HOME:=$HOME/.local/share}/icons" | |
APPDIR="$XDG_DATA_HOME/applications" | |
DISCORDDIR="$HOME/.local/opt/discord-$BRANCH" | |
mkdir -p "$ICONDIR" "$APPDIR" "$DISCORDDIR" | |
fail() { | |
printf '%s: %s\n' "$(basename "$0")" "$1" | |
} | |
WORKDIR="$(mktemp -td discord-upgradeXXXXXX)" | |
trap 'rm -r "$WORKDIR"' EXIT | |
download_url="https://discord.com/api/download/$BRANCH?platform=linux&format=tar.gz" | |
etag="$(curl -fsSLI "$download_url" | | |
grep -i '^etag:' | | |
tail -n 1 | | |
# assumes that the etag is hexadecimal, but Discord shouldn't return anything else | |
sed 's/^etag:[[:space:]]*"\([[:xdigit:]]\+\)"\r/\1/')" | |
versionfile="$DISCORDDIR/.discord_upgrade" | |
touch "$versionfile" | |
if [ "$(cat "$versionfile")" != "$etag" ]; then | |
cd "$WORKDIR" | |
curl -fsSLo discord.tar.gz "$download_url" | |
mkdir out | |
tar -C out -xf discord.tar.gz | |
[ "$(echo out/* | wc -l)" -ne 1 ] && fail "discord extracted into more than one top level dir" | |
cp -f out/*/*.png "$ICONDIR/" | |
sed -i -e '/Path=/d' -e "s%/usr/share/discord[[:alpha:]-]*/%$DISCORDDIR/%" out/*/*.desktop | |
mv out/*/*.desktop "$APPDIR/" | |
rsync -a out/*/ "$DISCORDDIR/" | |
printf '%s\n' "$etag" > "$versionfile" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment