#!/bin/bash

# load vscode-profile script
if test -e /etc/rstudio/vscode-profile
then
   . /etc/rstudio/vscode-profile
fi

# session arguments
# escape backslashes in arguments to pass safely to bash below
VSCODE_ARGS="${@//\\/\\\\}"

# install extension
if [ ! -z "$RS_VSCODE_EXT_VERSION" ]
then
   if [ -f /usr/lib/rstudio-server/extras/scripts/install-vs-code-ext.sh ]
   then
      /usr/lib/rstudio-server/extras/scripts/install-vs-code-ext.sh -l -v "$RS_VSCODE_EXT_VERSION"
   else
     echo "Skipping VS Code extension update to $RS_VSCODE_EXT_VERSION because /usr/lib/rstudio-server/extras/scripts/install-vs-code-ext.sh was not found."
   fi
fi

# run the session
/bin/bash --login $VSCODE_PROFILE_OPTIONS -c "$VSCODE_EXEC_COMMAND $VSCODE_ARGS"
exit $?
