]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/init.d/net/common/dhcpcd
Farbiger Bash-Prompt.
[ipfire-2.x.git] / src / initscripts / init.d / net / common / dhcpcd
CommitLineData
9c16cd92
MT
1#!/bin/sh
2# Begin $network-devices/services/dhcpcd
3
4# Based upon lfs-bootscripts-1.12 $network_devices/if{down,up}
5# Rewritten by Nathan Coulson <nathan@linuxfromscratch.org>
6# Adapted for dhcpcd by DJ Lucas <dj@lucasit.com>
7# Made compatible for ipfire by Michael Tremer mitch@ipfire.org
8
9. /etc/sysconfig/rc
10. $rc_functions
11
12PIDFILE="/var/run/dhcpcd-$1.pid"
13LEASEINFO="/var/ipfire/dhcpc/dhcpcd-$1.info"
14
15case "$2" in
16 up)
406f019f
MT
17 boot_mesg -n "Starting dhcpcd on the $1 interface..."
18 echo -n "${1}" > /var/ipfire/red/iface
19
9c16cd92
MT
20 # Test to see if there is a stale pid file
21 if [ -f "$PIDFILE" ]
22 then
23 ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
24 if [ $? != 0 ]
25 then
26 rm -f /var/run/dhcpcd-$1.pid > /dev/null
27 else
28 boot_mesg "dhcpcd already running!" ${WARNING}
29 echo_warning
30 exit 2
31 fi
32 fi
9520a3d0
MT
33 if [ "$NAME" == "red" ]; then
34 /sbin/iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${1} -j ACCEPT
35 /sbin/iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${1} -j ACCEPT
36 fi
37
9c16cd92 38 DHCP_START="-N -R -L /var/ipfire/dhcpc "
9520a3d0 39
9c16cd92 40 if [ -n "${DHCP_HOSTNAME}" ]; then
9520a3d0 41 DHCP_START+="-h ${DHCP_HOSTNAME} "
9c16cd92 42 fi
406f019f 43 /sbin/dhcpcd $1 $DHCP_START >/dev/null 2>&1
9c16cd92
MT
44 # Save the return value
45 RET="$?"
46 # Print the assigned settings if requested
47 if [ "$RET" = "0" -a "$PRINTIP" = "yes" ]; then
48 . /var/ipfire/dhcpc/dhcpcd-$1.info
406f019f 49 logger -t ipfire "DHCPCD Success"
9c16cd92
MT
50 if [ "$PRINTALL" = "yes" ]; then
51 echo ""
52 echo_ok
53 boot_mesg " DHCP Assigned Settings for $1:"
54 boot_mesg_flush
55 boot_mesg " IP Address: $IPADDR"
56 boot_mesg_flush
57 if [ -n "${DHCP_HOSTNAME}" ]; then
58 boot_mesg " Hostname: $DHCP_HOSTNAME"
59 boot_mesg_flush
60 fi
61 boot_mesg " Subnet Mask: $NETMASK"
62 boot_mesg_flush
63 boot_mesg " Default Gateway: $GATEWAY"
64 boot_mesg_flush
65 boot_mesg " DNS Server: $DNS"
66 boot_mesg_flush
67 else
68 boot_mesg " IP Addresss: ""$IPADDR"
69 echo_ok
70 fi
71 else
72 echo ""
406f019f 73 logger -t ipfire "DHCPCD Fail"
9c16cd92
MT
74 $(exit "$RET")
75 evaluate_retval
76 fi
77 ;;
78
79 down)
80 boot_mesg -n "Stopping dhcpcd on the $1 interface..."
81 # Do nothing with the client daemon if we have an infinate
82 # lease time as the client exits when started in this case,
83 # just echo OK.
84 DHCP_STOP="-k"
85 if [ -e $LEASEINFO ]
86 then
87 . $LEASEINFO
88
89 if [ "$LEASETIME" = "4294967295" ]
90 then
91 # do nothing, just echo ok
92 echo ""
93 echo_ok
94 else
95 if [ -n "$DHCP_STOP" ]
96 then
97 /sbin/dhcpcd $1 $DHCP_STOP &> /dev/null
98 RET="$?"
99 if [ "$RET" -eq 0 ]; then
100 echo ""
101 echo_ok
102 elif [ "$RET" -eq 1 ]; then
103 boot_mesg "dhcpcd not running!" ${WARNING}
104 echo_warning
105 else
106 echo ""
107 echo_failure
108 fi
109 else
110 echo ""
111 killproc dhcpcd
112 fi
113 fi
114 else
115 boot_mesg -n "LEASEINFO Test failed! - " ${WARNING}
116 boot_mesg "dhcpcd is not running!" ${WARNING}
117 echo_warning
118 exit 1
119 fi
120 ;;
121
122 *)
123 echo "Usage: $0 [interface] {up|down}"
124 exit 1
125 ;;
126esac
127
128# End $network_devices/services/dhcpcd