nettle: Add new crypto library.
[ipfire-2.x.git] / src / initscripts / init.d / dnsmasq
CommitLineData
d1e90efc
MT
1#!/bin/sh
2########################################################################
3# Begin $rc_base/init.d/dnsmasq
4#
5# Description : dnsmasq init script
6#
7# Authors : Michael Tremer - mitch@ipfire.org
8#
9# Version : 01.00
10#
11# Notes :
12#
13########################################################################
14
15. /etc/sysconfig/rc
16. ${rc_functions}
17
16a61778
MT
18# Pull custom configuration file
19if [ -e "/etc/sysconfig/dnsmasq" ]; then
20 . /etc/sysconfig/dnsmasq
21fi
22
f480386f
MT
23SHOW_SRV=1
24
e4ba53ed
SS
25function dns_forward_args() {
26 local file="${1}"
27
28 # Do nothing if file is empty.
29 [ -s "${file}" ] || return
30
31 local cmdline
32
33 local enabled zone server remark
34 while IFS="," read -r enabled zone server remark; do
35 # Line must be enabled.
36 [ "${enabled}" = "on" ] || continue
37
38 cmdline="${cmdline} --server=/${zone}/${server}"
39 done < ${file}
40
41 echo "${cmdline}"
42}
43
44
d1e90efc
MT
45case "${1}" in
46 start)
fcfd54ba
AF
47 # kill already running copy of dnsmasq...
48 killproc /usr/sbin/dnsmasq 2>&1 > /dev/null
49
d1e90efc
MT
50 boot_mesg "Starting Domain Name Service Proxy..."
51
52 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
2340d265 53 ARGS="$CUSTOM_ARGS"
2b1ff411 54 [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="$ARGS -s $DOMAIN_NAME_GREEN"
f480386f
MT
55
56 echo > /var/ipfire/red/resolv.conf # Clear it
57 if [ -e "/var/ipfire/red/dns1" ]; then
58 DNS1=$(cat /var/ipfire/red/dns1 2>/dev/null)
2789f357
AF
59 if [ ! -z ${DNS1} ]; then
60 echo "nameserver ${DNS1}" >> /var/ipfire/red/resolv.conf
61 fi
f480386f
MT
62 fi
63 if [ -e "/var/ipfire/red/dns2" ]; then
64 DNS2=$(cat /var/ipfire/red/dns2 2>/dev/null)
2789f357
AF
65 if [ ! -z ${DNS2} ]; then
66 echo "nameserver ${DNS2}" >> /var/ipfire/red/resolv.conf
67 fi
f480386f
MT
68 fi
69 [ -e "/var/ipfire/red/active" ] && ARGS="$ARGS -r /var/ipfire/red/resolv.conf"
e4ba53ed 70
63aceb22 71 ARGS="$ARGS --domain=`cat /var/ipfire/main/settings |grep DOMAIN |cut -d = -f 2`"
e4ba53ed
SS
72
73 # Add custom forward dns zones.
74 ARGS="${ARGS} $(dns_forward_args /var/ipfire/dnsforward/config)"
75
d1e90efc 76 loadproc /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS
f480386f
MT
77
78 if [ "${SHOW_SRV}" -eq 1 ] && [ "${DNS1}" != "" -o "${DNS2}" != "" ]; then
79 boot_mesg "Using DNS server(s): ${DNS1} ${DNS2}"
80 boot_mesg_flush
81 fi
d1e90efc
MT
82 ;;
83
84 stop)
85 boot_mesg "Stopping Domain Name Service Proxy..."
86 killproc /usr/sbin/dnsmasq
87 ;;
88
89 restart)
90 ${0} stop
91 sleep 1
92 ${0} start
93 ;;
94
95 status)
96 statusproc /usr/sbin/dnsmasq
97 ;;
98
99 *)
100 echo "Usage: ${0} {start|stop|restart|status}"
101 exit 1
102 ;;
103esac
104
105# End $rc_base/init.d/dnsmasq