2020-06-02 14:20:23 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
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() {
|
|
|
|
levels="$1"
|
|
|
|
number_of_spaces=$(( levels * SPACES_PER_INDENT ))
|
|
|
|
spaces="$(printf %${number_of_spaces}s)"
|
|
|
|
echo -n "${spaces}"
|
|
|
|
}
|
|
|
|
|
2020-06-03 09:28:22 +01:00
|
|
|
function print_section_separator() {
|
|
|
|
echo "== $* =="
|
2020-06-02 16:12:49 +01:00
|
|
|
}
|
2020-06-02 14:20:23 +01:00
|
|
|
|
|
|
|
function print_heading() {
|
2020-06-02 16:13:04 +01:00
|
|
|
echo "- $*"
|
2020-06-02 14:20:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_sub_point() {
|
2020-06-02 16:13:04 +01:00
|
|
|
echo "$(indent_to_level 1)- $*"
|
2020-06-02 14:20:23 +01:00
|
|
|
}
|
|
|
|
|
2020-06-02 15:11:02 +01:00
|
|
|
function print_sub_sub_point() {
|
2020-06-02 16:13:04 +01:00
|
|
|
echo "$(indent_to_level 2)- $*"
|
2020-06-02 15:11:02 +01:00
|
|
|
}
|
|
|
|
|
2020-06-02 14:20:23 +01:00
|
|
|
function check_host_information() {
|
|
|
|
print_heading "Host Information"
|
|
|
|
|
|
|
|
# Linux or not?
|
|
|
|
if [[ $(uname -a) =~ .*Linux.* ]]; then
|
|
|
|
print_sub_point "Linux"
|
|
|
|
else
|
|
|
|
print_sub_point "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
|
|
|
|
print_sub_point "Output of 'lsb_release -a':"
|
|
|
|
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
|
|
|
|
print_sub_point "lsb_release not found !"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function check_dependencies() {
|
|
|
|
|
|
|
|
function get_version() {
|
|
|
|
binary_name="$1"
|
|
|
|
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
|
|
|
|
$binary_name --version
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_for_binary() {
|
|
|
|
binary_name="$1"
|
2020-06-02 15:11:02 +01:00
|
|
|
print_sub_point "$binary_name"
|
2020-06-02 16:13:16 +01:00
|
|
|
if [[ -n $(command -v "$binary_name") ]]; then
|
2020-06-02 15:11:02 +01:00
|
|
|
print_sub_sub_point "status: present"
|
2020-06-02 16:13:16 +01:00
|
|
|
version=$(get_version "$binary_name")
|
2020-06-02 15:11:02 +01:00
|
|
|
print_sub_sub_point "version info: $version"
|
2020-06-02 14:20:23 +01:00
|
|
|
else
|
2020-06-02 15:11:02 +01:00
|
|
|
print_sub_sub_point "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
|
|
|
|
}
|
|
|
|
|
|
|
|
print_heading "Dependencies"
|
|
|
|
declare -a binaries=(
|
|
|
|
bash
|
|
|
|
docker
|
|
|
|
docker-compose
|
2020-06-02 15:11:02 +01:00
|
|
|
some-fake-program
|
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() {
|
|
|
|
print_heading "Docker Daemon"
|
|
|
|
if docker ps &>/dev/null; then
|
|
|
|
print_sub_point "status: up"
|
|
|
|
else
|
2020-06-02 15:19:15 +01:00
|
|
|
print_sub_point "status: DOWN !"
|
2020-06-02 16:53:28 +01:00
|
|
|
add_warning "Docker daemon is not running"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_warnings() {
|
2020-06-03 09:34:44 +01:00
|
|
|
if [[ -n $(head -n 1 "$WARNINGS_FILE") ]]; then
|
2020-06-03 09:28:22 +01:00
|
|
|
print_section_separator "Warnings"
|
2020-06-02 16:53:28 +01:00
|
|
|
while read -r _line; do
|
|
|
|
echo "! $_line"
|
|
|
|
done < "$WARNINGS_FILE"
|
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-06-12 09:10:29 +01:00
|
|
|
config_files=(
|
|
|
|
"config/overleaf.rc"
|
|
|
|
"config/variables.env"
|
|
|
|
"config/docker-compose.base.yml"
|
|
|
|
"config/docker-compose.mongo.yml"
|
|
|
|
"config/docker-compose.redis.yml"
|
2020-06-12 09:12:21 +01:00
|
|
|
"config/docker-compose.sibling-containers.yml"
|
2020-06-12 09:10:29 +01:00
|
|
|
)
|
|
|
|
for config_file in "${config_files[@]}"
|
|
|
|
do
|
|
|
|
print_sub_point "$config_file"
|
|
|
|
if [[ ! -f "$config_file" ]]; then
|
|
|
|
print_sub_sub_point "status: MISSING !"
|
|
|
|
add_warning "configuration file $config_file not found"
|
|
|
|
else
|
|
|
|
print_sub_sub_point "status: present"
|
|
|
|
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__ "$@"
|