summaryrefslogtreecommitdiff
path: root/bin/itzks-hosts
blob: ee1ade5e647d0897b81d2bed529f4fe453f34692 (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
#!/bin/bash

set -e

if [ -x "/usr/share/debian-edu-config/list-gosa-systems" ]; then
	/usr/share/debian-edu-config/list-gosa-systems ${@}
else

	# FIXME: drop this part for the bookworm release cycle...

	ldapsearch -xLLL "(&(cn=*)(|(objectClass=ipHost)(objectClass=goServer)))" \
	    cn ipHostNumber macAddress description 2>/dev/null | perl -p0e 's/\n //g' | \
	while read KEY VALUE ; do
		case "$KEY" in
			dn:)
				HOSTNAME= ; IP= ; MAC= ; DESC= ; DN=${VALUE}
				OU=$(echo $DN | sed -r -e 's/cn=[^,]+,ou=[^,]+,ou=[^,]+,ou=([^,]+),.*/\1/' | sed -r -e 's/cn=[^,]+,ou=[^,]+,ou=[^,]+,dc=.*/Servers/g')
			;;
			cn:) HOSTNAME="${VALUE}";;
			ipHostNumber:) IP="${VALUE}";;
			macAddress:) MAC="${VALUE}";;
			description:) DESC="${VALUE}";;
			"")
				if [ -n "$DESC" ]; then DESC="\"${DESC}\""; fi
				echo "${OU},${HOSTNAME},${IP},${MAC},${DESC}"
			;;
		esac
	done
fi

exit 0