#!/bin/bash

lvers=`ldd /usr/lib/tbackup/bin/flowpause|gawk '{print substr($1,6)}'`

if [ "$lvers" = "" ]; then
 echo "Shared library error.  Either you have a very old system, you"
 echo "don\'t have the \"ldd\" program, or both."
 echo
 echo "This situation should be corrected if a good tbackup rescue disk"
 echo "is to be made.  See the CREATE file."
 exit 1
fi

echo "The makedisk script packs the latest shared library versions:"
ls /lib/lib[cm].$lvers.*

echo

auxnames=`cat auxlist |grep -v true`
auxnames="$auxnames /usr/lib/tbackup/bin/flowpause /bin/bash"
echo "Finding the shared library versions needed by tbackup and its"
echo "auxilliary programs..."

err=n
rm -f /tmp/findlibs.tmp
for i in $auxnames; do
 n=`type -path $i`
 if [ "$n" = "" ]; then
   echo "Error: auxilliary program $i not found."
   err=y
 else
   if [ "$1" = "-v" ]; then echo $n; ldd $n; fi
   ldd $n >>/tmp/findlibs.tmp
 fi
done

echo
echo "Libraries needed:"
sort </tmp/findlibs.tmp |uniq >/tmp/findlibs.tmp2
cat /tmp/findlibs.tmp2

grep -v "lib[cm]\.$lvers\b" /tmp/findlibs.tmp2 >/tmp/findlibs.tmp3

echo
if [ -s /tmp/findlibs.tmp3 ]; then

 echo "ERROR: older (?) shared library versions are needed by the programs on the"
 echo "tbackup rescue disk."
 echo "The extra libraries needed are:"
 cat /tmp/findlibs.tmp3
 echo 
 echo "This situation should be corrected if a good tbackup rescue disk"
 echo "is to be made.  See the CREATE file."
else

 echo "All OK, the programs on the tbackup rescue disk work with the"
 echo "Latest shared libraries."

fi

rm -f /tmp/findlibs.tmp*
