#!/bin/sh -e

# Make a link to the newest install of wxMac/wxPython
rm -f /usr/local/lib/wxPython-unicode
ln -s wxPython-unicode-2.8.9.2 /usr/local/lib/wxPython-unicode
 
# find a Python 2.6 binary
for dir in /usr/bin            /usr/local/bin            /Library/Frameworks/Python.framework/Versions/2.6/bin            /System/Library/Frameworks/Python.framework/Versions/2.6/bin; do 
    if [ -e $dir/python2.6 ]; then
	PYTHON=$dir/python2.6
	break
    fi
done

if [ -z $PYTHON ]; then
    echo ERROR: Unable to find a Python 2.6 binary
    exit 1
fi

# Byte-compile the .py files to .pyc and .pyo
$PYTHON    -m compileall $2/usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.6/site-packages/wx-2.8-mac-unicode
$PYTHON -O -m compileall $2/usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.6/site-packages/wx-2.8-mac-unicode

# and all of the wxPython package should be group writable
chgrp -R admin $2/usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.6/site-packages/wx-2.8-mac-unicode
chmod -R g+w $2/usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.6/site-packages/wx-2.8-mac-unicode

# install a .pth file in any Python 2.6 installs we can find
for dir in /Library/Python/2.6/site-packages            /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages; do
    if [ -d $dir ]; then
        echo Writing wxredirect.pth in $dir
        DEST=`dirname /usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.6/site-packages`
        cat > $dir/wxredirect.pth <<pthEOF
import site; site.addsitedir('$DEST')
pthEOF
    fi
done

exit 0
