diff --git a/bin/run-script b/bin/run-script index da8fff2..0d667c4 100755 --- a/bin/run-script +++ b/bin/run-script @@ -18,20 +18,33 @@ fi function usage() { echo "Usage: - bin/run-script [SCRIPT...] [SCRIPT_ARGS..] + bin/run-script [-e 'VAR1=value VAR2=value'] [SCRIPT...] [SCRIPT_ARGS..] bin/run-script [OPTIONS] Options: help prints this help ls prints a list of all available scripts + -e space-separated list of environment variables (optional) Examples: bin/run-script scripts/create_project.js --user-id=649c3f45711ad101a13de737 + bin/run-script -e 'PROJECT_ID=5ac1011aa13de547c3fd' scripts/delete_dangling_file_refs.js bin/run-script ls" } function __main__() { + local env_vars='' + while getopts ":e:" opt + do + case $opt in + e ) env_vars="${OPTARG}" ;; + \?) usage && exit ;; + : ) usage && exit ;; + esac + done + shift $(( OPTIND -1 )) + if [[ "${1:-null}" == "null" ]] \ || [[ "${1:-null}" == "help" ]] \ || [[ "${1:-null}" == "--help" ]] ; then @@ -45,7 +58,8 @@ function __main__() { exit fi - local run_cmd="cd /overleaf/services/web; node $@" + local container_env="source /etc/overleaf/env.sh || source /etc/sharelatex/env.sh && source /etc/container_environment.sh" + local run_cmd="${container_env} && cd /overleaf/services/web && ${env_vars} node $@" exec "$TOOLKIT_ROOT/bin/docker-compose" exec sharelatex bash -c "$run_cmd" }