#!/bin/sh

# check for reasonable symlinks
for file in $(find . -type l); do
    # detect symlinks that don't link to anything
    if ! realpath $file 1>/dev/null; then
        echo "symlink links to nothing: $file $(readlink $file)"
        exit 1
    fi
    # detect symlinks that link outside the pwd
    if [ -n "$(realpath $file | grep -v "^$(pwd)")" ]; then
        echo "symlink outside of pwd: $file $(readlink $file)"
        exit 1
    fi
done

# check for prebuilt binary files
list=$(find . -type f -executable -not -empty | perl -lne 'print if -B')
if [ -n "$list" ]; then
    echo "prebuilt binary files:"
    echo "$list"
    exit 1
fi
