#!/bin/sh
# Rýchlik launcher: the only job is to find the application relative to itself, make sure the locale is UTF-8 and exec the real binary
# (exec: signals and the session manager talk to the application itself, there is no shell left in between).
self="$(readlink -f -- "$0")"
here="${self%/*}"
# Policy: keep a valid user locale; only when the effective character set is not UTF-8 fall back to the always-present C.UTF-8.
charmap=""
if command -v locale >/dev/null 2>&1; then
    charmap="$(locale charmap 2>/dev/null || true)"
else
    for v in "${LC_ALL:-}" "${LC_CTYPE:-}" "${LANG:-}"; do
        [ -n "$v" ] && { charmap="${v#*.}"; break; }
    done
fi
case "$(printf '%s' "$charmap" | tr 'a-z' 'A-Z')" in
    UTF-8|UTF8|UTF-8@*) ;;
    *) LC_ALL=C.UTF-8; export LC_ALL ;;
esac
# A Qt from another installation must never be picked up (the bundled plugins are found through bin/qt.conf).
unset QT_PLUGIN_PATH QT_QPA_PLATFORM_PLUGIN_PATH QML_IMPORT_PATH QML2_IMPORT_PATH
exec "$here/bin/rychlik" "$@"
