upgpkg: discord 0.0.55-2: refactor, fix autostart, add deps, use wayland

* Slightly refactor PKGBUILD
* Fix autostart desktop file
* Add optional dependency used in official arch package
* Include patcher to allow Krisp noise suppression support
* Add install file to inform user about this change
* Use Wayland instead of Xwayland in a Wayland session by setting
  Electron flag `ozone-platform-hint` to auto (default is X11)
This commit is contained in:
Manuel 2024-06-09 21:58:06 +02:00
parent 3cb800694b
commit 9fafba484a
Signed by: Manuel
GPG key ID: 4085037435E1F07A
6 changed files with 252 additions and 47 deletions

View file

@ -1,25 +1,29 @@
pkgbase = discord_arch_electron pkgbase = discord_arch_electron
pkgdesc = Discord (popular voice + video app) using the system provided electron for increased security and performance pkgdesc = Discord using system provided electron29 for increased security and performance
pkgver = 0.0.55 pkgver = 0.0.55
pkgrel = 1 pkgrel = 2
url = https://discord.com url = https://discord.com
install = discord_arch_electron.install
arch = any arch = any
license = custom license = custom
makedepends = asar makedepends = asar
makedepends = curl
depends = electron29 depends = electron29
depends = libxss depends = libxss
depends = python
optdepends = libpulse: Pulseaudio support optdepends = libpulse: Pulseaudio support
optdepends = libappindicator-gtk3: Systray indicator support
optdepends = xdg-utils: Open files optdepends = xdg-utils: Open files
optdepends = python-pyelftools: Required for Krisp patcher
optdepends = python-capstone: Required for Krisp patcher
provides = discord provides = discord
conflicts = discord conflicts = discord
options = !strip options = !strip
source = https://dl.discordapp.net/apps/linux/0.0.55/discord-0.0.55.tar.gz source = https://dl.discordapp.net/apps/linux/0.0.55/discord-0.0.55.tar.gz
source = discord-launcher.sh source = discord-launcher.sh
source = LICENSE.html::https://discord.com/terms source = krisp-patcher.py
source = OSS-LICENSES.html::https://discord.com/licenses
sha512sums = c12365109cb4db94033fda101073d2a3d6af7bdc9728e025494ee8d44ebf5f27623861879ec38bb7dd88d40de7cddede268e0f5e44bfeb586fc12713a3758c5b sha512sums = c12365109cb4db94033fda101073d2a3d6af7bdc9728e025494ee8d44ebf5f27623861879ec38bb7dd88d40de7cddede268e0f5e44bfeb586fc12713a3758c5b
sha512sums = d398351b209cd89432d8e9cebe9122f152484236d8ca4dd91e5679d3853fe2f082625d35a9ac3f450f1f08250736bf3a23db9926311e8271730d884b57d12dbc sha512sums = 88d8b7ae7efc4cb7173de1b0a209c3ae844e43685b1c042e6fe993099ce869dc0d072aa6a13bd5e56e2ebdaa2609ae5c90c6c93333ee2ec912e2d74d9c59f42a
sha512sums = SKIP sha512sums = 3c1021592fa856f3561072c76b5ee0b5a34a53bc230336e6d36827efb4866c9d801ef7abb24650d3a7210c61dd57f35e2812ae89226fc157cc8d9ffce032155f
sha512sums = SKIP
pkgname = discord_arch_electron pkgname = discord_arch_electron

View file

@ -1,60 +1,88 @@
# Maintainer: Zoddo <archlinux+aur@zoddo.fr> # Maintainer: Zoddo <archlinux+aur@zoddo.fr>
# Contributor: Thaodan <AUR+me@thaodan.de> # Contributor: Thaodan <AUR+me@thaodan.de>
# Contributor: Manuel Hüsers <aur@huesers.de>
# Contributor: huyizheng # Contributor: huyizheng
# Contributor: johnnyapol <arch@johnnyapol.me> # Contributor: johnnyapol <arch@johnnyapol.me>
# Based off the discord community repo PKGBUILD by Filipe Laíns (FFY00) <lains@archlinux.org> # Based off the discord community repo PKGBUILD by Filipe Laíns (FFY00) <lains@archlinux.org>
_pkgname=discord _pkgname=discord
_electron=electron29 _electron=electron29
pkgname=${_pkgname}_arch_electron pkgname=${_pkgname}_arch_electron
pkgver=0.0.55 pkgver=0.0.55
pkgrel=1 pkgrel=2
pkgdesc="Discord (popular voice + video app) using the system provided electron for increased security and performance" pkgdesc="Discord using system provided ${_electron} for increased security and performance"
arch=('any') arch=('any')
provides=("${_pkgname}") provides=("${_pkgname}")
conflicts=("${_pkgname}") conflicts=("${_pkgname}")
url='https://discord.com' url='https://discord.com'
license=('custom') license=('custom')
options=(!strip) options=('!strip')
depends=("${_electron}" 'libxss') install="$pkgname.install"
makedepends=('asar') depends=("${_electron}" 'libxss' 'python')
makedepends=('asar' 'curl')
optdepends=('libpulse: Pulseaudio support' optdepends=('libpulse: Pulseaudio support'
'xdg-utils: Open files') 'libappindicator-gtk3: Systray indicator support'
source=("https://dl.discordapp.net/apps/linux/$pkgver/$_pkgname-$pkgver.tar.gz" 'xdg-utils: Open files'
'python-pyelftools: Required for Krisp patcher'
'python-capstone: Required for Krisp patcher')
source=("https://dl.discordapp.net/apps/linux/${pkgver}/${_pkgname}-${pkgver}.tar.gz"
'discord-launcher.sh' 'discord-launcher.sh'
'LICENSE.html::https://discord.com/terms' 'krisp-patcher.py') # original: https://github.com/sersorrel/sys/blob/main/hm/discord/krisp-patcher.py
'OSS-LICENSES.html::https://discord.com/licenses')
sha512sums=('c12365109cb4db94033fda101073d2a3d6af7bdc9728e025494ee8d44ebf5f27623861879ec38bb7dd88d40de7cddede268e0f5e44bfeb586fc12713a3758c5b' sha512sums=('c12365109cb4db94033fda101073d2a3d6af7bdc9728e025494ee8d44ebf5f27623861879ec38bb7dd88d40de7cddede268e0f5e44bfeb586fc12713a3758c5b'
'd398351b209cd89432d8e9cebe9122f152484236d8ca4dd91e5679d3853fe2f082625d35a9ac3f450f1f08250736bf3a23db9926311e8271730d884b57d12dbc' '88d8b7ae7efc4cb7173de1b0a209c3ae844e43685b1c042e6fe993099ce869dc0d072aa6a13bd5e56e2ebdaa2609ae5c90c6c93333ee2ec912e2d74d9c59f42a'
SKIP '3c1021592fa856f3561072c76b5ee0b5a34a53bc230336e6d36827efb4866c9d801ef7abb24650d3a7210c61dd57f35e2812ae89226fc157cc8d9ffce032155f')
SKIP)
prepare() { prepare() {
sed -i "s|@PKGNAME@|${_pkgname}|;s|@ELECTRON@|${_electron}|" discord-launcher.sh # prepare launcher script
sed -i "s|Exec=.*|Exec=/usr/bin/$_pkgname|" Discord/discord.desktop sed -i -e "s|@PKGNAME@|${_pkgname}|" \
-e "s|@PKGVER@|${pkgver}|" \
-e "s|@ELECTRON@|${_electron}|" \
discord-launcher.sh
# HACKS FOR SYSTEM ELECTRON # fix the .desktop file
asar e Discord/resources/app.asar Discord/resources/app sed -i -e "s|Exec=.*|Exec=/usr/bin/${_pkgname}|" ${_pkgname^}/$_pkgname.desktop
rm Discord/resources/app.asar
sed -i "s|process.resourcesPath|'/usr/share/${_pkgname}/resources'|" Discord/resources/app/app_bootstrap/buildInfo.js # create the license files
sed -i "s|exeDir,|'/usr/share/pixmaps',|" Discord/resources/app/app_bootstrap/autoStart/linux.js curl -o "${srcdir}/LICENSE.html" https://discord.com/terms
sed -i -E "s|resourcesPath = _path.+;|resourcesPath = '/usr/share/${_pkgname}/resources';|" Discord/resources/app/common/paths.js curl -o "${srcdir}/OSS-LICENSES.html" https://discord.com/licenses
asar p Discord/resources/app Discord/resources/app.asar }
rm -rf Discord/resources/app
build() {
cd "${srcdir}/${_pkgname^}"
# use system electron
asar e resources/app.asar resources/app
rm resources/app.asar
sed -i -e "s|resourcesPath = _path.*;|resourcesPath = '/usr/share/${_pkgname}/resources';|" resources/app/common/paths.js
sed -i -e "s|process.resourcesPath|'/usr/share/${_pkgname}/resources'|" resources/app/app_bootstrap/buildInfo.js
sed -i -e "/^const appName/d" -e "/^const exePath/d" -e "/^const exeDir/d" -e "/^const iconPath/d" \
-e "s|^Exec=\${exePath}$|Exec=/usr/bin/${_pkgname}|" \
-e "s|^Name=\${appName}$|Name=${_pkgname^}|" \
-e "s|^Icon=\${iconPath}$|Icon=/usr/share/pixmaps/${_pkgname}.png|" \
resources/app/app_bootstrap/autoStart/linux.js
asar p resources/app resources/app.asar
rm -rf resources/app
} }
package() { package() {
# Install the app # create necessary directories
install -d "${pkgdir}/usr/share/${_pkgname}/resources" install -d "${pkgdir}/usr/share/${_pkgname}"
# Copy Relevanat data # copy relevant data
cp -r Discord/resources/* "${pkgdir}/usr/share/${_pkgname}/resources/" cp -r ${_pkgname^}/resources "${pkgdir}/usr/share/${_pkgname}/"
install -Dm 755 "${srcdir}/discord-launcher.sh" "${pkgdir}/usr/bin/${_pkgname}" # intall icon and desktop file
install -Dm 644 ${_pkgname^}/$_pkgname.png "${pkgdir}/usr/share/pixmaps/${_pkgname}.png"
install -Dm 644 ${_pkgname^}/$_pkgname.desktop "${pkgdir}/usr/share/applications/${_pkgname}.desktop"
install -Dm 644 Discord/discord.png "${pkgdir}/usr/share/pixmaps/${_pkgname}.png" # install the launch script
install -Dm 644 Discord/discord.desktop "${pkgdir}/usr/share/applications/${_pkgname}.desktop" install -Dm 755 discord-launcher.sh "${pkgdir}/usr/bin/${_pkgname}"
# Licenses # install krisp patcher
install -Dm 644 LICENSE.html "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.html install -Dm 644 krisp-patcher.py "${pkgdir}/usr/share/${_pkgname}/"
install -Dm 644 OSS-LICENSES.html "$pkgdir"/usr/share/licenses/$pkgname/OSS-LICENSES.html
# install 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"
} }

View file

@ -1,14 +1,25 @@
#!/usr/bin/bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
name=@PKGNAME@ name=@PKGNAME@
ver=@PKGVER@
electron=@ELECTRON@ electron=@ELECTRON@
flags_file="${XDG_CONFIG_HOME:-$HOME/.config}/${name}-flags.conf"
declare -a flags declare -a flags
declare -l PATCH_KRISP
if [[ -f "${flags_file}" ]]; then [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/${name}.conf" ]] && source "${XDG_CONFIG_HOME:-$HOME/.config}/${name}.conf"
flags_file="${XDG_CONFIG_HOME:-$HOME/.config}/${name}-flags.conf"
krisp_bin="${DISCORD_USER_DATA_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/${name}}/${ver}/modules/${name}_krisp/${name}_krisp.node"
if [[ "${PATCH_KRISP}" == true ]] && [[ -w "${krisp_bin}" ]] && python -c "import capstone; import elftools" &> /dev/null; then
# Patch Krisp binary to ignore signature check
python /usr/share/${name}/krisp-patcher.py "${krisp_bin}"
fi
if [[ -r "${flags_file}" ]]; then
mapfile -t < "${flags_file}" mapfile -t < "${flags_file}"
fi fi
@ -18,4 +29,7 @@ for line in "${MAPFILE[@]}"; do
fi fi
done done
exec /usr/bin/${electron} /usr/share/${name}/resources/app.asar "${flags[@]}" "$@" exec /usr/bin/${electron} \
/usr/share/${name}/resources/app.asar \
--ozone-platform-hint=auto \
"${flags[@]}" "$@"

View file

@ -0,0 +1,19 @@
post_upgrade() {
# return if old package version is greater than or equal to 0.0.55-2...
(( $(vercmp $2 '0.0.55-2') >= 0 )) && return
cat <<EOF
==> In order to patch Krisp noise suppression support set 'PATCH_KRISP=true'
in '~/.config/discord.conf' and install the necessary optional dependencies.
EOF
}
post_install() {
cat <<EOF
==> For Krisp noise suppression support consider installing the necessary optional
dependencies and setting 'PATCH_KRISP=true' in '~/.config/discord.conf'.
Restart your Discord client afterwards to apply the patch.
==> In case of performance problems consider setting additional flags
in '~/.config/discord-flags.conf'.
EOF
}

83
krisp-patcher.py Normal file
View file

@ -0,0 +1,83 @@
import sys
import shutil
from elftools.elf.elffile import ELFFile
from capstone import *
from capstone.x86 import *
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} [path to discord_krisp.node]")
# "Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors."
sys.exit(2)
executable = sys.argv[1]
elf = ELFFile(open(executable, "rb"))
symtab = elf.get_section_by_name('.symtab')
krisp_initialize_address = symtab.get_symbol_by_name("_ZN7discord15KrispInitializeEv")[0].entry.st_value
isSignedByDiscord_address = symtab.get_symbol_by_name("_ZN7discord4util17IsSignedByDiscordERKNSt4__Cr12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE")[0].entry.st_value
text = elf.get_section_by_name('.text')
text_start = text['sh_addr']
text_start_file = text['sh_offset']
# This seems to always be zero (.text starts at the right offset in the file). Do it just in case?
address_to_file = text_start_file - text_start
# Done with the ELF now.
# elf.close()
krisp_initialize_offset = krisp_initialize_address - address_to_file
isSignedByDiscord_offset = krisp_initialize_address - address_to_file
f = open(executable, "rb")
f.seek(krisp_initialize_offset)
krisp_initialize = f.read(64)
f.close()
# States
found_issigned_by_discord_call = False
found_issigned_by_discord_test = False
found_issigned_by_discord_je = False
found_already_patched = False
je_location = None
# We are looking for a call to IsSignedByDiscord, followed by a test, followed by a je.
# Then we patch the je into a two byte nop.
md = Cs(CS_ARCH_X86, CS_MODE_64)
md.detail = True
for i in md.disasm(krisp_initialize, krisp_initialize_address):
if i.id == X86_INS_CALL:
if i.operands[0].type == X86_OP_IMM:
if i.operands[0].imm == isSignedByDiscord_address:
found_issigned_by_discord_call = True
if i.id == X86_INS_TEST:
if found_issigned_by_discord_call:
found_issigned_by_discord_test = True
if i.id == X86_INS_JE:
if found_issigned_by_discord_test:
found_issigned_by_discord_je = True
je_location = i.address
break
if i.id == X86_INS_NOP:
if found_issigned_by_discord_test:
found_already_patched = True
break
if je_location:
print(f"Found patch location: 0x{je_location:x}")
shutil.copyfile(executable, executable + ".orig")
f = open(executable, 'rb+')
f.seek(je_location - address_to_file)
f.write(b'\x66\x90') # Two byte NOP
f.close()
else:
if found_already_patched:
print("Couldn't find patch location - already patched.")
else:
print("Couldn't find patch location - review manually. Sorry.")

57
update-package.sh Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -euo pipefail
readonly all_off="$(tput sgr0)"
readonly bold="${all_off}$(tput bold)"
readonly white="${bold}$(tput setaf 7)"
readonly blue="${bold}$(tput setaf 4)"
readonly red="${bold}$(tput setaf 1)"
msg() {
printf "${blue}::${white} $1${all_off}\n"
}
error() {
printf "${red}::${white} $1${all_off}\n"
}
msgbegin() {
printf "${blue}::${white} $1"
}
msgend() {
printf "$1${all_off}\n"
}
readonly krisp_zip='discord_krisp-1.zip'
readonly krisp_bin='discord_krisp.node'
# head to directory of this script
cd $(dirname "$0")
# update package to version used in PKGBUILD
source PKGBUILD
msg "Running updpkgsums (Updating checksums)"
updpkgsums
msg "Running mksrcinfo (Updating SRCINFO file)"
makepkg --printsrcinfo > .SRCINFO
msg "Getting Krisp module"
curl -O "https://dl.discordapp.net/apps/linux/${_pkgver:-${pkgver}}/modules/${krisp_zip}"
unzip "${krisp_zip}" "${krisp_bin}"
msg "Checking if Krisp module is patchable (watch output)"
python krisp-patcher.py "${krisp_bin}"
#msg "Updating Krisp module checksum"
#readonly chcksm=$(b2sum "${krisp_bin}.orig" | head -c 128)
#sed -i "s/^_krisp_b2sum='.*'$/_krisp_b2sum='${chcksm}'/" PKGBUILD
msgbegin "Cleaning up... "
rm -f "${krisp_zip}" "${krisp_bin}" "${krisp_bin}.orig"
msgend "Done"