#check required version of a lib in host graphic lib (ie i965) #return 1 if robomap3 version is not sufficient function check_required_lib_ver () { DRIVER_LIB=$1 PATTERN=$2 LIB=$3 #get the highest required version of $PATTERN VER_REQUIRED=$(objdump -T $DRIVER_LIB | grep $PATTERN | sed -e 's/.*'$PATTERN'_\(.*\) .*/\1/' | sort -uV | tail -1) #get currently used $LIB LIB_PROVIDED=$(ldd $EXEC | grep $LIB | sed -e 's/.*=> \(.*\) (.*/\1/') #get the highest version of $PATTERN supported by the $LIB VER_PROVIDED=$(objdump -T $LIB_PROVIDED | grep ".*"$PATTERN"_[0-9.]*$" | sed -e 's/.*'$PATTERN'_\(.*\)/\1/' | sort -V | tail -1) if [ $(echo -e "$VER_PROVIDED\n$VER_REQUIRED" | sort -V | tail -n1) != $VER_PROVIDED ]; then echo "We must use the local system $LIB" return 1 fi } if [ -f /etc/lsb-release ]; then . /etc/lsb-release fi if [ _$DISTRIB_ID = _Ubuntu ]; then #tested on Ubuntu 17.10 #we must run as root if [ $EUID -ne 0 ]; then exec sudo -E $0 $* fi #we must run in root cgroup to escape possible restrictions on scheduling if [ -d /sys/fs/cgroup/cpu ]; then echo $$ > /sys/fs/cgroup/cpu/tasks fi fi #special actions if we use 3D ldd $EXEC | grep "libGL.so" > /dev/null if [ $? -eq 0 ]; then #allow root access to the X server xhost si:localuser:root #Mesa DRI driver may need a lib more recent than robomap3's ldconfig -p | grep mesa > /dev/null if [ $? -eq 0 ]; then read DRI_CARD_MAJOR DRI_CARD_MINOR < <(stat -c '%t %T' /dev/dri/card0) DRIVER=$(cat /sys/dev/char/$((16#$DRI_CARD_MAJOR)):$((16#$DRI_CARD_MINOR))/device/uevent | grep DRIVER | cut -d= -f2) echo "Mesa DRI driver is $DRIVER" DRIVER_LIB=$(LIBGL_DEBUG=verbose glxinfo 2>&1 | grep OpenDriver | tail -n 1 | sed -e "s/.* \(.*\)/\1/") #todo: make a list, find a complete one! check_required_lib_ver $DRIVER_LIB GLIBC libm.so.6 if [ "$?" = "1" ]; then ADDED_LIBS=$(ldconfig -p | grep libm.so.6 | grep libc6,x86-64 | cut -d'>' -f2) fi check_required_lib_ver $DRIVER_LIB CXXABI libstdc++.so.6 if [ "$?" = "1" ]; then ADDED_LIBS="$ADDED_LIBS:$(ldconfig -p | grep libstdc++.so.6 | grep libc6,x86-64 | cut -d'>' -f2)" fi #remove whitespace #add libs to LD_PRELOAD if version robomap3 version is not sufficient export LD_PRELOAD="$(echo -e "${ADDED_LIBS}" | tr -d '[:space:]')" fi fi