forked from thctlo/samba4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
samba-info.sh
114 lines (97 loc) · 3.99 KB
/
samba-info.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
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
107
108
109
110
111
112
113
114
#!/bin/bash
##
## Version : 1.0.0
## release d.d. : 21-11-2016
## Author : L. van Belle
## E-mail : [email protected]
## Copyright : Free as free can be, copy it, change it if needed.
# This script checks you setup for the basic settings.
#
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
UNDERLINE=$(tput smul)
error() {
printf "%40s\n" "${RED}$@${NORMAL}"
}
warning() {
printf "%40s\n" "${YELLOW}$@${NORMAL}"
}
warning_underline() {
printf "%40s\n" "${YELLOW}${UNDERLINE}$@${NORMAL}"
}
check_run_as_sudo_root() {
if ! [[ $EUID -eq 0 ]]; then
error "This script should be run using sudo or by root."
exit 1
fi
}
#
######## LEAVE THESE HERE AND DONT CHANGE THESE 3 !!!!!!
## hostname in single word, but you dont need to change this
SETHOSTNAME=`hostname -s`
## domainname.tld, but if you installed correct, you dont need to change this
SETDNSDOMAIN=`hostname -d`
## hostname.domainname.tld, but if you installed correct, you dont need to change this
SETFQDN=`hostname -f`
## the ip of the server, if you resolv.conf is correctly setup.
SETSERVERIP1=`hostname -i`
SETSERVERIP2=`hostname -I`
if [ "${SETSERVERIP1}" = "${SETSERVERIP2}" ]; then
SETSERVERIP="${SETSERVERIP1}"
else
SETSERVERIP="${SETSERVERIP2}"
fi
##################################################################
## DONT CHANGE BELOW Please
check_run_as_sudo_root
SAMBA_DC_FSMO=$(samba-tool fsmo show | cut -d"," -f2 | head -n1 | cut -c4-100)
SAMBA_DC_FSMO_SITE=$(samba-tool fsmo show | cut -d"," -f4 | head -n1 | cut -c4-100)
SAMBA_DC_NC=$(samba-tool fsmo show | cut -d"," -f7,8,9 | head -n1)
## get DC's
DCS=$(host -t SRV _kerberos._udp.${SETDNSDOMAIN} | awk '{print $NF}'| sed 's/.$//')
SAMBA_DC1=$(echo "$DCS" | sed -n 1p)
SAMBA_DC2=$(echo "$DCS" | sed -n 2p)
## get the ip of the DC's
if [ -z "${SAMBA_DC1}" ] && [ -z "${SAMBA_DC2}" ]; then
echo "Could not obtain an ipaddress for any AD DC.. Exiting"
exit 1
fi
if [ -z "${SAMBA_DC2}" ]; then
SAMBA_DC1_IP=$(host -t A ${SAMBA_DC1} | awk '{print $NF}')
SAMBA_DC2_IP=""
else
SAMBA_DC1_IP=$(host -t A ${SAMBA_DC1} | awk '{print $NF}')
SAMBA_DC2_IP=$(host -t A ${SAMBA_DC2} | awk '{print $NF}')
fi
SAMBA_NT_DOMAINNAME=$(samba-tool domain info ${SAMBA_DC1} | grep Netbios | cut -d":" -f2 | cut -c2-100)
SAMBA_KERBEROS_NAME=$(cat /etc/krb5.conf | grep default_realm | cut -d"=" -f2 | cut -c2-100)
#
echo "This script was tested with Debian Jessie."
echo "Server info: detected (command and where to look)"
echo "This server hostname = ${SETHOSTNAME} (hostname -s and /etc/hosts and DNS server)"
echo "This server FQDN (hostname) = ${SETFQDN} (hostname -f and /etc/hosts and DNS server)"
echo "This server primary dnsdomain = ${SETDNSDOMAIN} (hostname -d and /etc/resolv.conf and DNS server)"
echo "This server IP address(ses) = ${SETSERVERIP} (hostname -i (-I) and /etc/networking/interfaces and DNS server"
echo "The DC with FSMO roles = ${SAMBA_DC_FSMO} (samba-tool fsmo show)"
echo "The DC (with FSMO) Site name = ${SAMBA_DC_FSMO_SITE} (samba-tool fsmo show)"
echo "The Default Naming Context = ${SAMBA_DC_NC} (samba-tool fsmo show)"
echo "The Kerberos REALM name used = ${SAMBA_KERBEROS_NAME} (kinit and /etc/krb5.conf and resolving)"
if [ -z "${SAMBA_DC2}" ]; then
SAMBA_DC1_IP=$(host -t A ${SAMBA_DC1} | awk '{print $NF}')
echo "The Ipadres of DC ${SAMBA_DC1} = ${SAMBA_DC1_IP}"
else
SAMBA_DC1_IP=$(host -t A ${SAMBA_DC1} | awk '{print $NF}')
SAMBA_DC2_IP=$(host -t A ${SAMBA_DC2} | awk '{print $NF}')
echo "The Ipadres of DC ${SAMBA_DC1} = ${SAMBA_DC1_IP}"
echo "The Ipadres of DC ${SAMBA_DC2} = ${SAMBA_DC2_IP}"
fi