#!/bin/sh
#
# Bundle up a directory containing a main python script and some
# modules into a zip file with a unix python exec header. The main
# must be named __main__.py (or use symlinks). Method described here:
# http://blog.ablepear.com/2012/10/bundling-python-files-into-stand-alone.html
#
# This does not work under windows, but the comments in the link above
# have suggestions for windows: use a specific extension and association.
fatal()
{
echo $* 1>&2 ; exit 1
}
Usage()
{
fatal 'Usage: bundle.sh dir output'
}
test $# -eq 2 || Usage
dir=$1
output=$2
test -d "$dir" || fatal "cant access $dir"
(cd "$dir"; zip ../"$dir".zip *.py; cd ..)
echo '#!/usr/bin/env python' | cat - "$dir".zip > "$output"
rm -f "$dir".zip
chmod a+x "$output"