diff --git a/scripts/cloudron-support b/scripts/cloudron-support index f5eea02cd..9d057f925 100755 --- a/scripts/cloudron-support +++ b/scripts/cloudron-support @@ -8,6 +8,11 @@ if [[ ${EUID} -ne 0 ]]; then exit 1 fi +readonly RED='\033[31m' +readonly GREEN='\033[32m' +readonly YELLOW='\033[33m' +readonly DONE='\033[m' + readonly PASTEBIN="https://paste.cloudron.io" readonly LINE="\n========================================================\n" readonly HELP_MESSAGE=" @@ -23,6 +28,22 @@ readonly HELP_MESSAGE=" --help Show this message " +function success() { + echo -e "[${GREEN}OK${DONE}]\t${1}" +} + +function info() { + echo -e "${1}" +} + +function warn() { + echo -e "[${YELLOW}WARN${DONE}]\t${1}" +} + +function fail() { + echo -e "[${RED}FAIL${DONE}]\t${1}" +} + function enable_remote_access() { local -r cloudron_support_public_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGWS+930b8QdzbchGljt3KSljH9wRhYvht8srrtQHdzg support@cloudron.io" local -r ssh_user="cloudron-support" @@ -42,17 +63,17 @@ function enable_remote_access() { function check_host_mysql() { if ! systemctl is-active -q mysql; then - echo "MySQL is down. Maybe restarting fixes it" + info "MySQL is down. Maybe restarting fixes it" systemctl restart mysql if ! systemctl is-active -q mysql; then - echo "MySQL is still down, please investigate the error by inspecting /var/log/mysql/error.log" + fail "MySQL is still down, please investigate the error by inspecting /var/log/mysql/error.log" exit 1 fi fi - echo "MySQL is OK" + success "MySQL is running" } function owner_login() { @@ -124,68 +145,69 @@ function send_diagnostics() { function check_unbound() { if ! systemctl is-active -q unbound; then - echo "unbound is down. updating root anchor to see if it fixes it" + info "unbound is down. updating root anchor to see if it fixes it" unbound-anchor -a /var/lib/unbound/root.key systemctl restart unbound if ! systemctl is-active -q unbound; then - echo "unbound is still down, please investigate the error using 'journalctl -u unbound'" + fail "unbound is still down, please investigate the error using 'journalctl -u unbound'" exit 1 fi fi test_resolve=$(dig cloudron.io @127.0.0.1 +short) if [[ -z "test_resolve" ]]; then - echo "DNS is not resolving, maybe try forwarding all DNS requests using the --use-external-dns option" + fail "DNS is not resolving, maybe try forwarding all DNS requests using the --use-external-dns option" exit 1 fi - echo "unbound is OK" + success "unbound is running" } function check_nginx() { if ! systemctl is-active -q nginx; then - echo "nginx is down. checking if this is because of invalid certs" + fail "nginx is down. checking if this is because of invalid certs" # TODO: delete config files that use invalid certs and restart nginx fi - echo "nginx is OK" + success "nginx is running" } function check_docker() { if ! systemctl is-active -q docker; then - echo "Docker is down. Maybe restarting fixes it" + info "Docker is down. Maybe restarting fixes it" systemctl restart docker if ! systemctl is-active -q docker; then - echo "Docker is still down, please investigate the error using 'journalctl -u docker'" + fail "Docker is still down, please investigate the error using 'journalctl -u docker'" exit 1 fi fi - echo "docker is OK" + success "docker is running" } function check_hairpin_nat() { local -r dashboard_domain=$(mysql -NB -uroot -ppassword -e "SELECT value FROM box.settings WHERE name='dashboard_domain'" 2>/dev/null) if ! curl --fail -s https://my.${dashboard_domain} >/dev/null; then - echo "Could not query dashboard domain. Is Hairpin NAT functional?" + fail "Could not query dashboard domain. Is Hairpin NAT functional?" exit 1 fi - echo "Hairpin NAT is OK" + success "Hairpin NAT is good" } function check_expired_domain() { + local -r dashboard_domain=$(mysql -NB -uroot -ppassword -e "SELECT value FROM box.settings WHERE name='dashboard_domain'" 2>/dev/null) + if ! command -v whois &> /dev/null; then - echo "Domain expiry check skipped because whois is not installed. Run 'apt install whois' to check" + info "Domain ${dashboard_domain} expiry check skipped because whois is not installed. Run 'apt install whois' to check" exit 0 fi - local -r dashboard_domain=$(mysql -NB -uroot -ppassword -e "SELECT value FROM box.settings WHERE name='dashboard_domain'" 2>/dev/null) local -r expdate=$(whois ${dashboard_domain} | egrep -i 'Expiration Date:|Expires on|Expiry Date:' | head -1 | awk '{print $NF}') if [[ -z "${expdate}" ]]; then - echo "Domain expiry check skipped because whois does not have this information" + warn "Domain ${dashboard_domain} expiry check skipped because whois does not have this information" exit 0 fi @@ -193,17 +215,17 @@ function check_expired_domain() { local -r curdate_secs="$(date +%s)" if (( curdate_secs > expdate_secs )); then - echo "Domain appears to be expired" + fail "Domain ${dashboard_domain} appears to be expired" exit 1 fi - echo "Domain is valid and has not expired" + success "Domain ${dashboard_domain} is valid and has not expired" } function use_external_dns() { local -r $conf_file="/etc/unbound/unbound.conf.d/forward-everything.conf" - echo "Forwarding all DNS requests to Google/Cloudflare DNS. To remove the forwarding, please delete $conf and 'systemctl restart unbound'" + info "Forwarding all DNS requests to Google/Cloudflare DNS. To remove the forwarding, please delete $conf and 'systemctl restart unbound'" cat > $conf_file < $conf_file <