#!/bin/bash
#
# Simple script to remove libvpb files from the standard system locations.
# Mostly useful for people transitioning from pre-FHS versions (prior to 4.1)
# who might otherwise end up with files in both /usr and /usr/local

set -e

HEADERS="vpbapi.h vtcore_ioctl.h vt_deprecated.h vt/tonegen.h"
LIBS="libvpb.* libtoneg.*"

DIRS="/usr /usr/local"

for d in $DIRS; do
    for h in $HEADERS; do
        FILES="$(echo $FILES $(ls $d/include/$h 2> /dev/null))"
    done
    for l in $LIBS; do
        FILES="$(echo $FILES $(ls $d/lib/$l 2> /dev/null))"
    done
done

if test -z "$FILES"; then
    echo "Nothing to be removed."
    exit 0
fi

echo "The following files will be removed:"
for f in $FILES; do echo $f; done

echo
read -p "Proceed (y/N)? " -n 1
echo

case "$REPLY" in
    y|Y)
        for f in $FILES; do rm -f $f; done
        echo "Files removed."
        ;;
    *)
        echo "Aborted."
        ;;
esac

