Skip to content

Commit 70cd501

Browse files
committed
Added MATLAB Engine installer script
1 parent 101faab commit 70cd501

File tree

1 file changed

+136
-2
lines changed

1 file changed

+136
-2
lines changed
Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,138 @@
11
#!/bin/bash
2-
export ROOTPATH="$(dirname "$(readlink -f "$0")")"
2+
export ROOTPATH="$(dirname "$(readlink -f "$0")")/.."
33

4-
# TODO
4+
OS=""
5+
PACKAGE_SYSTEM=""
6+
UNAME=`uname`
7+
DATE_STRING=`date +"%Y-%m-%d_%H%M%S"`
8+
LOG_FILE="$ROOTPATH/tools/MATLAB_Engine_install_log_$DATE_STRING.log"
9+
FILE_LOG_LEVEL=7
10+
CONSOLE_LOG_LEVEL=5
11+
MLC_PYTHON_DIR="$ROOTPATH/mlc_python"
12+
UNINSTALL=0
13+
INSTALLED=0
14+
PACKAGE_PATH=""
15+
MATLAB_DIR=""
16+
PYTHON_ENG_DIR="extern/engines/python"
17+
18+
19+
function usage() {
20+
log_message 5 "MLC Installer. Available options:"
21+
log_message 5 " -h: Show this help"
22+
log_message 5 " -d <dir>: Absolute path where MATLAB is installed in the system. Mandatory!"
23+
}
24+
25+
26+
# LOG LEVELS:
27+
# 0: EMERGENCY
28+
# 1: CRITICAL
29+
# 2: ERROR
30+
# 3: WARNING
31+
# 4: NOTICE
32+
# 5: INFO
33+
# 6: DEBUG
34+
# 7: TRACE
35+
function log_message() {
36+
LOG_LEVEL=$1
37+
LOG_MESSAGE=$2
38+
39+
if [ $LOG_LEVEL -le $FILE_LOG_LEVEL ]; then
40+
echo -e "$LOG_MESSAGE" >> $LOG_FILE
41+
fi
42+
43+
if [ $LOG_LEVEL -le $CONSOLE_LOG_LEVEL ]; then
44+
echo -e "$LOG_MESSAGE"
45+
fi
46+
}
47+
48+
49+
function parse_args() {
50+
log_message 7 "Checking command line arguments"
51+
# Needed to make getopts work
52+
local OPTIND opt
53+
OPTSPEC=":hup:d:"
54+
55+
while getopts $OPTSPEC opt; do
56+
case "${opt}" in
57+
h)
58+
usage
59+
exit 0
60+
;;
61+
d)
62+
if [ -z "$OPTARG" ]; then
63+
log_message 1 "option '-d' requires an argument"
64+
usage
65+
exit 1
66+
fi
67+
MATLAB_DIR=$OPTARG
68+
;;
69+
\?)
70+
log_message 1 "ERROR: Invalid option received"
71+
usage
72+
exit 1
73+
;;
74+
esac
75+
done
76+
77+
if [ $UNINSTALL -eq 1 ]; then
78+
return
79+
fi
80+
81+
if [ x"$MATLAB_DIR" = "x" ]; then
82+
log_message 1 "MATLAB dir must be supplied."
83+
usage
84+
exit 1
85+
fi
86+
}
87+
88+
89+
function check_run_as_root() {
90+
case `id` in
91+
uid=0*) ;;
92+
93+
*)
94+
log_message 1 "ERROR: Must be root to run script (use -h for help). Aborting installation"
95+
exit 1
96+
;;
97+
esac
98+
}
99+
100+
101+
function install_matlab_engine() {
102+
# Move to Python engine directory to install the Engine module. It doesn't work in another way
103+
cd "$MATLAB_DIR/$PYTHON_ENG_DIR"
104+
105+
#Remove the build directory if it exists
106+
rm -rf "$MATLAB_DIR/$PYTHON_ENG_DIR/build"
107+
$MLC_PYTHON_DIR/bin/mlc_python "$MATLAB_DIR/$PYTHON_ENG_DIR/setup.py" build > /dev/null 2>&1
108+
if [ $? -ne 0 ]; then
109+
log_message 1 "An error ocurred while building MATLAB Python Package. Aborting installation"
110+
exit 1
111+
fi
112+
113+
114+
$MLC_PYTHON_DIR/bin/mlc_python "$MATLAB_DIR/$PYTHON_ENG_DIR/setup.py" install > /dev/null 2>&1
115+
if [ $? -ne 0 ]; then
116+
log_message 1 "An error ocurred while installing MATLAB Python Package. Aborting installation"
117+
exit 1
118+
fi
119+
120+
log_message 5 "MATLAB Engine was succesfully installed"
121+
}
122+
123+
124+
function main() {
125+
log_message 4 "#################################"
126+
log_message 4 "# MATLAB Engine Installer #"
127+
log_message 4 "#################################"
128+
log_message 4 "Saving log to $LOG_FILE"
129+
130+
if [ $# -ne 1 -o "$1" != "-h" ]; then
131+
check_run_as_root
132+
fi
133+
parse_args $*
134+
install_matlab_engine
135+
}
136+
137+
138+
main $*

0 commit comments

Comments
 (0)