#! /bin/sh

set -e

# might be used by some AppRun scripts, e.g., craft runenv hook
# shellcheck disable=SC2034
this_dir=/opt/appimagelauncher.AppDir

# might be used by some other scripts, generally a good idea to set it
APPDIR="$this_dir"
export APPDIR

script_dir="$APPDIR/apprun-hooks"
if [ -d "$script_dir" ]; then
    for script in "$script_dir"/*; do
        # some plugins put non-script files in the directory        # we do our best to avoid running them by accident
        [ ! -f "$script" ] && continue

        # shellcheck disable=SC1090
        . "$script"
    done
fi

exec /opt/appimagelauncher.AppDir/usr/bin/AppImageLauncher "$@"
