Skip to content

Instantly share code, notes, and snippets.

@CorySanin
Last active September 29, 2022 21:39
Show Gist options
  • Save CorySanin/7e962431e23067377f276e748a0e886a to your computer and use it in GitHub Desktop.
Save CorySanin/7e962431e23067377f276e748a0e886a to your computer and use it in GitHub Desktop.
Automatically download the latest Discord in Arch-based distros
#!/bin/bash
# requires jq: pacman -S jq
# requries sudo, gksu, zensu etc for install. Edit the "pacman -U" line to suit your needs.
# The desktop file will attempt to run discord-update
# ln -sf /path/to/discord-update.sh /usr/bin/discord-update
# https://stackoverflow.com/a/246128/11210376
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
cd "$DIR"
CVER=$(awk -F "=" '/pkgver=/ {print $2}' ./PKGBUILD)
LATEST=$(curl -s https://discord.com/api/updates/stable?platform=linux | jq -r .name)
if [[ "$CVER" != "$LATEST" ]]; then
echo "Updating to $LATEST";
rm -rf pkg src ./*.tar.gz ./*.tar.zst ./*.html
/usr/bin/cp ./PKGBUILD.template PKGBUILD
sed -i -e "s/%pkgver%/$LATEST/g" ./PKGBUILD
makepkg
mv ./*.tar.zst ./discord-realtime.tar.zst
gksu pacman -U --noconfirm ./discord-realtime.tar.zst
fi;
/usr/bin/discord
pkgname=discord
_pkgname=Discord
pkgver=%pkgver%
pkgrel=1
pkgdesc="Discord, but the PKGBUILD is automatically updated. Probably a bad idea."
arch=('x86_64')
url='https://discordapp.com'
license=('custom')
depends=('libnotify' 'libxss' 'nspr' 'nss' 'gtk3')
optdepends=('libpulse: Pulseaudio support'
'xdg-utils: Open files')
source=("https://dl.discordapp.net/apps/linux/$pkgver/$pkgname-$pkgver.tar.gz"
'LICENSE.html::https://discordapp.com/terms'
'OSS-LICENSES.html::https://discordapp.com/licenses')
sha512sums=('SKIP'
'SKIP'
'SKIP')
prepare() {
cd $_pkgname
sed -i "s|Exec=.*|Exec=/usr/bin/$pkgname|" $pkgname.desktop
echo 'Path=/usr/bin' >> $pkgname.desktop
sed -i -e "s:/usr/bin/discord:/usr/bin/discord-update:g" $pkgname.desktop
}
package() {
# Install the app
install -d "$pkgdir"/opt/$pkgname
cp -a $_pkgname/. "$pkgdir"/opt/$pkgname
chmod 755 "$pkgdir"/opt/$pkgname/$_pkgname
rm "$pkgdir"/opt/$pkgname/postinst.sh
install -d "$pkgdir"/usr/{bin,share/{pixmaps,applications}}
ln -s /opt/$pkgname/$_pkgname "$pkgdir"/usr/bin/$pkgname
ln -s /opt/$pkgname/discord.png "$pkgdir"/usr/share/pixmaps/$pkgname.png
ln -s /opt/$pkgname/$pkgname.desktop "$pkgdir"/usr/share/applications/$pkgname.desktop
# setuid on chrome-sandbox
chmod u+s "$pkgdir"/opt/$pkgname/chrome-sandbox
# Licenses
install -Dm 644 LICENSE.html "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.html
install -Dm 644 OSS-LICENSES.html "$pkgdir"/usr/share/licenses/$pkgname/OSS-LICENSES.html
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment