-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymake.run
More file actions
executable file
·204 lines (181 loc) · 8.18 KB
/
polymake.run
File metadata and controls
executable file
·204 lines (181 loc) · 8.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
dirtmp=$(cd "$(dirname "$0")"; pwd)
dir=`echo $dirtmp | awk '{ print $1 }'`
ResourcesDir="${dir%MacOS}Resources"
BundleBase=${ResourcesDir%/polymake.app/Contents/Resources}
write_default_config=0
alias perl=/usr/bin/perl
perlversion=`/usr/bin/perl --version | grep -o "5[.][0-9]*[.][0-9]"`
debug=0
polymake_user_dir=".polymake-macbundle"
if [[ "$#" -gt "0" ]]; then
if [[ "$1" = "-d" ]]; then
shift;
polymake_user_dir=".polymake-macbundle-debug"
debug=1;
fi;
fi;
if [ "$perlversion" != "REPLACE_PERLVERSION" ]; then
echo "=========================================================================="
echo "your perl version ($perlversion) does not match the perl version this"
echo "app was built for (REPLACE_PERLVERSION)"
echo "please download and install the version of polymake that corresponds"
echo "to the version of your system perl"
echo "You can find the version number by executing"
echo "/usr/bin/perl --version"
echo "in a terminal."
echo "If there is no version of the polymake app matching your perl version"
echo "please contact us at http://forum.polymake.org"
echo "=========================================================================="
exit
fi;
if [[ -f $HOME/$polymake_user_dir/bundle.config ]]; then
. $HOME/$polymake_user_dir/bundle.config
if [[ "$POLYMAKE_BASE_DIR" != "$dir" ]]; then
echo "========================================================================="
echo "Your polymake customization files in"
echo
echo "${HOME}/$polymake_user_dir"
echo
echo "correspond to a different installation of polymake"
echo "(or you have moved your installation to a different location on your Mac)"
echo "if you continue then all files in this directory will be reset "
echo "to default values".
echo
echo "If you have imported extensions into polymake then you should call"
echo "make clean"
echo "in all extension base directories befor you continue "
echo "and reimport them into polymake afterwards."
echo
echo "If you have activated the jupyter version of polymake "
echo "you will have to redo your changes to the file"
echo "bundle.config and at least reactivate the jupyter version."
echo "The file will be rewritten with its default values "
echo "if you continue."
echo
echo "If you have a saved copy of bundle.config and want to put "
echo "this back to ~/$polymake_user_dir, then"
echo "make sure that POLYMAKE_JUPYTER_FORCE_REINSTALL is set to 1."
echo
echo "If you want to save some of your previous settings you should abort now"
echo "(see the README.pdf that came with the bundle if you need help)"
echo "otherwise you can continue"
read -p "[a]bort or [c]ontinue? "
[ "$REPLY" == "c" ] || exit
rm -rf "${HOME}/$polymake_user_dir"
write_default_config=1
fi
else
write_default_config=1
fi
if [[ $write_default_config == 1 ]]; then
mkdir -p $HOME/$polymake_user_dir
cat <<EOT >> $HOME/$polymake_user_dir/bundle.config
# The terminal app used to start polymake, either Terminal or iTerm
# POLYMAKE_TERM=Terminal
# This variable determines whether polymake should run in a terminal or start a jupyter notebook
# 0: start in a terminal
# 1: use jupyter
# Note that this still opens a terminal to start the notebook server
# and then switches to your default web browser to open a notebook.
# Choose "polymake" in the menu "new" on the top right corner to start polymake.
# You have to close the notebook server yourself in this terminal
# after you finished the polymake notebook by typing Ctrl^c twice.
POLYMAKE_START_IN_JUPYTER=0
# Set the initial directory for your jupyter notebooks
# the default value is your home directory
# it is recommended to change this to something else, otherwise this will clutter your home with
# notebook files for each run of polymake
# the path can either be absolute or relative to your home directory (e.g. "~/Documents")
# the directory must exist, it will not be created
# POLYMAKE_JUPYTER_NOTEBOOK_DIR=
# The ip the jupyter server connects to
# by default this is localhost
# you have to set this variable if you start polymake remotely and want to connect to it from another machine
# if you start polymake in a virtual machine and want to connect from the host, then 0.0.0.0 is a suitable choice
# POLYMAKE_JUPYTER_IP=
# Set the port for the jupyter server
# by default, this is 8888 if it is available, or the next available port above 8888 if this is taken
# note that jupyter will choose another port if the port you provide is already taken
# POLYMAKE_JUPYTER_PORT=8888
# Set this to 0 if only the server should be started
# but no notebook should be opened in a browser
# e.g. when you start this remotely or in a vm and
# want to access the jupyter server from another machine or the vm host
POLYMAKE_JUPYTER_START_BROWSER=1
# Should polymake ask whether you want to start a new jupyter server if it detects an already running one?
POLYMAKE_JUPYTER_ASK_IF_RUNNING_SERVER=1
# Set the browser jupyter uses to start the notebook
# To use e.g.Chrome you shoud set this to
# POLYMAKE_JUPYTER_BROWSER='/Applications/Vivaldi.app/Contents/MacOS/Vivaldi %s'
# POLYMAKE_JUPYTER_BROWSER=
# set this to 1 if you want to force a recompilation of the jupyter kernel
# the variable should be set to 1 if you have not yet started polymake in jupyter
# or have relocated the bundle to a different directory
POLYMAKE_JUPYTER_FORCE_REINSTALL=1
# additional path variables
# POLYMAKE_ADD_PATH=
# Please do not edit the following line
EOT
echo " POLYMAKE_BASE_DIR=$dir" >> $HOME/$polymake_user_dir/bundle.config
. $HOME/$polymake_user_dir/bundle.config
fi
if [[ -n $POLYMAKE_ADD_PATH ]]; then
export PATH=$PATH:$POLYMAKE_ADD_PATH
fi
root=`grep -m 1 "root=.*" $ResourcesDir/polymake/lib/polymake/config.ninja | sed -Ee "s|root=(.*)/polymake.app/Contents/Resources/polymake/share/polymake|\1|"`
if [[ -z "$root" ]]; then
echo "polymake build configure file is missing"
echo "This should not happen. Your bundle seems to be corrupt. Please reinstall."
exit
fi
if [[ ! $root =~ ${BundleBase} ]]; then
echo "========================================================================="
echo "The bundle is started for the first time or has been relocated. Updating the configuration file..."
tfile=$(mktemp /tmp/polybundle.XXXXXXXXX)
sed "s|$root|$BundleBase|g" $ResourcesDir/polymake/lib/polymake/config.ninja > $tfile && cp $tfile $ResourcesDir/polymake/lib/polymake/config.ninja && rm $tfile
echo "...done"
fi
if [[ $POLYMAKE_START_IN_JUPYTER == 0 || "$#" -gt "0" || $debug == 1 ]]; then
if [[ $debug == 1 ]]; then
$dir/polymake.debug $@
else
$dir/polymake.start $@
fi;
else
options=()
if [[ $POLYMAKE_JUPYTER_ASK_IF_RUNNING_SERVER == 1 && $POLYMAKE_JUPYTER_FORCE_REINSTALL == 0 ]]; then
if [[ `jupyter notebook list | grep http` ]]; then
echo "Running jupyter server on your machine detected."
read -p "Do you want to start a new one (y/n)?"
while [[ "$REPLY" != "y" && "$REPLY" != "n" ]]; do
read -p "Please type y or n"
done
if [[ "$REPLY" == n ]]; then
exit 0
fi
fi
fi
if [[ $POLYMAKE_JUPYTER_FORCE_REINSTALL == 1 ]]; then
options+=("--force")
tfile=$(mktemp /tmp/polybundle.XXXXXXXXX)
sed "s/POLYMAKE_JUPYTER_FORCE_REINSTALL=1/POLYMAKE_JUPYTER_FORCE_REINSTALL=0/" $HOME/$polymake_user_dir/bundle.config > $tfile && cp $tfile $HOME/$polymake_user_dir/bundle.config && rm $tfile
fi
if [[ -n $POLYMAKE_JUPYTER_NOTEBOOK_DIR ]]; then
options+=("--notebook-dir=$POLYMAKE_JUPYTER_NOTEBOOK_DIR")
fi
if [[ -n $POLYMAKE_JUPYTER_IP ]]; then
options+=("--ip=$POLYMAKE_JUPYTER_IP")
fi
if [[ -n $POLYMAKE_JUPYTER_PORT ]]; then
options+=("--port=$POLYMAKE_JUPYTER_PORT")
fi
if [[ $POLYMAKE_JUPYTER_START_BROWSER == 0 ]]; then
options+=("--no-browser")
fi
if [[ -n $POLYMAKE_JUPYTER_BROWSER ]]; then
options+=("--browser='$POLYMAKE_JUPYTER_BROWSER'")
fi
$dir/polymake.start --script jupyter "${options[@]}"
fi
exit 0