#!/bin/bash12# start-sage.sh3# Fluidium4#5# Created by Ivan Andrus on 16/1/10.6# Copyright 2010 Ivan Andrus. All rights reserved.78# Ensure we have enough arguments9if [ $# -lt 2 ]; then10echo "usage: $0 SAGE_EXECUTABLE LOG"11exit 1;12fi1314# Ensure that we have the original sage and therefore the directory it's in should be SAGE_ROOT (right?)15SAGE_EXECUTABLE=`readlink -n "$1" 2> /dev/null` || \16SAGE_EXECUTABLE="$1"1718# Strip the last section off -- this should be SAGE_ROOT. We could19# just call `sage --root`, but I'm afraid this may not work (if there20# are spaces). But if sageBinary is not set, the "sage" gets passed21# in, and we have no choice, but to call `sage --root`, and it should22# work in that case (assuming of course that sage is in PATH)23if [ "x$SAGE_EXECUTABLE" = "xsage" ]; then24SAGE_ROOT=`sage --root`25else26SAGE_ROOT="${SAGE_EXECUTABLE%/*}/"27fi28SAGE_LOG="$2"2930# Work around spaces in the path (and perhaps cut down on location changes).31# We delete and recreate the symlink every time to ensure we are in the right place32rm -f /tmp/sage-mac-app33ln -s "$SAGE_ROOT" /tmp/sage-mac-app3435# Move to a fake SAGE_ROOT -- without spaces36cd /tmp/sage-mac-app || exit 13738# Set SAGE_ROOT and all the other environment variables by sourcing39# sage-env. In order to support older versions 4.x of Sage, we try both40# spkg/bin/sage-env and local/bin/sage-env.41echo Setting environment variables >> "$SAGE_LOG"42{ . spkg/bin/sage-env || . local/bin/sage-env; } >> "$SAGE_LOG" 2>> "$SAGE_LOG" || exit 143export SAGE_ROOT4445# Mac OS X app bundles are *intended* to be moved around, and/or given away46# So always run first the respective script handling this47# (This should also catch Intel vs. PPC or 32Bit vs. 64Bit conflicts - untested)48echo Checking install location >> "$SAGE_LOG"49./local/bin/sage-location >> "$SAGE_LOG" 2>> "$SAGE_LOG" || exit 15051echo Checking existence of notebook directory >> "$SAGE_LOG"52if [ -d $DOT_SAGE/sage_notebook.sagenb ]; then53echo Starting Notebook >> "$SAGE_LOG"54./sage --notebook >> "$SAGE_LOG" 2>> "$SAGE_LOG"55else56# if Terminal.app is not running before it is activated by57# osascript, then it inherits the environment from osascript.58# This includes SAGE_ENV_SOURCED which causes problems because59# PATH can get messed up and we'll end up calling the system60# python instead of the sage version. We unset it here so that61# sage-env will be sourced and PATH set up properly.62SAGE_ENV_SOURCED=63echo Starting Notebook in Terminal >> "$SAGE_LOG"64sage-native-execute osascript \65-e 'tell app "Terminal"' \66-e ' activate' \67-e " do script \"'$SAGE_ROOT'/sage --notebook\"" \68-e 'end'69fi70exit 0717273