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 #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 libstdc++ 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/") #get the highest required version of CXXABI CXXABI_REQUIRED=$(objdump -T $DRIVER_LIB | grep CXXABI | sed -e 's/.*CXXABI_\(.*\) .*/\1/' | sort -uV | tail -1) #get currently used libstdc++ LIBSTDCXX_PROVIDED=$(ldd $EXEC | grep libstdc++ | sed -e 's/.*=> \(.*\) (.*/\1/') #get the highest version of CXXABI supported by the libstdc++ CXXABI_PROVIDED=$(objdump -T $LIBSTDCXX_PROVIDED | grep ".*CXXABI_[0-9.]*$" | sed -e 's/.*CXXABI_\(.*\)/\1/' | sort -V | tail -1) if [ $(echo -e "$CXXABI_PROVIDED\n$CXXABI_REQUIRED" | sort -V | tail -n1) != $CXXABI_PROVIDED ]; then echo "We must use the local system libstdc++" export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 fi fi fi fi