shell library for Debian package releases
Some lints:


Uppercase names are by convention only for exported variables.
You can use getopt to parse parameters. This should make it easier to handle optional parameters, and also makes it easy to avoid positional parameters (which makes commands more self-documenting).
Use More Quotes™
I would guard against errors and accidents by using set -o errexit -o noclobber -o nounset -o pipefail at the top of the script.
returning anything other than an exit code is a problem. You function should instead output the value (and ensure other output goes to standard error). One issue is the semantics of conflating exit codes. The other is the lingering bug because exit codes wrap around after 255.
You can use mktemp --directory to create a temporary directory to store intermediate results. Even better would be to pass results in a pipeline to avoid any temporary files.