#!/bin/bash
# fixes absolute symbolic links

set -x

# correct absolute symlinks
pushd ${APPDIR}
function processlinks()
{
    while read SOURCE; do
        TARGET=$(ls -l "${SOURCE}" | sed -e "s,.*-> *,,")
        RELATIVEUP=$(dirname ${SOURCE} | sed -e 's,^./,,' -e 's,[^/]*,..,g')
        if  echo ${TARGET} | grep '^/' > /dev/null; then
            NEWTARGET=${RELATIVEUP}${TARGET}
            ln -sf ${NEWTARGET} ${SOURCE}
        fi
    done
}

find . -type l | processlinks
popd
