fix: postuninst & postinst script in Linux (#1295)

* refactor: Postinstall script in linux

* fix: add postuninst script in linux
This commit is contained in:
Moon 2025-10-20 07:29:35 +08:00 committed by GitHub
parent 877a84dc32
commit 236ad0ab43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 6 deletions

View File

@ -1,8 +1,10 @@
#!/bin/bash
if type update-alternatives 2>/dev/null >&1; then
set -e
if type update-alternatives >/dev/null 2>&1; then
# Remove previous link if it doesn't use update-alternatives
if [ -L '/usr/bin/mihomo-party' -a -e '/usr/bin/mihomo-party' -a "`readlink '/usr/bin/mihomo-party'`" != '/etc/alternatives/mihomo-party' ]; then
if [ -L '/usr/bin/mihomo-party' ] && [ -e '/usr/bin/mihomo-party' ] && [ "$(readlink '/usr/bin/mihomo-party')" != '/etc/alternatives/mihomo-party' ]; then
rm -f '/usr/bin/mihomo-party'
fi
update-alternatives --install '/usr/bin/mihomo-party' 'mihomo-party' '/opt/mihomo-party/mihomo-party' 100 || ln -sf '/opt/mihomo-party/mihomo-party' '/usr/bin/mihomo-party'
@ -10,10 +12,11 @@ else
ln -sf '/opt/mihomo-party/mihomo-party' '/usr/bin/mihomo-party'
fi
chmod 4755 '/opt/mihomo-party/chrome-sandbox' || true
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo-alpha
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo-smart
chmod 4755 '/opt/mihomo-party/chrome-sandbox' 2>/dev/null || true
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo 2>/dev/null || true
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo-alpha 2>/dev/null || true
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo-smart 2>/dev/null || true
if hash update-mime-database 2>/dev/null; then
update-mime-database /usr/share/mime || true

22
build/linux/postuninst Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash
case "$1" in
remove|purge|0)
if type update-alternatives >/dev/null 2>&1; then
update-alternatives --remove 'mihomo-party' '/opt/mihomo-party/mihomo-party' 2>/dev/null || true
fi
[ -L '/usr/bin/mihomo-party' ] && rm -f '/usr/bin/mihomo-party'
if hash update-mime-database 2>/dev/null; then
update-mime-database /usr/share/mime || true
fi
if hash update-desktop-database 2>/dev/null; then
update-desktop-database /usr/share/applications || true
fi
;;
*)
# others
;;
esac

View File

@ -68,7 +68,9 @@ linux:
artifactName: clash-party-linux-${version}-${arch}.${ext}
deb:
afterInstall: 'build/linux/postinst'
afterRemove: 'build/linux/postuninst'
rpm:
afterInstall: 'build/linux/postinst'
afterRemove: 'build/linux/postuninst'
npmRebuild: true
publish: []