Created
March 19, 2026 21:02
-
-
Save imaami/473f0151cb4ac241d92170692d3b6b5d to your computer and use it in GitHub Desktop.
An autoupdate-on-launch thing for Discord on Debian
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # | |
| # /usr/local/bin/discord | |
| # Discord autoupdate-on-launch wrapper | |
| update_script="${0/%discord/update-discord.sh}" | |
| [[ ! -x "$update_script" ]] || "$update_script" | |
| exec /usr/bin/discord "$@" |
This file contains hidden or 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
| # /etc/sudoers.d/update-discord | |
| # | |
| # Lets Discord autoupdate wrapper execute `dpkg -i` as root | |
| username ALL=(root) NOPASSWD: /usr/local/bin/update-discord.sh |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # | |
| # /usr/local/bin/update-discord.sh | |
| # Run by /usr/local/bin/discord | |
| api='https://discord.com/api/{}/stable?platform=linux' | |
| chk="${api/{\}/updates}" | |
| dl="${api/{\}/download}" | |
| latest() | |
| { | |
| local o=$(set +o) | |
| set +e | |
| (( UID )) || { | |
| [[ -z "$1" || ! -f "$1" ]] || { | |
| local d=$(dirname "$1") | |
| dpkg -i "$1" | |
| [[ -z "$d" || ! -d "$d" ]] || rm -fr "$d" | |
| } | |
| eval "$o" | |
| return 0 | |
| } | |
| set -o pipefail | |
| local a b | |
| ! a=$(dpkg-query -Wf'${Version}' discord 2>/dev/null) || [[ ! "$a" ]] || | |
| ! b=$(curl -Ss "$chk" | jq -er .name) || [[ ! "$b" || "$b" == "$a" ]] | |
| b=$? | |
| eval "$o" | |
| return "$b" | |
| } | |
| update() | |
| { | |
| local d | |
| ! d=$(mktemp -dp /tmp .update-discord-XXXXXXXX) || [[ ! -d "$d" ]] || { | |
| local f="$d/discord.deb" | |
| ! curl -Ss --follow --output="$f" "$dl" || | |
| [[ ! -f "$f" ]] || exec sudo "$1" "$f" | |
| rm -fr "$d/" | |
| } | |
| } | |
| latest "$1" || update "$0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment