All checks were successful
Zapret source guards / validate (push) Successful in 9s
Tested on the real KDE desktop (real FUSE mount, no APPIMAGE_EXTRACT_AND_RUN): the first start installs the system part, and the person is added to the group zapretgui, but their session does not have it until the next login, so the window started and then refused to start the engine. With no arguments AppRun now starts the window through `sg zapretgui`; with a file argument it keeps the old "log out and in" note. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
66 lines
2.9 KiB
Shell
66 lines
2.9 KiB
Shell
#!/bin/sh
|
|
# Start of the AppImage. The window needs the system part (the root helper, the service that owns the firewall table,
|
|
# the group) of the SAME version. The helper reads the program files from /opt/zapretgui, and root cannot read an
|
|
# AppImage's own mount (it belongs to the user), so on first start (or after an update) the files are copied to a
|
|
# temporary folder and install.sh puts them into /opt/zapretgui. After that the installed program runs, like the .deb.
|
|
HERE="$(dirname "$(readlink -f "$0")")"
|
|
ROOT="$HERE/zapretgui-root"
|
|
export PYTHONUTF8=1
|
|
# The compiled program ignores PYTHONUTF8; its file-name and text encoding follow the C library's character type.
|
|
export LC_CTYPE=C.UTF-8
|
|
|
|
bundled="$(cat "$ROOT/VERSION" 2>/dev/null)"
|
|
installed="$(cat /opt/zapretgui/VERSION 2>/dev/null)"
|
|
|
|
say() {
|
|
echo "zapretgui: $*" >&2
|
|
if [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then
|
|
command -v zenity >/dev/null && zenity --info --no-wrap --title=Zapret --text="$*" 2>/dev/null && return 0
|
|
command -v kdialog >/dev/null && kdialog --msgbox "$*" 2>/dev/null && return 0
|
|
command -v notify-send >/dev/null && notify-send Zapret "$*" 2>/dev/null
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
system_part_ready() {
|
|
[ "$bundled" = "$installed" ] && [ -x /opt/zapretgui/bin/zapretgui ] && getent group zapretgui >/dev/null \
|
|
&& systemctl is-active --quiet zapretgui-helper.service 2>/dev/null
|
|
}
|
|
|
|
install_system_part() {
|
|
tmp="$(mktemp -d /var/tmp/zapretgui-install.XXXXXX)" || return 1
|
|
status=1
|
|
if cp -a "$ROOT"/. "$tmp"/; then
|
|
if [ "$(id -u)" = 0 ]; then
|
|
"$tmp/install.sh"
|
|
elif [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ] && command -v pkexec >/dev/null; then
|
|
pkexec "$tmp/install.sh" --user "$(id -un)"
|
|
elif command -v sudo >/dev/null; then
|
|
sudo "$tmp/install.sh" --user "$(id -un)"
|
|
else
|
|
false
|
|
fi
|
|
status=$?
|
|
fi
|
|
rm -rf "$tmp" # not a trap: the script ends with exec, which would skip it
|
|
return $status
|
|
}
|
|
|
|
if [ "$1" = "--install-system-part" ] || ! system_part_ready; then
|
|
say "First start: Zapret installs its system part (a small root service and the firewall table). It asks for your password once."
|
|
if ! install_system_part; then
|
|
say "The system part was not installed. Run: sudo $(readlink -f "$0") --install-system-part"
|
|
exit 1
|
|
fi
|
|
[ "$1" = "--install-system-part" ] && exit 0
|
|
# The person was just added to the group zapretgui, but this session does not have it until the next login. Without
|
|
# arguments the window can start at once inside the new group (sg); the helper only talks to members of the group.
|
|
if ! id -nG | tr ' ' '\n' | grep -qx zapretgui && getent group zapretgui | grep -qw "$(id -un)"; then
|
|
if [ "$#" -eq 0 ] && command -v sg >/dev/null; then
|
|
exec sg zapretgui -c "exec /opt/zapretgui/bin/zapretgui"
|
|
fi
|
|
say "You were added to the group zapretgui. Log out and in once, then start Zapret again."
|
|
fi
|
|
fi
|
|
|
|
exec /opt/zapretgui/bin/zapretgui "$@"
|