#!/usr/bin/sh
pruneMarker="--prunepaths="
isPrunepathsFound="false"
isInPrunePaths="false"
prunePathsArguments=""
remainingArguments=""
for argValue in $*
do
    if [[ $isInPrunePaths == "false" ]] ;
    then
        if [[ $isPrunepathsFound == "false" ]] && [[ $argValue == "$pruneMarker"* ]] ;
        then
            prunePathsArguments=`echo "$argValue" | sed 's,--prunepaths=,,'`
            isPrunepathsFound="true"
	    isInPrunePaths="true"
        else
            remainingArguments="$remainingArguments $argValue"
        fi
    else
        if [[ $argValue == "-"* ]] ;
        then
            isInPrunePaths="false"
            remainingArguments="$remainingArguments $argValue"
        else
            prunePathsArguments="$prunePathsArguments $argValue"
	fi
    fi
done
if [[ $prunePathsArguments == "" ]] ;
then
    exec env LIBPATH=/opt/mlocate/lib:$LIBPATH LD_LIBRARY_PATH=/opt/mlocate/lib:$LD_LIBRARY_PATH /opt/mlocate/bin/updatedb $remainingArguments
else
    exec env LIBPATH=/opt/mlocate/lib:$LIBPATH LD_LIBRARY_PATH=/opt/mlocate/lib:$LD_LIBRARY_PATH /opt/mlocate/bin/updatedb $remainingArguments --prunepaths "$prunePathsArguments"
fi

