Mentions légales du service

Skip to content
Snippets Groups Projects
Commit e489ae2b authored by hhakim's avatar hhakim
Browse files

Update post-install scripts (win, macos, linux) to add faust data dir in...

Update post-install scripts (win, macos, linux) to add faust data dir in matlab path and to secure further the update of th e path for matlab.

Each existing startup user's script are updated with addpath.
addpath is only executed if matfaust.version is not found in matlab path.
matlabrc calls startup to be sure (in case of not updated matlab path cache).
https://fr.mathworks.com/help/matlab/matlab_env/toolbox-path-caching-in-the-matlab-program.html
https://fr.mathworks.com/help/matlab/ref/rehash.html
https://fr.mathworks.com/help/matlab/ref/matlabrc.html
https://fr.mathworks.com/help/matlab/ref/startup.html
parent f7fd5c9c
Branches
Tags 2.5.62rc15
No related merge requests found
Pipeline #833951 skipped
#!/bin/bash
function dirname_noerr {
function dirname_noerr
{
[[ ! "$1" = /* ]] && return
dirname "$1" 2>/dev/null
}
function inject_matlab_code_to_update_path
{
FILE=$1
echo "matfaust_path = which('matfaust.version')" >> "$FILE"
echo "if(isempty(matfaust_path))" >> "$FILE"
echo "addpath('"$FAUST_MATLAB_WRAPPER_PATH"')" >> "$FILE"
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/mex'])" >> "$FILE"
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/tools'])" >> "$FILE"
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/data'])" >> "$FILE"
echo "matfaust.enable_gpu_mod('silent', true)" >> "$FILE"
echo end >> "$FILE"
}
MATLAB_ROOT=$(dirname_noerr $(dirname_noerr $(which matlab 2>/dev/null)))
[[ ! -d "${MATLAB_ROOT}" ]] && MATLAB_ROOT=$(dirname_noerr $(dirname_noerr $(find /usr/local -maxdepth 10 -type f -name "matlab" | tail -n 1)))
# find is sorted by default (contrary to macOS that needs find -s predicate)
[[ ! -d "${MATLAB_ROOT}" ]] && MATLAB_ROOT=$(dirname_noerr $(dirname_noerr $(find /opt/ -maxdepth 10 -type f -name "matlab" | tail -n 1)))
if [[ ! -d "${MATLAB_ROOT}" || ! -x "${MATLAB_ROOT}/bin/matlab" ]]
then
......@@ -14,22 +29,23 @@ then
else
MATLAB_BIN="${MATLAB_ROOT}/bin/matlab"
STARTUP_DIR="${MATLAB_ROOT}/toolbox/local/"
STARTUP_FILE=${STARTUP_DIR}/startup.m
MATLABRC="${STARTUP_DIR}/matlabrc.m"
STARTUP_FILE="${STARTUP_DIR}/startup.m"
[[ -r "$STARTUP_FILE" ]] && grep -i -v faust "$STARTUP_FILE" > "${STARTUP_FILE}.tmp" 2>/dev/null && mv "${STARTUP_FILE}.tmp" "$STARTUP_FILE"
FAUST_MATLAB_WRAPPER_PATH="@CMAKE_INSTALL_MATLAB_PREFIX@"
#USR_STARTUP_FILE=$($MATLAB_BIN -nojvm -nodisplay -r "which startup;exit" | tail -n 2 | head -n 1) # useless in root
if [[ -d "${FAUST_MATLAB_WRAPPER_PATH}" ]]
then
#echo "addpath(genpath('"$FAUST_MATLAB_WRAPPER_PATH"'))" >> "$STARTUP_FILE"
echo "addpath('"$FAUST_MATLAB_WRAPPER_PATH"')" >> $STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/mex'])" >> $STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/tools'])" >> $STARTUP_FILE
echo "matfaust.enable_gpu_mod()" >> "$STARTUP_FILE"
inject_matlab_code_to_update_path "$STARTUP_FILE"
# add a line to force startup execution into matlabrc
echo "oldpwd = pwd; startup_path = fullfile(matlabroot, 'toolbox', 'local'); cd(startup_path); startup; cd(oldpwd)" >> $MATLABRC
RET1=$?
RET2=0
# try edit startup.m of all users (only when files exist)
for USER_DIR in /home/*
do
USER=${USER_DIR##*/}
for USR_STARTUP_FILE in $USER_DIR/Documents/MATLAB/startup.m $USER_DIR/matlab/startup.m
do
#if [[ ! "${USR_STARTUP_FILE}" = "${STARTUP_FILE}" ]]
......@@ -38,11 +54,8 @@ else
then
grep -i -v faust "$USR_STARTUP_FILE" > "${USR_STARTUP_FILE}.tmp" 2>/dev/null && mv "${USR_STARTUP_FILE}.tmp" "$USR_STARTUP_FILE"
#echo "addpath(genpath('"$FAUST_MATLAB_WRAPPER_PATH"'))" >> "$USR_STARTUP_FILE"
echo "addpath('"$FAUST_MATLAB_WRAPPER_PATH"')" >> $USR_STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/mex'])" >> $USR_STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/tools'])" >> $USR_STARTUP_FILE
echo "matfaust.enable_gpu_mod('silent', true)" >> "$USR_STARTUP_FILE"
chown $USER $USR_STARTUP_FILE
inject_matlab_code_to_update_path "$USR_STARTUP_FILE"
chown $USER "$USR_STARTUP_FILE"
RET2=$(($?+$RET2))
fi
#fi
......
#!/bin/bash
function inject_matlab_code_to_update_path
{
FILE=$1
echo "matfaust_path = which('matfaust.version')" >> "$FILE"
echo "if(isempty(matfaust_path))" >> "$FILE"
echo "addpath('"$FAUST_MATLAB_WRAPPER_PATH"')" >> "$FILE"
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/mex'])" >> "$FILE"
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/tools'])" >> "$FILE"
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/data'])" >> "$FILE"
echo "matfaust.enable_gpu_mod('silent', true)" >> "$FILE"
echo end >> "$FILE"
}
# find matlab root path from the accessible matlab in the PATH
MATLAB_BIN=$(which matlab)
# deduce MATLAB_ROOT
......@@ -9,7 +22,6 @@ then
# if which method failed try this
# find the more recent matlab version installed (sorted by year normally contained in folder name)
MATLAB_ROOT=$(LC_ALL=C find /Applications/ -iname "MATLAB*" -maxdepth 2 | sort | tail -n 1)
# find -s is available only on macOS, that's why sort is used
# LC_ALL is for avoiding different order depending on the user environment
fi
if [[ ! -d "${MATLAB_ROOT}" ]]
......@@ -20,29 +32,32 @@ else
# set path in system startup script
STARTUP_DIR="${MATLAB_ROOT}/toolbox/local/"
STARTUP_FILE=${STARTUP_DIR}/startup.m
MATLABRC="${STARTUP_DIR}/matlabrc.m"
[[ -r "$STARTUP_FILE" ]] && grep -i -v faust "$STARTUP_FILE" > "${STARTUP_FILE}.tmp" && mv "${STARTUP_FILE}.tmp" "$STARTUP_FILE"
FAUST_MATLAB_WRAPPER_PATH="@CMAKE_INSTALL_MATLAB_PREFIX@"
#echo "addpath(genpath('"$FAUST_MATLAB_WRAPPER_PATH"'))" >> "$STARTUP_FILE"
echo "addpath('"$FAUST_MATLAB_WRAPPER_PATH"')" >> $STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/mex'])" >> $STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/tools'])" >> $STARTUP_FILE
inject_matlab_code_to_update_path $STARTUP_FILE
# add a line to force startup execution into matlabrc
echo "oldpwd = pwd; startup_path = fullfile(matlabroot, 'toolbox', 'local'); cd(startup_path); startup; cd(oldpwd)" >> $MATLABRC
# set path in user startup script
#USR_STARTUP_FILE="$($MATLAB_BIN -nojvm -nodisplay -r "which startup;exit" | tail -n 2 | head -n 1)" # doesn't work into install script
# even if it works in a normal script #TODO: debug
# temporary solution (hard-coded paths)
for USR_STARTUP_FILE in /Users/$USER/Documents/MATLAB/startup.m /Users/$USER/matlab/startup.m
for USR_HOME in /Users/*
do
#if [[ ! "${USR_STARTUP_FILE}" = "${STARTUP_FILE}" ]]
#then
if [[ -r "$USR_STARTUP_FILE" ]]
then
grep -i -v faust "$USR_STARTUP_FILE" > "${USR_STARTUP_FILE}.tmp" && mv "${USR_STARTUP_FILE}.tmp" "$USR_STARTUP_FILE"
#echo "addpath(genpath('"$FAUST_MATLAB_WRAPPER_PATH"'))" >> "$USR_STARTUP_FILE"
echo "addpath('"$FAUST_MATLAB_WRAPPER_PATH"')" >> $USR_STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/mex'])" >> $USR_STARTUP_FILE
echo "addpath(['"$FAUST_MATLAB_WRAPPER_PATH"' '/tools'])" >> $USR_STARTUP_FILE
chown $USER "$USR_STARTUP_FILE"
fi
#fi
USER=${USR_HOME##*/}
for USR_STARTUP_FILE in "$USR_HOME"/Documents/MATLAB/startup.m "$USR_HOME"/matlab/startup.m
do
#if [[ ! "${USR_STARTUP_FILE}" = "${STARTUP_FILE}" ]]
#then
if [[ -r "$USR_STARTUP_FILE" ]]
then
grep -i -v faust "$USR_STARTUP_FILE" > "${USR_STARTUP_FILE}.tmp" && mv "${USR_STARTUP_FILE}.tmp" "$USR_STARTUP_FILE"
#echo "addpath(genpath('"$FAUST_MATLAB_WRAPPER_PATH"'))" >> "$USR_STARTUP_FILE"
inject_matlab_code_to_update_path "$USR_STARTUP_FILE"
chown $USER "$USR_STARTUP_FILE"
fi
#fi
done
done
fi
......@@ -244,14 +244,23 @@ Function matlabFoundCb
FileOpen $1 "$R4\toolbox\local\startup.m" a
FileSeek $1 0 END ; do not erase start of file (but risk to add Faust path multiple times)
;FileWrite $1 "$\r$\naddpath(genpath('$INSTDIR\matlab'));$\r$\nmatfaust.enable_gpu_mod('silent', true)"
FileWrite $1 "$\r$\naddpath('$INSTDIR\matlab');$\r$\naddpath('$INSTDIR\matlab\mex');$\r$\naddpath('$INSTDIR\matlab\tools');$\r$\nmatfaust.enable_gpu_mod('silent', true)"
FileWrite $1 "matfaust_path = which('matfaust.version');$\r$\nif(isempty(matfaust_path))"
FileWrite $1 "$\r$\naddpath('$INSTDIR\matlab');$\r$\naddpath('$INSTDIR\matlab\mex');$\r$\naddpath('$INSTDIR\matlab\tools');$\r$\naddpath('$INSTDIR\matlab\data')$\r$\nmatfaust.enable_gpu_mod('silent', true)"
FileWrite $1 "$\r$\nend"
FileClose $1
FileOpen $1 "$DOCUMENTS\MATLAB\startup.m" w
FileOpen $1 "$R4\toolbox\local\matlabrc.m" a
FileSeek $1 0 END ; do not erase start of file (but risk to add Faust path multiple times)
FileWrite $1 "oldpwd = pwd; startup_path = fullfile(matlabroot, 'toolbox', 'local'); cd(startup_path); startup; cd(oldpwd)"
FileClose $1
FileOpen $1 "$DOCUMENTS\MATLAB\startup.m" a
IfErrors done
FileSeek $1 0 END
;FileWrite $1 "$\r$\naddpath(genpath('$INSTDIR\matlab'));$\r$\nmatfaust.enable_gpu_mod('silent', true)"
FileWrite $1 "$\r$\naddpath('$INSTDIR\matlab');$\r$\naddpath('$INSTDIR\matlab\mex');$\r$\naddpath('$INSTDIR\matlab\tools');$\r$\nmatfaust.enable_gpu_mod('silent', true)"
FileWrite $1 "matfaust_path = which('matfaust.version');$\r$\nif(isempty(matfaust_path))"
FileWrite $1 "$\r$\naddpath('$INSTDIR\matlab');$\r$\naddpath('$INSTDIR\matlab\mex');$\r$\naddpath('$INSTDIR\matlab\tools');$\r$\naddpath('$INSTDIR\matlab\data')$\r$\nmatfaust.enable_gpu_mod('silent', true);"
FileWrite $1 "$\r$\nend"
FileClose $1
done:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment