Created
August 11, 2022 17:36
-
-
Save mark-kubacki/0b5c051402c4185a4e0767e9f9a17cda to your computer and use it in GitHub Desktop.
Container Discord and its update script
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
# .local/share/applications/Discord.desktop | |
[Desktop Entry] | |
Name=Discord Chat | |
Icon=/opt/Discord/discord.png | |
StartupWMClass=discord | |
Comment=Discord Chat | |
Exec=sudo /usr/bin/systemctl start [email protected] | |
Terminal=false | |
Type=Application | |
Categories=Network;InstantMessaging; | |
Path=/usr/bin |
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
# /etc/systemd/user/[email protected] | |
[Unit] | |
Description=Discord-App | |
After=multi-user.target | |
After=network-online.target | |
Wants=network-online.target | |
[Service] | |
IPAccounting=yes | |
CPUSchedulingPolicy=batch | |
IOSchedulingPriority=6 | |
Environment="XDG_RUNTIME_DIR=/run/user/%i" "DISPLAY=:0" "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%i/bus" | |
WorkingDirectory=/opt/Discord | |
ExecStart=/opt/Discord/Discord | |
Restart=no | |
TimeoutStopSec=5s | |
KillMode=mixed | |
User=%i | |
Slice=user-%i.slice | |
NoNewPrivileges=true | |
ProtectControlGroups=true | |
PrivateTmp=yes | |
ProtectSystem=strict | |
ProtectHome=tmpfs | |
BindPaths="/home/mark/.config/discord" "-/home/mark/Pictures" "-/home/mark/Downloads" | |
BindPaths=/run/user/%i | |
InaccessiblePaths=-/var/480 -/opt/go | |
ProtectProc=noaccess | |
ProcSubset=pid | |
# Make it more likely that, on low memory, this service gets terminated. | |
OOMScoreAdjust=500 |
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/bash | |
# This /usr/local/sbin/update-discord.sh will update the Discord in /opt/Discord | |
set -eupo pipefail | |
if [[ -t 1 ]] && command -v 'tput' &>/dev/null && tput colors >&/dev/null; then | |
V_BOLD_RED=$(tput bold; tput setaf 1) | |
V_BOLD_GREEN=$(tput bold; tput setaf 2) | |
V_VIDOFF=$(tput sgr0) | |
else | |
V_BOLD_RED='' | |
V_BOLD_GREEN='' | |
V_VIDOFF='' | |
fi | |
info() { | |
printf "${V_BOLD_GREEN}${1}${V_VIDOFF}\n" | |
} | |
error() { | |
>&2 printf "${V_BOLD_RED}${1}${V_VIDOFF}\n" | |
} | |
: ${D:="/opt/Discord"} | |
: ${PV:="0.0.14"} | |
if [[ -s "${D}/resources/build_info.json" ]]; then | |
read -r PV < <(<"${D}/resources/build_info.json" jq -r '.version') | |
fi | |
declare -r OLDPV="$PV" | |
next_pv=() | |
next_versions() { | |
local parts | |
parts=(${1//./ }) | |
next_pv+=( | |
"$(( ${parts[0]} + 1 )).0.0" | |
"${parts[0]}.$(( ${parts[1]} +1 )).0" | |
"${parts[0]}.${parts[1]}.$(( ${parts[2]} + 1 ))" | |
) | |
} | |
next_versions "${OLDPV}" | |
for PV in "${next_pv[@]}" ${OLDPV}; do | |
download_url="https://dl.discordapp.net/apps/linux/${PV}/discord-${PV}.tar.gz" | |
if curl -fsS --head "${download_url}" &>/dev/null; then | |
break | |
fi | |
done | |
if [[ "${OLDPV}" == "${PV}" ]]; then | |
error "Local version already is at '${PV}'. Exiting." | |
exit 0 | |
fi | |
info "Starting upsert to: ${PV}" | |
echo $PV ${download_url} | |
WORKDIR=$(mktemp -d) | |
trap "rm -rf '${WORKDIR}'" ERR EXIT | |
curl --fail --location --progress-bar \ | |
"${download_url}" \ | |
| tar --no-same-owner --strip-components=1 -C "${WORKDIR}/" -xz | |
rm --one-file-system -rf "${D}"/[a-zA-Z]* | |
mv "${WORKDIR}"/* "${D}"/ | |
info "Done!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment