Skip to content

Commit 22084fb

Browse files
Kumar AnuragKumar Anurag
Kumar Anurag
authored and
Kumar Anurag
committed
LoboTeX
1 parent a2c08a8 commit 22084fb

File tree

382 files changed

+12869
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

382 files changed

+12869
-0
lines changed

bin/backup-config

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#! /usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
#### Detect Toolkit Project Root ####
6+
# if realpath is not available, create a semi-equivalent function
7+
command -v realpath >/dev/null 2>&1 || realpath() {
8+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
9+
}
10+
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
11+
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
12+
TOOLKIT_ROOT="$(realpath "$SCRIPT_DIR/..")"
13+
if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
14+
echo "ERROR: could not find root of overleaf-toolkit project (inferred project root as '$TOOLKIT_ROOT')"
15+
exit 1
16+
fi
17+
18+
function usage() {
19+
echo "Usage: bin/backup-config [OPTIONS] [DESTINATION]"
20+
echo ""
21+
echo "Backup configuration files, to DESTINATION"
22+
echo ""
23+
echo "Options:"
24+
echo " -m mode: zip | tar | copy (default=copy)"
25+
echo ""
26+
echo "Examples:"
27+
echo ""
28+
echo " bin/backup-config -m zip ~/overleaf-config-backup.zip"
29+
echo ""
30+
echo " bin/backup-config -m tar ~/overleaf-config-backup.tar"
31+
echo ""
32+
echo " bin/backup-config -m copy ~/overleaf-config-backup"
33+
echo ""
34+
echo " bin/backup-config ~/overleaf-config-backup"
35+
echo ""
36+
}
37+
38+
function __main__() {
39+
mode='copy'
40+
41+
while getopts "m:" opt
42+
do
43+
case $opt in
44+
m ) mode="${OPTARG}" ;;
45+
\?) usage && exit ;;
46+
esac
47+
done
48+
shift $(( OPTIND -1 ))
49+
50+
if [[ "${1:-null}" == "null" ]] \
51+
|| [[ "${1:-null}" == "help" ]] \
52+
|| [[ "${1:-null}" == "--help" ]] ; then
53+
usage && exit
54+
fi
55+
56+
destination="$1"
57+
58+
if [[ "$mode" == "copy" ]]; then
59+
cp -r "$TOOLKIT_ROOT/config" "$destination"
60+
elif [[ "$mode" == "zip" ]]; then
61+
zip -j -r "$destination" "$TOOLKIT_ROOT/config"
62+
elif [[ "$mode" == "tar" ]]; then
63+
tar -cf "$destination" -C "$TOOLKIT_ROOT" config
64+
else
65+
echo "Error: unrecognized mode '$mode'"
66+
exit 1
67+
fi
68+
}
69+
70+
__main__ "$@"

bin/dev/lint

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /usr/bin/env bash
2+
3+
exec find ./bin -type f -not -name '*.swp' -print0 | xargs -0 shellcheck

bin/docker-compose

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#! /usr/bin/env bash
2+
# shellcheck source-path=..
3+
4+
set -euo pipefail
5+
6+
#### Detect Toolkit Project Root ####
7+
# if realpath is not available, create a semi-equivalent function
8+
command -v realpath >/dev/null 2>&1 || realpath() {
9+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
10+
}
11+
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
12+
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
13+
TOOLKIT_ROOT="$(realpath "$SCRIPT_DIR/..")"
14+
if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
15+
echo "ERROR: could not find root of overleaf-toolkit project (inferred project root as '$TOOLKIT_ROOT')"
16+
exit 1
17+
fi
18+
19+
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
20+
21+
function build_environment() {
22+
canonicalize_data_paths
23+
set_base_vars
24+
25+
if [[ $REDIS_ENABLED == "true" ]]; then
26+
set_redis_vars
27+
fi
28+
if [[ $MONGO_ENABLED == "true" ]]; then
29+
set_mongo_vars
30+
fi
31+
if [[ "$SIBLING_CONTAINERS_ENABLED" == "true" ]]; then
32+
if [[ $SERVER_PRO == "true" ]]; then
33+
set_sibling_containers_vars
34+
else
35+
if [[ ${SKIP_WARNINGS:-null} != "true" ]]; then
36+
echo "WARNING: SIBLING_CONTAINERS_ENABLED=true is not supported in Overleaf Community Edition." >&2
37+
echo " Sibling containers are not available in Community Edition, which is intended for use in environments where all users are trusted. Community Edition is not appropriate for scenarios where isolation of users is required." >&2
38+
echo " When not using Sibling containers, users have full read and write access to the 'sharelatex' container resources (filesystem, network, environment variables) when running LaTeX compiles." >&2
39+
echo " Sibling containers are offered as part of our Server Pro offering and you can read more about the differences at https://www.overleaf.com/for/enterprises/features." >&2
40+
echo " Falling back using insecure in-container compiles. Set SIBLING_CONTAINERS_ENABLED=false in config/overleaf.rc to silence this warning." >&2
41+
fi
42+
fi
43+
fi
44+
if [[ "${OVERLEAF_LOG_PATH:-null}" != "null" ]]; then
45+
set_logging_vars
46+
fi
47+
if [[ $NGINX_ENABLED == "true" ]]; then
48+
set_nginx_vars
49+
fi
50+
if [[ $GIT_BRIDGE_ENABLED == "true" ]]; then
51+
set_git_bridge_vars
52+
fi
53+
54+
# Include docker-compose.override.yml if it is present
55+
if [[ -f "$TOOLKIT_ROOT/config/docker-compose.override.yml" ]]; then
56+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/config/docker-compose.override.yml")
57+
fi
58+
}
59+
60+
function canonicalize_data_paths() {
61+
OVERLEAF_DATA_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$OVERLEAF_DATA_PATH")
62+
if [[ "${OVERLEAF_LOG_PATH:-null}" != "null" ]]; then
63+
OVERLEAF_LOG_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$OVERLEAF_LOG_PATH")
64+
fi
65+
MONGO_DATA_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$MONGO_DATA_PATH")
66+
REDIS_DATA_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$REDIS_DATA_PATH")
67+
GIT_BRIDGE_DATA_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$GIT_BRIDGE_DATA_PATH")
68+
}
69+
70+
# Set environment variables for docker-compose.base.yml
71+
function set_base_vars() {
72+
DOCKER_COMPOSE_FLAGS=(-f "$TOOLKIT_ROOT/lib/docker-compose.base.yml")
73+
if [[ "$IMAGE_VERSION_MAJOR" -lt 5 ]]; then
74+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.vars-legacy.yml")
75+
else
76+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.vars.yml")
77+
fi
78+
79+
set_server_pro_image_name "$IMAGE_VERSION"
80+
81+
if [[ ${OVERLEAF_LISTEN_IP:-null} == "null" ]];
82+
then
83+
if [[ ${SKIP_WARNINGS:-null} != "true" ]]; then
84+
echo "WARNING: the value of OVERLEAF_LISTEN_IP is not set in config/overleaf.rc. This value must be set to the public IP address for direct container access. Defaulting to 0.0.0.0" >&2
85+
fi
86+
OVERLEAF_LISTEN_IP="0.0.0.0"
87+
fi
88+
export OVERLEAF_LISTEN_IP
89+
90+
HAS_WEB_API=false
91+
if [[ $IMAGE_VERSION_MAJOR -gt 4 ]]; then
92+
HAS_WEB_API=true
93+
elif [[ $IMAGE_VERSION_MAJOR == 4 && $IMAGE_VERSION_MINOR -ge 2 ]]; then
94+
HAS_WEB_API=true
95+
fi
96+
97+
OVERLEAF_IN_CONTAINER_DATA_PATH=/var/lib/overleaf
98+
if [[ "$IMAGE_VERSION_MAJOR" -lt 5 ]]; then
99+
OVERLEAF_IN_CONTAINER_DATA_PATH=/var/lib/sharelatex
100+
fi
101+
102+
export GIT_BRIDGE_ENABLED
103+
export MONGO_URL
104+
export REDIS_HOST
105+
export REDIS_PORT
106+
export OVERLEAF_DATA_PATH
107+
export OVERLEAF_PORT
108+
export OVERLEAF_IN_CONTAINER_DATA_PATH
109+
110+
}
111+
112+
# Set environment variables for docker-compose.redis.yml
113+
function set_redis_vars() {
114+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.redis.yml")
115+
export REDIS_IMAGE
116+
export REDIS_DATA_PATH
117+
118+
if [[ -z "${REDIS_AOF_PERSISTENCE:-}" ]]; then
119+
if [[ ${SKIP_WARNINGS:-null} != "true" ]]; then
120+
echo "WARNING: the value of REDIS_AOF_PERSISTENCE is not set in config/overleaf.rc"
121+
echo " See https://github.com/overleaf/overleaf/wiki/Release-Notes-5.x.x#redis-aof-persistence-enabled-by-default"
122+
fi
123+
REDIS_COMMAND="redis-server"
124+
elif [[ $REDIS_AOF_PERSISTENCE == "true" ]]; then
125+
REDIS_COMMAND="redis-server --appendonly yes"
126+
else
127+
REDIS_COMMAND="redis-server"
128+
fi
129+
export REDIS_COMMAND
130+
}
131+
132+
# Set environment variables for docker-compose.mongo.yml
133+
function set_mongo_vars() {
134+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.mongo.yml")
135+
136+
if [[ $MONGO_ENABLED == "true" && $IMAGE_VERSION_MAJOR -ge 4 ]]; then
137+
MONGO_ARGS="--replSet overleaf"
138+
else
139+
MONGO_ARGS=""
140+
fi
141+
export MONGO_ARGS
142+
143+
export MONGO_DATA_PATH
144+
export MONGO_DOCKER_IMAGE
145+
export MONGOSH
146+
}
147+
148+
# Set environment variables for docker-compose.sibling-containers.yml
149+
function set_sibling_containers_vars() {
150+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.sibling-containers.yml")
151+
export DOCKER_SOCKET_PATH
152+
export OVERLEAF_DATA_PATH
153+
}
154+
155+
# Set environment variables for docker-compose.logging.yml
156+
function set_logging_vars() {
157+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.logging.yml")
158+
159+
if [[ $IMAGE_VERSION_MAJOR -ge 5 ]]; then
160+
OVERLEAF_IN_CONTAINER_LOG_PATH="/var/log/overleaf"
161+
else
162+
OVERLEAF_IN_CONTAINER_LOG_PATH="/var/log/sharelatex"
163+
fi
164+
export OVERLEAF_IN_CONTAINER_LOG_PATH
165+
export OVERLEAF_LOG_PATH
166+
}
167+
168+
# Set environment variables for docker-compose.nginx.yml
169+
function set_nginx_vars() {
170+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.nginx.yml")
171+
172+
if [[ -n ${TLS_PRIVATE_KEY_PATH-} ]]; then
173+
TLS_PRIVATE_KEY_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$TLS_PRIVATE_KEY_PATH")
174+
fi
175+
if [[ -n ${TLS_CERTIFICATE_PATH-} ]]; then
176+
TLS_CERTIFICATE_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$TLS_CERTIFICATE_PATH")
177+
fi
178+
if [[ -n ${NGINX_CONFIG_PATH-} ]]; then
179+
NGINX_CONFIG_PATH=$(cd "$TOOLKIT_ROOT"; realpath "$NGINX_CONFIG_PATH")
180+
fi
181+
182+
export NGINX_CONFIG_PATH
183+
export NGINX_IMAGE
184+
export NGINX_HTTP_PORT
185+
export NGINX_HTTP_LISTEN_IP
186+
export NGINX_TLS_LISTEN_IP
187+
export TLS_CERTIFICATE_PATH
188+
export TLS_PORT
189+
export TLS_PRIVATE_KEY_PATH
190+
}
191+
192+
# Set environment variables for docker-compose.git-bridge.yml
193+
function set_git_bridge_vars() {
194+
set_git_bridge_image_name "$IMAGE_VERSION"
195+
196+
GIT_BRIDGE_API_BASE_URL="http://sharelatex/api/v0/"
197+
if [[ $HAS_WEB_API == "true" ]]; then
198+
GIT_BRIDGE_API_BASE_URL="http://sharelatex:3000/api/v0/"
199+
fi
200+
201+
DOCKER_COMPOSE_FLAGS+=(-f "$TOOLKIT_ROOT/lib/docker-compose.git-bridge.yml")
202+
export GIT_BRIDGE_API_BASE_URL
203+
export GIT_BRIDGE_DATA_PATH
204+
export GIT_BRIDGE_LOG_LEVEL
205+
}
206+
207+
function print_debug_info() {
208+
if [[ ${RC_DEBUG:-null} != "null" ]]; then
209+
echo ">>>>>>VARS>>>>>>"
210+
echo "$(set -o posix; set)" # print all vars
211+
echo "IMAGE_VERSION=$IMAGE_VERSION"
212+
echo "<<<<<<<<<<<<<<<<"
213+
echo ">>>>COMPOSE-ARGS>>>>"
214+
echo "-p $PROJECT_NAME"
215+
echo "${DOCKER_COMPOSE_FLAGS[@]}"
216+
echo "$@"
217+
echo "<<<<<<<<<<<<<<<<<<<<"
218+
fi
219+
}
220+
221+
function docker_compose() {
222+
local flags=(-p "$PROJECT_NAME" "${DOCKER_COMPOSE_FLAGS[@]}" "$@")
223+
if docker compose version >/dev/null 2>&1; then
224+
# Docker compose v2 is available
225+
exec docker compose "${flags[@]}"
226+
elif command -v docker-compose >/dev/null; then
227+
# Fall back to docker-compose v1
228+
if [[ ${SKIP_WARNINGS:-null} != "true" ]]; then
229+
echo "WARNING: docker-compose v1 has reached its End Of Life in July 2023 (https://docs.docker.com/compose/migrate/). Support for docker-compose v1 in the Overleaf Toolkit will be dropped with the release of Server Pro 5.2. We recommend upgrading to Docker Compose v2 before then." >&2
230+
fi
231+
exec docker-compose "${flags[@]}"
232+
else
233+
echo "ERROR: Could not find Docker Compose." >&2
234+
exit 1
235+
fi
236+
}
237+
238+
read_image_version
239+
read_mongo_version
240+
read_config
241+
check_retracted_version
242+
check_sharelatex_env_vars
243+
build_environment
244+
print_debug_info "$@"
245+
docker_compose "$@"

0 commit comments

Comments
 (0)