2020-06-02 14:20:23 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2020-07-16 09:36:49 +01:00
|
|
|
#### Detect Toolkit Project Root ####
|
2020-07-16 13:55:18 +01:00
|
|
|
# if realpath is not available, create a semi-equivalent function
|
|
|
|
command -v realpath >/dev/null 2>&1 || realpath() {
|
|
|
|
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
|
|
|
}
|
2020-07-16 09:36:49 +01:00
|
|
|
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
|
|
|
|
|
2020-06-02 15:11:02 +01:00
|
|
|
SPACES_PER_INDENT=4
|
2020-06-02 14:20:23 +01:00
|
|
|
|
2020-06-02 16:53:28 +01:00
|
|
|
WARNINGS_FILE="$(mktemp)"
|
|
|
|
|
|
|
|
function add_warning() {
|
|
|
|
echo "$@" >> "$WARNINGS_FILE"
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:20:23 +01:00
|
|
|
function indent_to_level() {
|
2020-07-30 09:52:43 +01:00
|
|
|
local levels="$1"
|
|
|
|
local number_of_spaces=$(( levels * SPACES_PER_INDENT ))
|
|
|
|
local spaces="$(printf %${number_of_spaces}s)"
|
2020-06-02 14:20:23 +01:00
|
|
|
echo -n "${spaces}"
|
|
|
|
}
|
|
|
|
|
2020-06-03 09:28:22 +01:00
|
|
|
function print_section_separator() {
|
2020-06-17 09:44:11 +01:00
|
|
|
echo "====== $* ======"
|
2020-06-02 16:12:49 +01:00
|
|
|
}
|
2020-06-02 14:20:23 +01:00
|
|
|
|
2020-06-17 09:29:57 +01:00
|
|
|
function print_point() {
|
2020-07-30 09:52:43 +01:00
|
|
|
local indent_level="0"
|
2020-06-17 09:29:57 +01:00
|
|
|
if [[ "${1:-null}" =~ [0-9]{1} ]]; then
|
2020-06-17 09:46:36 +01:00
|
|
|
indent_level="$1"
|
2020-06-17 09:29:57 +01:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
# shellcheck disable=SC2086
|
2020-06-17 09:46:36 +01:00
|
|
|
echo "$(indent_to_level $indent_level)- $*"
|
2020-06-17 09:20:27 +01:00
|
|
|
}
|
|
|
|
|
2020-06-02 14:20:23 +01:00
|
|
|
function check_host_information() {
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 0 "Host Information"
|
2020-06-02 14:20:23 +01:00
|
|
|
|
|
|
|
# Linux or not?
|
|
|
|
if [[ $(uname -a) =~ .*Linux.* ]]; then
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "Linux"
|
2020-06-02 14:20:23 +01:00
|
|
|
else
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "Not Linux !"
|
2020-06-02 16:53:28 +01:00
|
|
|
add_warning "This system seems to not be Linux"
|
2020-06-02 14:20:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# LSB Information (particular distribution of Linux, and version)
|
|
|
|
if [[ -n $(command -v lsb_release) ]]; then
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "Output of 'lsb_release -a':"
|
2020-06-02 14:20:23 +01:00
|
|
|
lsb_release -a 2>&1 | while read -r _line; do
|
2020-06-02 15:11:02 +01:00
|
|
|
echo "$(indent_to_level 3)$_line"
|
2020-06-02 14:20:23 +01:00
|
|
|
done
|
|
|
|
else
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "lsb_release not found !"
|
2020-06-02 14:20:23 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function check_dependencies() {
|
|
|
|
|
|
|
|
function get_version() {
|
2020-07-30 09:52:43 +01:00
|
|
|
local binary_name="$1"
|
2020-06-02 14:20:23 +01:00
|
|
|
if [[ "bash" == "$binary_name" ]]; then
|
|
|
|
bash -c 'echo $BASH_VERSION'
|
2020-06-02 14:54:38 +01:00
|
|
|
elif [[ "perl" == "$binary_name" ]]; then
|
|
|
|
perl -e 'print $];'
|
2020-06-02 14:20:23 +01:00
|
|
|
else
|
2020-06-16 11:45:31 +01:00
|
|
|
$binary_name --version | head -n 1
|
2020-06-02 14:20:23 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_for_binary() {
|
2020-07-30 09:52:43 +01:00
|
|
|
local binary_name="$1"
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "$binary_name"
|
2020-06-02 16:13:16 +01:00
|
|
|
if [[ -n $(command -v "$binary_name") ]]; then
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 2 "status: present"
|
2020-07-30 09:52:43 +01:00
|
|
|
local version=$(get_version "$binary_name")
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 2 "version info: $version"
|
2020-07-16 13:55:18 +01:00
|
|
|
if [[ "$binary_name" == "realpath" ]] \
|
|
|
|
&& [[ "$(command -V "$binary_name")" =~ .*function.* ]]; then
|
2020-07-30 09:52:43 +01:00
|
|
|
local message="Could not find 'realpath' binary, falling back to custom function"
|
2020-07-16 13:55:18 +01:00
|
|
|
print_point 2 "WARNING: $message"
|
|
|
|
add_warning "$message"
|
|
|
|
fi
|
2020-06-02 14:20:23 +01:00
|
|
|
else
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 2 "status: MISSING !"
|
2020-06-02 16:53:28 +01:00
|
|
|
add_warning "$binary_name not found"
|
2020-06-02 14:20:23 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 0 "Dependencies"
|
2020-06-02 14:20:23 +01:00
|
|
|
declare -a binaries=(
|
|
|
|
bash
|
|
|
|
docker
|
|
|
|
docker-compose
|
2020-07-16 13:55:18 +01:00
|
|
|
realpath
|
2020-06-02 14:54:38 +01:00
|
|
|
perl
|
2020-06-12 09:19:22 +01:00
|
|
|
awk
|
2020-06-02 14:20:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
for binary in "${binaries[@]}"; do
|
|
|
|
check_for_binary "$binary"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-06-02 15:18:46 +01:00
|
|
|
function check_docker_daemon() {
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 0 "Docker Daemon"
|
2020-06-02 15:18:46 +01:00
|
|
|
if docker ps &>/dev/null; then
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "status: up"
|
2020-06-02 15:18:46 +01:00
|
|
|
else
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 1 "status: DOWN !"
|
2020-06-02 16:53:28 +01:00
|
|
|
add_warning "Docker daemon is not running"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_warnings() {
|
2020-07-16 13:55:18 +01:00
|
|
|
print_section_separator "Warnings"
|
2020-06-03 09:34:44 +01:00
|
|
|
if [[ -n $(head -n 1 "$WARNINGS_FILE") ]]; then
|
2020-06-02 16:53:28 +01:00
|
|
|
while read -r _line; do
|
|
|
|
echo "! $_line"
|
|
|
|
done < "$WARNINGS_FILE"
|
2020-07-16 13:55:18 +01:00
|
|
|
else
|
|
|
|
echo "- None, all good"
|
2020-06-02 15:18:46 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-05 10:54:44 +01:00
|
|
|
function check_config_files() {
|
|
|
|
print_section_separator "Configuration"
|
|
|
|
|
2020-07-30 09:52:43 +01:00
|
|
|
local config_files=(
|
2020-07-09 11:31:06 +01:00
|
|
|
"config/version"
|
2020-06-12 09:10:29 +01:00
|
|
|
"config/overleaf.rc"
|
|
|
|
"config/variables.env"
|
|
|
|
)
|
|
|
|
for config_file in "${config_files[@]}"
|
|
|
|
do
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-06-17 09:42:46 +01:00
|
|
|
print_point 0 "$config_file"
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-07-16 09:36:49 +01:00
|
|
|
if [[ ! -f "$TOOLKIT_ROOT/$config_file" ]]; then
|
2020-06-17 09:42:46 +01:00
|
|
|
print_point 1 "status: MISSING !"
|
2020-06-12 09:10:29 +01:00
|
|
|
add_warning "configuration file $config_file not found"
|
|
|
|
else
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-06-17 09:42:46 +01:00
|
|
|
print_point 1 "status: present"
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-07-09 11:31:06 +01:00
|
|
|
if [[ "$config_file" == "config/version" ]]; then
|
2020-07-16 09:36:49 +01:00
|
|
|
print_point 1 "version: $(head -n 1 "$TOOLKIT_ROOT/$config_file")"
|
2020-07-09 11:31:06 +01:00
|
|
|
elif [[ "$config_file" == "config/overleaf.rc" ]]; then
|
2020-06-17 09:54:49 +01:00
|
|
|
print_point 1 "values"
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-07-09 11:09:09 +01:00
|
|
|
# Load vars from the rc file
|
2020-06-17 09:20:27 +01:00
|
|
|
# shellcheck disable=SC1090
|
2020-07-16 09:36:49 +01:00
|
|
|
source "$TOOLKIT_ROOT/$config_file"
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-06-30 15:36:53 +01:00
|
|
|
# Check some vars from the RC file
|
2020-07-09 11:09:09 +01:00
|
|
|
if [[ "${SHARELATEX_DATA_PATH:-null}" != "null" ]]; then
|
|
|
|
print_point 2 "SHARELATEX_DATA_PATH: $SHARELATEX_DATA_PATH"
|
2020-06-17 09:20:27 +01:00
|
|
|
else
|
2020-06-17 09:29:57 +01:00
|
|
|
print_point 2 "SHARELATEX_DATA_PATH: MISSING !"
|
2020-06-17 09:20:27 +01:00
|
|
|
add_warning "rc file, SHARELATEX_DATA_PATH not set"
|
|
|
|
fi
|
2020-07-09 13:59:49 +01:00
|
|
|
|
2020-07-09 11:09:09 +01:00
|
|
|
print_point 2 "SERVER_PRO: $SERVER_PRO"
|
2020-07-21 11:16:10 +01:00
|
|
|
if [[ "${SERVER_PRO:-null}" == "true" ]]; then
|
|
|
|
local logged_in
|
2020-07-21 11:28:06 +01:00
|
|
|
logged_in="$(grep -q quay.io ~/.docker/config.json && echo 'true' || echo 'false')"
|
2020-07-21 11:16:10 +01:00
|
|
|
print_point 3 "logged in to quay.io: $logged_in"
|
|
|
|
if [[ "${logged_in}" == "false" ]]; then
|
|
|
|
local warning_message=(
|
|
|
|
"Server Pro enabled, but not logged in to quay.io repository."
|
|
|
|
"These credentials are supplied by Overleaf with a Server Pro"
|
|
|
|
"license. See https://www.overleaf.com/for/enterprises/features"
|
2020-07-21 11:27:42 +01:00
|
|
|
"for more details about Server Pro, or contact support@overleaf.com"
|
|
|
|
"if you have any questions."
|
2020-07-21 11:16:10 +01:00
|
|
|
)
|
|
|
|
add_warning "${warning_message[@]}"
|
|
|
|
fi
|
2020-07-23 09:28:34 +01:00
|
|
|
print_point 2 "SIBLING_CONTAINERS_ENABLED: $SIBLING_CONTAINERS_ENABLED"
|
2020-07-21 11:16:10 +01:00
|
|
|
fi
|
2020-07-09 15:56:38 +01:00
|
|
|
|
2020-07-09 11:09:09 +01:00
|
|
|
print_point 2 "MONGO_ENABLED: $MONGO_ENABLED"
|
2020-07-09 15:56:38 +01:00
|
|
|
if [[ "${MONGO_URL:-null}" != "null" ]]; then
|
|
|
|
print_point 2 "MONGO_URL: [set here]"
|
|
|
|
fi
|
|
|
|
if [[ "${MONGO_IMAGE:-null}" != "null" ]]; then
|
|
|
|
print_point 2 "MONGO_IMAGE: $MONGO_IMAGE"
|
|
|
|
fi
|
|
|
|
|
2020-07-09 11:09:09 +01:00
|
|
|
print_point 2 "REDIS_ENABLED: $REDIS_ENABLED"
|
2020-07-09 15:56:38 +01:00
|
|
|
if [[ "${REDIS_HOST:-null}" != "null" ]]; then
|
|
|
|
print_point 2 "REDIS_HOST: [set here]"
|
|
|
|
fi
|
|
|
|
if [[ "${REDIS_PORT:-null}" != "null" ]]; then
|
|
|
|
print_point 2 "REDIS_PORT: [set here]"
|
|
|
|
fi
|
|
|
|
if [[ "${REDIS_IMAGE:-null}" != "null" ]]; then
|
|
|
|
print_point 2 "REDIS_IMAGE: $REDIS_IMAGE"
|
|
|
|
fi
|
2020-06-17 09:20:27 +01:00
|
|
|
fi
|
2020-06-12 09:10:29 +01:00
|
|
|
fi
|
|
|
|
done
|
2020-06-05 10:54:44 +01:00
|
|
|
}
|
|
|
|
|
2020-06-02 16:53:28 +01:00
|
|
|
function cleanup() {
|
|
|
|
rm "$WARNINGS_FILE"
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:20:23 +01:00
|
|
|
function __main__() {
|
2020-06-03 09:28:22 +01:00
|
|
|
print_section_separator "Overleaf Doctor"
|
2020-06-02 14:20:23 +01:00
|
|
|
check_host_information
|
|
|
|
check_dependencies
|
2020-06-02 15:18:46 +01:00
|
|
|
check_docker_daemon
|
2020-06-05 10:54:44 +01:00
|
|
|
check_config_files
|
2020-06-02 16:53:28 +01:00
|
|
|
print_warnings
|
2020-06-03 09:28:22 +01:00
|
|
|
print_section_separator "End"
|
2020-06-02 16:53:28 +01:00
|
|
|
cleanup
|
2020-06-02 14:20:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
__main__ "$@"
|