#!/bin/bash

BIN=$PREFIX/bin

if [ $PRERELEASE == True ]
then

    rm -rf anaconda_navigator/app/Navigator.app

else
    POST_LINK=$BIN/.anaconda-navigator-post-link.sh
    PRE_UNLINK=$BIN/.anaconda-navigator-pre-unlink.sh

    # Create Mac app
    if [ `uname` == Darwin ]
    then
        mv anaconda_navigator/app/Navigator.app $PREFIX/navigatorapp
        find $PREFIX/navigatorapp -name '__init__.py' | xargs rm

        AE=$PREFIX/navigatorapp/Contents/MacOS/run.sh
        cat <<EOF >$AE
#!/bin/sh
source "$PREFIX"/bin/activate root
"$PREFIX"/bin/anaconda-navigator \$@
EOF
        chmod +x $AE

        cp $RECIPE_DIR/osx-post.sh $POST_LINK
        cp $RECIPE_DIR/osx-pre.sh $PRE_UNLINK
        chmod +x $POST_LINK $PRE_UNLINK
    fi


    # Add desktop file for Linux
    if [ `uname` == Linux ]
    then
        rm -rf anaconda_navigator/app/Navigator.app

        AE=$PREFIX/navigator.desktop
        cat <<EOF >$AE
[Desktop Entry]
Name=Anaconda Navigator
Comment=Frontend to the Anaconda Platform
Exec=/usr/bin/env PATH=$PREFIX/bin:$PATH $PREFIX/bin/anaconda-navigator
Terminal=false
Type=Application
Categories=Development
Icon=$SP_DIR/anaconda_navigator/images/anaconda-icon-1024x1024.png
EOF

        cp $RECIPE_DIR/linux-post.sh $POST_LINK
        cp $RECIPE_DIR/linux-pre.sh $PRE_UNLINK
        chmod +x $POST_LINK $PRE_UNLINK
    fi
fi

$PYTHON setup.py install --old-and-unmanageable
