Skip to content

Instantly share code, notes, and snippets.

@markizano
Created February 9, 2024 17:44
Show Gist options
  • Save markizano/3d9caf4fb1d85a1139111b8807643152 to your computer and use it in GitHub Desktop.
Save markizano/3d9caf4fb1d85a1139111b8807643152 to your computer and use it in GitHub Desktop.
Using aptly? update your repos with Discord automatically!
#!/bin/bash
. common.sh
exec > >(log update-discord)
exec 2>&1
function aptly() {
sudo -H -uaptly -gapps aptly $@
}
set -e
download_uri='https://discord.com/api/download?platform=linux&format=deb'
function checkversion() {
discordver=$(basename "`curl -s --head "$download_uri" | dos2unix | grep -i location | cut -d' ' -f2`" .deb | sed s/-/_/)
aptly repo search discord | grep -q "$discordver" && {
echo "We seem to have this discord version $discordver. Exit."
exit 0
} || {
echo "We do not have $discordver. Downloading latest..."
}
}
checkversion
deb=/opt/aptly/tmp/discord.deb
snaps="`aptly snapshot list -raw | grep discord`" || true
snapName="discord-`date +%F`"
rm -f "$deb"
curl -vsL "$download_uri" -o "$deb"
info=`dpkg -I "$deb"`
discordVersion=`echo "$info" | grep Version | awk '{print $2}'`
discordArch=`echo "$info" | grep Arch | awk '{print $2}'`
mv "$deb" "$(dirname $deb)/discord_${discordVersion}-${discordArch}.deb"
deb="$(dirname $deb)/discord_${discordVersion}-${discordArch}.deb"
aptly repo add discord "$deb"
aptly snapshot create "$snapName" from repo discord
aptly publish list -raw | grep -qi discord && aptly publish drop discord || true
chmod g+rw `tty`
chgrp apps `tty`
aptly publish -distribution discord snapshot "$snapName"
test -z "$snaps" || aptly snapshot drop $snaps
rm -f "$deb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment