Foolproof way of extracting .pkg files
It's easy enough to create a shell script which checks for a few conditions and then takes the appropriate action.

I've put mine at http://dl.dropbox.com/u/18414/bin/unpkg.sh but will copy the initial version below:

#!/bin/zsh
#
#   Author:     Timothy J. Luoma
#   Email:      luomat at gmail dot com
#   Date:       2011-12-29
#
#   Purpose:    extract .pkg files, either xar archives or directory
#               
#   URL:       http://dl.dropbox.com/u/18414/bin/unpkg.sh
#   
#   See also:  http://apple.stackexchange.com/questions/34957/foolproof-way-of-extracting-pkg-files

NAME="$0:t"

    # Brief explanation of how program works
USAGE="$NAME is meant to extract package files. (Filenames must end in .pkg). Can handle both .pkg directories or xar archives.

Usage: $NAME /path/to/foo.pkg
"

    # in case of emergency, report error and exit
die ()
{
    echo "$NAME: $@"
    exit 1
}

    # if not given any input, explain how to use it
if [ "$#" = "0" ]
then
        die "$USAGE"    
fi

    # put whatever we get as an argument into a variable
INPUT="$@"

    # does the input actual refer to an existing file?
    # if not, exit
[[ -e "$INPUT" ]]       || die "$INPUT does not exist"

    # get the extension of the input. i.e. if we are
    # given "foo.pkg" this will just be "pkg"
EXT="$INPUT:e"

    # check to make sure that the extension is 'pkg'
    # because that's what we're looking for
[[ "$EXT" = "pkg" ]]    || die "$INPUT is not a pkg"

TYPE=`file -b "$INPUT"`

case "$TYPE" in 
    directory)
                gzcat "$INPUT/Contents/Archive.pax.gz" | pax -r

    ;;

    "xar archive - version 1")
                # Put whatever commands you want here
                :
    ;;


    *)
            die "$USAGE"    
    ;;

esac



exit 0
#EOF


zsh has been included in Mac OS X for several releases now. I prefer it over /bin/sh because… well, let's not get into a "my shell is better than your shell" war, because my shell would win :-) 

In any event, zsh makes things a little easier and a little nicer, and it's included, so there's no reason not to use it, IMO. Especially for a OS X-specific script like this.

This was tested on 10.7.