All checks were successful
Zapret source guards / validate (push) Successful in 9s
The 297 program and nfqws2 need GLIBC_2.38. Debian 12 accepted the .deb and the AppImage installed its system part, and only then did the program die with GLIBC_2.38 not found. Now apt refuses the .deb with a clear dependency message and AppRun stops before installing anything. Ubuntu 24.04 (glibc 2.39) is not affected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
157 lines
7.6 KiB
Shell
Executable file
157 lines
7.6 KiB
Shell
Executable file
#!/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.
|
|
PREFIX="${ZAPRETGUI_PREFIX:-/opt/zapretgui}" # a test points it at a scratch folder
|
|
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 "$PREFIX/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 && return 0
|
|
# a desktop without any of the above (a bare window manager) still has xmessage or a terminal: a double-clicked
|
|
# AppImage must never fail silently
|
|
command -v xmessage >/dev/null && xmessage -center "$*" 2>/dev/null && return 0
|
|
command -v x-terminal-emulator >/dev/null && x-terminal-emulator -e sh -c 'echo "$1"; echo; printf "Enter to close: "; read answer' sh "$*" 2>/dev/null
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# The program is built on Debian 13 and needs its C library. On an older system (Debian 12 has 2.36) the first start would
|
|
# install the system part and only then fail with "GLIBC_2.38 not found": say it at once instead. The number is the libc6
|
|
# line of deb/control.in (a test keeps them equal).
|
|
MIN_GLIBC=2.38
|
|
have_glibc="$(getconf GNU_LIBC_VERSION 2>/dev/null | cut -d' ' -f2)"
|
|
if [ -n "$have_glibc" ] && [ "$(printf '%s\n%s\n' "$MIN_GLIBC" "$have_glibc" | sort -V | head -n 1)" != "$MIN_GLIBC" ]; then
|
|
say "This Zapret build needs a newer system: the C library (glibc) here is $have_glibc, the program needs $MIN_GLIBC or newer (Debian 13, Ubuntu 24.04 or newer). Nothing was installed."
|
|
exit 1
|
|
fi
|
|
|
|
system_part_ready() {
|
|
[ "$bundled" = "$installed" ] && [ -x "$PREFIX/bin/zapretgui" ] && getent group zapretgui >/dev/null \
|
|
&& systemctl is-active --quiet zapretgui-helper.service 2>/dev/null
|
|
}
|
|
|
|
# Runs install.sh through sudo in a terminal window, for a desktop where the graphical password dialog (pkexec) is missing
|
|
# or has no agent: a double-clicked AppImage has no terminal, so sudo alone cannot ask for the password. The terminal
|
|
# programs differ in how they take a command and in whether they wait, so the result comes back through a marker file.
|
|
sudo_in_terminal() {
|
|
marker="$1/.install-status"
|
|
rm -f "$marker"
|
|
script='sudo "$1" --user "$2"; code=$?; echo "$code" > "$3"; echo
|
|
if [ "$code" = 0 ]; then echo "Zapret is installed. You can close this window."; else echo "The installation failed (see above)."; fi
|
|
printf "Enter to close: "; read answer'
|
|
for term in x-terminal-emulator gnome-terminal konsole xfce4-terminal mate-terminal lxterminal xterm; do
|
|
command -v "$term" >/dev/null 2>&1 || continue
|
|
case "$term" in
|
|
gnome-terminal) "$term" -- sh -c "$script" sh "$1/install.sh" "$(id -un)" "$marker" >/dev/null 2>&1 & ;;
|
|
xfce4-terminal|mate-terminal) "$term" -x sh -c "$script" sh "$1/install.sh" "$(id -un)" "$marker" >/dev/null 2>&1 & ;;
|
|
*) "$term" -e sh -c "$script" sh "$1/install.sh" "$(id -un)" "$marker" >/dev/null 2>&1 & ;;
|
|
esac
|
|
pid=$!
|
|
# a terminal that cannot start exits with an error at once: try the next one instead of waiting for the password
|
|
tries=0
|
|
while kill -0 "$pid" 2>/dev/null && [ "$tries" -lt 10 ]; do sleep 0.2; tries=$((tries + 1)); done
|
|
if ! kill -0 "$pid" 2>/dev/null && ! wait "$pid" 2>/dev/null; then
|
|
[ -s "$marker" ] || continue
|
|
fi
|
|
waited=0
|
|
while [ ! -s "$marker" ] && [ "$waited" -lt 900 ]; do sleep 1; waited=$((waited + 1)); done
|
|
[ -s "$marker" ] && return "$(cat "$marker")"
|
|
return 1
|
|
done
|
|
return 1
|
|
}
|
|
|
|
install_system_part() {
|
|
tmp="$(mktemp -d /var/tmp/zapretgui-install.XXXXXX)" || return 1
|
|
status=1
|
|
if cp -a "$ROOT"/. "$tmp"/; then
|
|
# a build made from a git export may have lost the executable bit (Dev 296 did: sudo said "command not found")
|
|
chmod 0755 "$tmp/install.sh" "$tmp/uninstall.sh" 2>/dev/null
|
|
gui=
|
|
[ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ] && gui=1
|
|
if [ "$(id -u)" = 0 ]; then
|
|
"$tmp/install.sh"
|
|
status=$?
|
|
else
|
|
status=127
|
|
if [ -n "$gui" ] && command -v pkexec >/dev/null; then
|
|
pkexec "$tmp/install.sh" --user "$(id -un)"
|
|
status=$?
|
|
fi
|
|
# pkexec missing (Debian 13 ships it as its own package) or without a password agent exits 127, a dismissed dialog
|
|
# 126 (the person said no: stop). With a terminal around, ask there through sudo; without a desktop sudo is plain.
|
|
if [ "$status" = 127 ]; then
|
|
if [ -t 0 ] && command -v sudo >/dev/null; then
|
|
sudo "$tmp/install.sh" --user "$(id -un)"
|
|
status=$?
|
|
elif [ -n "$gui" ] && command -v sudo >/dev/null; then
|
|
sudo_in_terminal "$tmp"
|
|
status=$?
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
rm -rf "$tmp" # not a trap: the script ends with exec, which would skip it
|
|
return $status
|
|
}
|
|
|
|
# Starts the window and, when it dies within a few seconds, says why: a double-clicked AppImage has no terminal, so a
|
|
# missing window-system library ("could not load the Qt platform plugin xcb") would otherwise be "nothing happens".
|
|
start_window() {
|
|
log="$(mktemp /var/tmp/zapretgui-start.XXXXXX)" || exec "$@"
|
|
"$@" 2>"$log" &
|
|
pid=$!
|
|
waited=0
|
|
while kill -0 "$pid" 2>/dev/null && [ "$waited" -lt 8 ]; do sleep 1; waited=$((waited + 1)); done
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
rm -f "$log" # still running: the program keeps writing into the removed file, nothing is lost that matters
|
|
exit 0
|
|
fi
|
|
wait "$pid"
|
|
code=$?
|
|
if [ "$code" != 0 ]; then
|
|
lacking="$(for f in "$PREFIX/_internal/zapretgui" $(find "$PREFIX/_internal" -name libqxcb.so 2>/dev/null); do ldd "$f" 2>/dev/null | grep 'not found'; done | sort -u | tr -s '\t ' ' ' | head -8)"
|
|
say "Zapret did not start (exit code $code).
|
|
$(tail -n 8 "$log" 2>/dev/null)${lacking:+
|
|
|
|
Libraries that are missing on this system:
|
|
$lacking}"
|
|
fi
|
|
rm -f "$log"
|
|
exit "$code"
|
|
}
|
|
|
|
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
|
|
reason="$(tail -n 8 /var/log/zapretgui-install.log 2>/dev/null)"
|
|
say "The system part was not installed.${reason:+
|
|
$reason
|
|
}
|
|
Run it in a terminal to see everything: 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
|
|
start_window sg zapretgui -c "exec $PREFIX/bin/zapretgui"
|
|
fi
|
|
say "You were added to the group zapretgui. Log out and in once, then start Zapret again."
|
|
fi
|
|
fi
|
|
|
|
start_window "$PREFIX/bin/zapretgui" "$@"
|