#!/bin/bash
#
# 'diffpack' works with the 'lspack' utility to show how the local
# filesystem contents differ from the specified VARIANT and TARGET
# Qualcomm CRM release combination.
#

usage ()
{
cat <<USAGE
    Usage: diffpack -t TARGET -v VARIANT

    Show differences between the current working directory and the
    contents of Qualcomm's CRM release packfiles.  Output is restricted
    to the current sub-tree.

    Required arguements:

          -t TARGET    chipset target (e.g. msm8660_surf, msm7630_fusion, ...)
          -v VARIANT   CRM variant (e.g. HY11, HY22, ...)

    Individual files are frequently included in multiple VARIANT and TARGET
    release combinations.  In order to present diff output in a meaningful
    way a unique VARIANT and TARGET release combination must be specified
    to restrict the comparison output results.

    Example:

        Display files in the current directory sub-tree which are included
        in the currently defined HY11, msm8660_surf pack file combination:

           $ diffpack -v HY11 -t msm8660

USAGE
}

while getopts ":t::v:" opt; do
    case ${opt} in
    t)
        target_restrict=${OPTARG}
        ;;
    v)
        variant_restrict=$(echo ${OPTARG} | tr '[a-z]' '[A-Z]')
        ;;
    *)
        usage
        exit 1
        ;;
    esac
done

if [ -z ${variant_restrict} ] || [ -z ${target_restrict} ]; then
    usage
    exit 1
fi

unit=$(pwd | sed 's!^.*vendor\/qcom\/!!')

# ignore UNIX/Windows path separator differences
diff -d -C 0 --label=packfiles --label=${unit}                     \
     <(lspack -1 -q -v ${variant_restrict} -t ${target_restrict} | \
                        sed 's!\\!\/!g' | sort)                    \
     <(find . -type d -name .git -prune -o -type f -print |        \
                        sed 's!^.\/!!g' | sort)

