File: functions

package info (click to toggle)
rinetd 0.73-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 740 kB
  • sloc: ansic: 3,091; sh: 152; makefile: 28
file content (75 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download
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
# -*- shell-script -*-

FUNCTIONS_DIR="debian/tests/functions.d"

match_or_exit () {
	file_to_match="$1"
	pattern_file="$2"

	while read line_to_match <&3 && read pattern_line <&4 ; do
		if [ "${line_to_match##$pattern_line}" ]; then
			echo '!!! MISMATCH !!!' >&2
			echo "Line:    ${line_to_match}" >&2
			echo "Pattern: ${pattern_line}" >&2
			exit 1
		fi;
	done 3<"${file_to_match}" 4<"${pattern_file}"
}

linecount () {
	wc -l $1 | cut -d' ' -f1
}

error_exit () {
	echo "ERROR: $1"
	exit 1
}

stop_bind_networking () {
	systemctl stop named.service
	systemctl stop networking.service
}

configure_and_start_networking () {
	cat ${FUNCTIONS_DIR}/add-to.interfaces >> /etc/network/interfaces
	systemctl start networking.service
}

configure_and_start_bind () {
	cp ${FUNCTIONS_DIR}/db.autopkg.test /etc/bind/
	cat ${FUNCTIONS_DIR}/add-to.named.conf.local >> /etc/bind/named.conf.local
	cp ${FUNCTIONS_DIR}/named.conf.options /etc/bind/named.conf.options
	systemctl start named.service
}

configure_and_restart_rinetd() {
	cp ${FUNCTIONS_DIR}/rinetd.conf /etc
	systemctl restart rinetd.service
}

query_test_zone_records_and_check_the_result () {
	local server port option
	server=$1
	port=$2
	option=$3
	echo ~~~ Query $server/$port/$option for test zone records and check the result...
	dig @$server -p$port +$option +short SOA autopkg.test >dig.out 2>&1
	dig @$server -p$port +$option +short NS autopkg.test >>dig.out 2>&1
	dig @$server -p$port +$option +short A ns.autopkg.test >>dig.out 2>&1
	dig @$server -p$port +$option +short A dhcp3.autopkg.test >>dig.out 2>&1
	cat dig.out
	if [ `linecount dig.out` -ne `linecount ${FUNCTIONS_DIR}/dig.patterns` ] ; then
		error_exit 'empty or unexpected output'
	fi
	match_or_exit dig.out ${FUNCTIONS_DIR}/dig.patterns
}

dump_logfile () {
    local logfile
	logfile=`head -n1 /etc/rinetd.conf | grep -o '/.*'`
	echo ~~~ Dump $logfile
	if [ ! -e $logfile ]; then
		error_exit "logfile '$logfile' is missing"
	fi
	cat $logfile
}