1
0
Fork 0
mirror of https://github.com/overleaf/toolkit.git synced 2025-04-19 15:28:06 +02:00
overleaf-toolkit/bin/doctor
2020-06-12 09:19:22 +01:00

157 lines
3.3 KiB
Bash
Executable file

#! /usr/bin/env bash
set -euo pipefail
SPACES_PER_INDENT=4
WARNINGS_FILE="$(mktemp)"
function add_warning() {
echo "$@" >> "$WARNINGS_FILE"
}
function indent_to_level() {
levels="$1"
number_of_spaces=$(( levels * SPACES_PER_INDENT ))
spaces="$(printf %${number_of_spaces}s)"
echo -n "${spaces}"
}
function print_section_separator() {
echo "== $* =="
}
function print_heading() {
echo "- $*"
}
function print_sub_point() {
echo "$(indent_to_level 1)- $*"
}
function print_sub_sub_point() {
echo "$(indent_to_level 2)- $*"
}
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 !"
add_warning "This system seems to not be Linux"
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
echo "$(indent_to_level 3)$_line"
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'
elif [[ "perl" == "$binary_name" ]]; then
perl -e 'print $];'
else
$binary_name --version
fi
}
function check_for_binary() {
binary_name="$1"
print_sub_point "$binary_name"
if [[ -n $(command -v "$binary_name") ]]; then
print_sub_sub_point "status: present"
version=$(get_version "$binary_name")
print_sub_sub_point "version info: $version"
else
print_sub_sub_point "status: MISSING !"
add_warning "$binary_name not found"
fi
}
print_heading "Dependencies"
declare -a binaries=(
bash
docker
docker-compose
some-fake-program
perl
awk
)
for binary in "${binaries[@]}"; do
check_for_binary "$binary"
done
}
function check_docker_daemon() {
print_heading "Docker Daemon"
if docker ps &>/dev/null; then
print_sub_point "status: up"
else
print_sub_point "status: DOWN !"
add_warning "Docker daemon is not running"
fi
}
function print_warnings() {
if [[ -n $(head -n 1 "$WARNINGS_FILE") ]]; then
print_section_separator "Warnings"
while read -r _line; do
echo "! $_line"
done < "$WARNINGS_FILE"
fi
}
function check_config_files() {
print_section_separator "Configuration"
config_files=(
"config/overleaf.rc"
"config/variables.env"
"config/docker-compose.base.yml"
"config/docker-compose.mongo.yml"
"config/docker-compose.redis.yml"
"config/docker-compose.sibling-containers.yml"
)
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
}
function cleanup() {
rm "$WARNINGS_FILE"
}
function __main__() {
print_section_separator "Overleaf Doctor"
check_host_information
check_dependencies
check_docker_daemon
check_config_files
print_warnings
print_section_separator "End"
cleanup
}
__main__ "$@"