1
0
Fork 0
mirror of https://github.com/overleaf/toolkit.git synced 2025-04-19 23:38:06 +02:00
overleaf-toolkit/bin/up

67 lines
1.8 KiB
Text
Raw Permalink Normal View History

2020-06-02 14:20:23 +01:00
#! /usr/bin/env bash
# shellcheck source-path=..
2020-06-02 14:20:23 +01:00
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
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
function usage() {
echo "Usage: bin/up [FLAGS...]"
echo ""
echo "A wrapper around 'docker compose up'."
echo ""
echo "This program will pass any extra flags to docker compose,"
echo "for example: 'bin/up -d' will run in detached mode"
}
2020-06-02 14:20:23 +01:00
function check_config() {
if [[ ! -f "$TOOLKIT_ROOT/config/overleaf.rc" ]] \
|| [[ ! -f "$TOOLKIT_ROOT/config/variables.env" ]]; then
echo "Config files not found! exiting"
exit 1
fi
}
function initiate_mongo_replica_set() {
echo "Initiating Mongo replica set..."
"$TOOLKIT_ROOT/bin/docker-compose" up -d mongo
"$TOOLKIT_ROOT/bin/docker-compose" exec -T mongo sh -c '
while ! mongo --eval "db.version()" > /dev/null; do
echo "Waiting for Mongo..."
sleep 1
done
mongo --eval "rs.initiate({ _id: \"overleaf\", members: [ { _id: 0, host: \"mongo:27017\" } ] })" > /dev/null'
}
2020-06-02 14:20:23 +01:00
function __main__() {
if [[ "${1:-null}" == "help" ]] || [[ "${1:-null}" == "--help" ]]; then
usage
exit
fi
read_image_version
2020-06-02 14:20:23 +01:00
check_config
read_config
if [[ "$MONGO_ENABLED" == "true" && "$IMAGE_VERSION_MAJOR" -ge 4 ]]; then
initiate_mongo_replica_set
fi
exec "$TOOLKIT_ROOT/bin/docker-compose" up "$@"
2020-06-02 14:20:23 +01:00
}
__main__ "$@"