mirror of
https://github.com/overleaf/toolkit.git
synced 2025-04-19 07:18:06 +02:00
Added bin/run-script
Facilitates the process of running web scripts
This commit is contained in:
parent
87f0d3734a
commit
a2270df49c
2 changed files with 56 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 2024-07-30
|
||||
### Added
|
||||
- New `bin/run-script` command
|
||||
|
||||
## 2024-07-29
|
||||
### Fixed
|
||||
- Sandboxed Compiles is available for Server Pro only
|
||||
|
|
52
bin/run-script
Executable file
52
bin/run-script
Executable file
|
@ -0,0 +1,52 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
#### Detect Toolkit Project Root ####
|
||||
# if realpath is not available, create a semi-equivalent function
|
||||
command -v realpath >/dev/null 2>&1 || realpath() {
|
||||
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
||||
}
|
||||
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
|
||||
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
|
||||
TOOLKIT_ROOT="$(realpath "$SCRIPT_DIR/..")"
|
||||
if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
|
||||
echo "ERROR: could not find root of overleaf-toolkit project (inferred project root as '$TOOLKIT_ROOT')"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
function usage() {
|
||||
echo "Usage:
|
||||
bin/run-script [SCRIPT...] [SCRIPT_ARGS..]
|
||||
bin/run-script [OPTIONS]
|
||||
|
||||
Options:
|
||||
help prints this help
|
||||
ls prints a list of all available scripts
|
||||
|
||||
Examples:
|
||||
bin/run-script create_project --user-id=649c3f45711ad101a13de737
|
||||
bin/run-script ls"
|
||||
}
|
||||
|
||||
|
||||
function __main__() {
|
||||
if [[ "${1:-null}" == "null" ]] \
|
||||
|| [[ "${1:-null}" == "help" ]] \
|
||||
|| [[ "${1:-null}" == "--help" ]] ; then
|
||||
usage && exit
|
||||
fi
|
||||
|
||||
if [[ "${1:-null}" == "ls" ]] || [[ "${1:-null}" == "--ls" ]]; then
|
||||
# only prints files under services/web/scripts, no recursive lookup
|
||||
local cmd='ls -p /overleaf/services/web/scripts | grep -v /'
|
||||
exec "$TOOLKIT_ROOT/bin/docker-compose" exec sharelatex bash -c "$cmd"
|
||||
exit
|
||||
fi
|
||||
|
||||
local run_cmd="cd /overleaf/services/web; node scripts/$@"
|
||||
exec "$TOOLKIT_ROOT/bin/docker-compose" exec sharelatex bash -c "$run_cmd"
|
||||
}
|
||||
|
||||
__main__ "$@"
|
Loading…
Add table
Add a link
Reference in a new issue