Files
UltraGrid/data/scripts/Linux-AppImage/scripts/preload.sh
Martin Pulec 8670a1d25f AppRun: set LD_LIBRARY_PATH at the end
set LD_LIBRARY_PATH just before uv (or other tool) is run

This minimizes interference when running the script.
2023-11-03 16:16:06 +01:00

32 lines
940 B
Bash

# shellcheck shell=sh
get_loader() {
loaders='/lib64/ld-linux-*so* /lib/ld-linux-*so* /lib*/ld-linux-*so*'
for n in $loaders; do
for m in $n; do
if [ -x "$m" ]; then
echo "$m"
return
fi
done
done
}
# @param $1 UG library name
# @param $2 system preloaded library pattern
#
set_ld_preload() {
ug_module_lib=$AI_LIB_PATH/ultragrid/$1
if [ ! -f "$ug_module_lib" ]; then
return
fi
loader=$(get_loader)
if [ ! -x "$loader" ]; then
return
fi
system_lib=$(LD_TRACE_LOADED_OBJECTS=1 $loader "$ug_module_lib" | grep "$2" | grep -v 'not found' | awk '{print $3}')
if [ -n "$system_lib" ]; then
export LD_PRELOAD="$system_lib"${LD_PRELOAD:+":$LD_PRELOAD"}
fi
}