#!/bin/bash
# /usr/bin/arx-messenger — launcher installed by the .deb.
#
# The bundle lives in /opt/arx-messenger because it is a Flutter bundle, not a
# collection of FHS-placed files: `arx_pro` resolves `data/` relative to its own
# directory and `lib/` through an $ORIGIN/lib rpath (linux/CMakeLists.txt), so
# the tree has to stay intact and has to be entered before exec.
#
# The preflight still runs even though apt has resolved every Depends: it also
# reports the OPTIONAL half — ffmpeg, parecord, a running sound server, a
# notification daemon and a LOCKED keyring — none of which apt can guarantee
# (Recommends can be declined, and a keyring cannot be unlocked by a package).
# A hard blocker here means someone removed a dependency by hand; that is worth
# a readable message rather than an ld.so backtrace.
#
# /opt/arx is substituted by scripts/build_linux_deb.sh: the dev-flavor
# package installs under its own prefix so it cannot replace a production
# install (AM-1503).
set -u

APP_DIR=/opt/arx

if [ "${ARX_SKIP_PREFLIGHT:-0}" != "1" ] && [ -x "${APP_DIR}/preflight.sh" ]; then
  "${APP_DIR}/preflight.sh" "${APP_DIR}/arx_pro" || exit 1
fi

cd "${APP_DIR}" || exit 1
exec ./arx_pro "$@"
