Skip to content

Instantly share code, notes, and snippets.

@niklasdewally
Last active December 18, 2023 21:49
Show Gist options
  • Save niklasdewally/3f39822c2db4f483ae8efc69783857b1 to your computer and use it in GitHub Desktop.
Save niklasdewally/3f39822c2db4f483ae8efc69783857b1 to your computer and use it in GitHub Desktop.
Discord Installer
#!/bin/bash
shopt -s nullglob
pp (){
if [ -x "$(command -v cowsay)" ]
then
cowsay "$1"
else
echo "=========="
echo "$1"
echo "=========="
fi
}
# CHECK FOR ROOT
if [[ $(id -u) -ne 0 ]] ; then pp "Please run as root" ; exit 1 ; fi
tmpdir=$(mktemp -d)
pp "Downloading Discord"
wget --output-document="$tmpdir/discord.tar.gz" 'https://discord.com/api/download?platform=linux&format=tar.gz'
tar xf "$tmpdir/discord.tar.gz" --directory="$tmpdir"
pp "Installing to /opt/Discord"
mkdir -p /opt/Discord
rm -rf /opt/Discord/*
cp -r $tmpdir/Discord /opt/
pp "Run postinstallation script"
sudo -u $(logname) sh -c "/opt/Discord/postinst.sh"
pp "Create desktop file"
# https://superuser.com/a/484280/1691435
desktopFile="/home/$(logname)/.local/share/applications/discord.desktop"
echo "Saving desktop entry to $desktopFile"
cat << EOF > $desktopFile
## AUTOGENERATED BY update-discord!
[Desktop Entry]
Name=Discord
StartupWMClass=discord
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
GenericName=Internet Messenger
Path=/opt/Discord
Exec=/opt/Discord/Discord --no-sandbox
Icon=/opt/Discord/discord.png
Type=Application
Categories=Network;InstantMessaging;
EOF
chown $(logname):$(logname) "$desktopFile"
chmod 777 "$desktopFile"
pp "Refresh desktop applications"
sudo -u $(logname) sh -c "xdg-desktop-menu forceupdate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment