This is cut and past from gaia-marionette.

But the idea is to get the path of the actual source instead of $0 which would be the invocation command....

See http://hustoknow.blogspot.ca/2011/01/what-bashsource-does.html

Since we require bash anyway