Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/mac-app/start-sage.sh
8817 views
1
#!/bin/bash
2
3
# start-sage.sh
4
# Fluidium
5
#
6
# Created by Ivan Andrus on 16/1/10.
7
# Copyright 2010 Ivan Andrus. All rights reserved.
8
9
# Ensure we have enough arguments
10
if [ $# -lt 2 ]; then
11
echo "usage: $0 SAGE_EXECUTABLE LOG"
12
exit 1;
13
fi
14
15
# Ensure that we have the original sage and therefore the directory it's in should be SAGE_ROOT (right?)
16
SAGE_EXECUTABLE=`readlink -n "$1" 2> /dev/null` || \
17
SAGE_EXECUTABLE="$1"
18
19
# Strip the last section off -- this should be SAGE_ROOT. We could
20
# just call `sage --root`, but I'm afraid this may not work (if there
21
# are spaces). But if sageBinary is not set, the "sage" gets passed
22
# in, and we have no choice, but to call `sage --root`, and it should
23
# work in that case (assuming of course that sage is in PATH)
24
if [ "x$SAGE_EXECUTABLE" = "xsage" ]; then
25
SAGE_ROOT=`sage --root`
26
else
27
SAGE_ROOT="${SAGE_EXECUTABLE%/*}/"
28
fi
29
SAGE_LOG="$2"
30
31
# Work around spaces in the path (and perhaps cut down on location changes).
32
# We delete and recreate the symlink every time to ensure we are in the right place
33
rm -f /tmp/sage-mac-app
34
ln -s "$SAGE_ROOT" /tmp/sage-mac-app
35
36
# Move to a fake SAGE_ROOT -- without spaces
37
cd /tmp/sage-mac-app || exit 1
38
39
# Set SAGE_ROOT and all the other environment variables by sourcing
40
# sage-env. In order to support older versions 4.x of Sage, we try both
41
# spkg/bin/sage-env and local/bin/sage-env.
42
echo Setting environment variables >> "$SAGE_LOG"
43
{ . spkg/bin/sage-env || . local/bin/sage-env; } >> "$SAGE_LOG" 2>> "$SAGE_LOG" || exit 1
44
export SAGE_ROOT
45
46
# Mac OS X app bundles are *intended* to be moved around, and/or given away
47
# So always run first the respective script handling this
48
# (This should also catch Intel vs. PPC or 32Bit vs. 64Bit conflicts - untested)
49
echo Checking install location >> "$SAGE_LOG"
50
./local/bin/sage-location >> "$SAGE_LOG" 2>> "$SAGE_LOG" || exit 1
51
52
echo Checking existence of notebook directory >> "$SAGE_LOG"
53
if [ -d $DOT_SAGE/sage_notebook.sagenb ]; then
54
echo Starting Notebook >> "$SAGE_LOG"
55
./sage --notebook >> "$SAGE_LOG" 2>> "$SAGE_LOG"
56
else
57
# if Terminal.app is not running before it is activated by
58
# osascript, then it inherits the environment from osascript.
59
# This includes SAGE_ENV_SOURCED which causes problems because
60
# PATH can get messed up and we'll end up calling the system
61
# python instead of the sage version. We unset it here so that
62
# sage-env will be sourced and PATH set up properly.
63
SAGE_ENV_SOURCED=
64
echo Starting Notebook in Terminal >> "$SAGE_LOG"
65
sage-native-execute osascript \
66
-e 'tell app "Terminal"' \
67
-e ' activate' \
68
-e " do script \"'$SAGE_ROOT'/sage --notebook\"" \
69
-e 'end'
70
fi
71
exit 0
72
73