Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ncp-diag « bin - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6289fb98df31f998f7bd96fed821d3ed2145a661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash

# NextCloudPi diagnostics report
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage:
#   sudo ncp-diag
#
# More at https://ownyourbits.com
#

# Distro, NCP version and tag
echo "NextCloudPi version|$( cat /usr/local/etc/ncp-version )"
echo "NextCloudPi image|$( cat /usr/local/etc/ncp-baseimage )"
echo "distribution|$( cat /etc/issue )"

# Data
DATADIR="$( grep datadirectory /var/www/nextcloud/config/config.php |
	    awk '{ print $3 }' | grep -oP "[^']*[^']" | head -1 )"
test -d "$DATADIR" || DIRINFO=" (doesn't exist)"
USBDEVS="$( lsblk -S -o  NAME,TRAN | awk '{ if ( $2 == "usb" ) print $1; }' | tr '\n' ' ' )"
[[ "$USBDEVS" == "" ]] && USBDEVS="none"

echo "automount|$( grep "^ACTIVE_" /usr/local/etc/nextcloudpi-config.d/nc-automount.sh | cut -d'=' -f2 )"
echo "USB devices|$USBDEVS"
echo "datadir|$DATADIR$DIRINFO"
[[ "$DIRINFO" == "" ]] && {
  echo "data in SD|$( [[ $( stat -fc%d / ) == $( stat -fc%d "$DATADIR" ) ]] && echo yes || echo no )"
  echo "data filesystem|$( stat -fc%T $DATADIR )"
  echo "data disk usage|$( df -h "$DATADIR" | tail -1 | awk '{ print $3"/"$2 }')"
}
echo "rootfs usage|$( df -h / | tail -1 | awk '{ print $3"/"$2 }')"

# Nextcloud
VERSION="$( sudo -u www-data php /var/www/nextcloud/occ status | grep "version:" | awk '{ print $3 }' )"
if [[ "$VERSION" != "" ]]; then
  echo "Nextcloud check|ok"
  echo "Nextcloud version|$VERSION"
  else
  echo "Nextcloud check|error"
fi

# Services
echo "HTTPD service|$( pgrep -c apache2 &>/dev/null && echo up || echo down )"
echo "PHP service|$( pgrep -c php-fpm &>/dev/null && echo up || echo down )"
echo "MariaDB service|$( pgrep -c mysqld &>/dev/null && echo up || echo down )"
echo "Redis service|$( pgrep -c redis-server &>/dev/null && echo up || echo down )"
echo "Postfix service|$( postfix status &>/dev/null && echo up || echo down )"

# WAN
echo "internet check|$( ping -W 2 -w 1 -q github.com &>/dev/null && echo ok || echo no } )"

function is_port_open()
{
  PORT=$1
  wget -q http://canyouseeme.org --post-data \
    "IP=$(wget -q ipinfo.io/ip -O -)&port=$PORT" \
    -O - | grep -q "Connection refused" && { echo "closed"; return 1; }
  echo "open"
}

echo "port check 80|$( is_port_open 80 )"
echo "port check 443|$( is_port_open 443 )"

# LAN
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
GW=$(    ip r | grep "default via" | awk '{ print $3 }' )
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )

echo "IP|$IP"
echo "gateway|$GW"
echo "interface|$IFACE"

# Certificates
LEOUT="$( /etc/letsencrypt/letsencrypt-auto certificates 2>/dev/null )"
CERTS="$( echo -e "$LEOUT" | grep "Domains:" | awk '{ print $2 }' | tr '\n' ' ' )"
CDUE="$( echo -e "$LEOUT" | grep "VALID:"   | grep -oP "\d+ days" | tr '\n' ' ' )"
[[ "$CERTS" == "" ]] && CERTS=none
[[ "$CDUE" == "" ]] && CDUE=none
echo "certificates|$CERTS"
echo "certs due|$CDUE"

RESOLV="$( ping -c 1 "$CERTS" 2>/dev/null | head -1 | grep -oP '\d{1,3}(.\d{1,3}){3}' )"
echo "NAT loopback|$( [[ "$RESOLV" == "$IP" ]] && echo yes || echo no )"

# Other
echo "uptime|$( uptime | cut -f1 -d',' | awk '{ $1=""; $2=""; print }' | tr -d "  " )"

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA