/
check_certs.sh
42 lines (33 loc) · 962 Bytes
/
check_certs.sh
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
#!/bin/bash
USAGE="
sudo $0 /path/to/cert.pem
"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please run with sudo."
exit 1
fi
if [[ $# -eq 0 || -z "$1" ]]; then
echo "Please specify the location of a cert file to compare against.
$USAGE "
exit 1
fi
CURRENT_VER=$(md5sum "$1" | awk '{print $1}')
declare -a allcerts
readarray -t allcerts < <(find /usr/syno/etc/certificate/ -type f -name "cert.pem")
declare -a certs_unmatching
if [ ${#allcerts[@]} -eq 0 ]; then
echo "No certificates found."
exit 1
fi
for dir in "${allcerts[@]}"; do
THIS_VERSION=$(md5sum "$dir" | awk '{print $1}')
if [[ "$CURRENT_VER" != "$THIS_VERSION" ]]; then
certs_unmatching+=("$dir")
fi
done
if [ ${#certs_unmatching[@]} -eq 0 ]; then
echo "All certificates match the current version."
else
echo "The following certificates do not match the current version:"
printf '%s\n' "${certs_unmatching[@]}" | sed 's/^/ - /'
fi