Files
startup_scripts/pshell2
Alexandre Gobbo 2427bc4b39 Added pshell2
2025-12-12 14:53:21 +01:00

134 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
#Check if running as e-account
for i in "$@"
do
case $i in
-ea|-ea=*)
export ea="${i#*=}"
export pars=""
if [[ $BEAMLINE != "" ]] ; then
export epars="-data /${FACILITY}/${BEAMLINE}/data/p${ea:1}/raw"
fi
echo "Running as e-account"
#Replace ea into eax
for j in "$@"
do
case $j in
-ea|-ea=*)
pars+='-eax '
;;
*) # unknown option
pars+=$j
pars+=' '
;;
esac
done
if [[ $ea == "-ea" ]] ; then
export cmd='read -p "Enter E-Account: " ea ; echo Authenticating user ${ea}...; su ${ea} -c'
else
export cmd='echo Authenticating user ${ea}...; su ${ea} -c'
fi
if [ -z "$DESKTOP_SESSION" ]
then
#echo "SSH session"
cookie=$(xauth list $DISPLAY)
export cmd="${cmd} 'xauth add $cookie; ${BASH_SOURCE} ${pars} ${epars}; sleep 2'"
else
#echo "Desktop session"
export cmd="${cmd} '${BASH_SOURCE} ${pars} ${epars}; sleep 2'"
fi
#echo $cmd
xterm -T "Run PShell as E-Account" -fa monaco -fs 14 -bg black -fg green -geometry 80x15+400+100 -e "${cmd}"
exit
;;
esac
done
#Parse JVM arguments, Pshell version and JEP option
export PSHELL_VER_DEFAULT=v2
export PSHELL_VER=${PSHELL_VER_DEFAULT}
export JAVA_VER=/opt/gfa/java/jdk-24.0.1
export MAIN_CLASS=ch.psi.pshell.App
export JVM_EARGS="--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens java.desktop/sun.swing=ALL-UNNAMED --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --enable-native-access=ALL-UNNAMED"
export JVM_ARGS=
export UCP=
export COMMAND=
PASS=()
while (($#)); do
case $1 in
-jvmarg=*) JVM_ARGS="${1#*=}" ;;
-ucp=*) UCP="${1#*=}" ;;
-version=*) PSHELL_VER="${1#*=}" ;;
-test) PSHELL_VER="testing" ;;
-last) PSHELL_VER="latest" ;;
-javaver=*) JAVA_VER="${1#*=}" ;;
-command=*) COMMAND="${1#*=}" ;;
*) PASS+=("$1") ;;
esac
shift
done
# Show them like before, in one line:
#printf 'Remaining args:'
#for arg in "${PASS[@]}"; do
# printf ' "%s"' "$arg"
#done
#echo
# Restore positional parameters cleanly
set -- "${PASS[@]}"
if [[ $PSHELL_VER != $PSHELL_VER_DEFAULT ]] ; then
echo "Using PShell version:" ${PSHELL_VER}
fi
if [[ $@ == **-py** ]] ; then
#Using JEP
#First clean path and vars
unset PYTHONPATH
CLEAN_PATH=""
for p in $(echo $PATH | sed 's/:/ /g') ; do
if [[ $p =~ ^.*/opt/gfa/python.*$ ]] ; then
echo 'Remove from path' $p
else
if [ "$CLEAN_PATH" == "" ] ; then
CLEAN_PATH=$p
else
CLEAN_PATH=$CLEAN_PATH:$p
fi
fi
done
echo "Setting Python 3.8 for JEP"
#Python 3.8
export PYTHONHOME=/opt/gfa/python-3.8/latest
export JEP_JAR=${PYTHONHOME}/lib/python3.8/site-packages/jep/jep-3.9.1.jar
export LD_LIBRARY_PATH=${PYTHONHOME}/lib/python3.8/site-packages/jep
export LD_PRELOAD=${PYTHONHOME}/lib/libpython3.8.so
else
#Standard startup with -jar
if [[ $UCP == "" ]] ; then
${JAVA_VER}/bin/java ${JVM_EARGS} ${JVM_ARGS} -jar /opt/gfa/pshell/${PSHELL_VER} ${COMMAND} "$@"
exit
fi
fi
if [[ $UCP != "" ]] ; then
UCP=${UCP}:
fi
export PATH=${PYTHONHOME}/bin:$CLEAN_PATH
${JAVA_VER}/bin/java ${JVM_EARGS} ${JVM_ARGS} -cp ${UCP}/opt/gfa/pshell/${PSHELL_VER}:${JEP_JAR} ${MAIN_CLASS} ${COMMAND} "$@"