]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | PIDFILE="/var/run/dhcpcd-$1.pid" | |
13 | LEASEINFO="/var/ipfire/dhcpc/dhcpcd-$1.info" | |
14 | ||
15 | case "$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 | |
33 | /sbin/iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${1} -j ACCEPT | |
34 | /sbin/iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${1} -j ACCEPT | |
35 | DHCP_START="-N -R -L /var/ipfire/dhcpc " | |
36 | if [ -n "${DHCP_HOSTNAME}" ]; then | |
37 | DHCP_START+="-h ${DHCP_HOSTNAME}" | |
38 | fi | |
406f019f | 39 | /sbin/dhcpcd $1 $DHCP_START >/dev/null 2>&1 |
9c16cd92 MT |
40 | # Save the return value |
41 | RET="$?" | |
42 | # Print the assigned settings if requested | |
43 | if [ "$RET" = "0" -a "$PRINTIP" = "yes" ]; then | |
44 | . /var/ipfire/dhcpc/dhcpcd-$1.info | |
406f019f | 45 | logger -t ipfire "DHCPCD Success" |
9c16cd92 MT |
46 | if [ "$PRINTALL" = "yes" ]; then |
47 | echo "" | |
48 | echo_ok | |
49 | boot_mesg " DHCP Assigned Settings for $1:" | |
50 | boot_mesg_flush | |
51 | boot_mesg " IP Address: $IPADDR" | |
52 | boot_mesg_flush | |
53 | if [ -n "${DHCP_HOSTNAME}" ]; then | |
54 | boot_mesg " Hostname: $DHCP_HOSTNAME" | |
55 | boot_mesg_flush | |
56 | fi | |
57 | boot_mesg " Subnet Mask: $NETMASK" | |
58 | boot_mesg_flush | |
59 | boot_mesg " Default Gateway: $GATEWAY" | |
60 | boot_mesg_flush | |
61 | boot_mesg " DNS Server: $DNS" | |
62 | boot_mesg_flush | |
63 | else | |
64 | boot_mesg " IP Addresss: ""$IPADDR" | |
65 | echo_ok | |
66 | fi | |
67 | else | |
68 | echo "" | |
406f019f | 69 | logger -t ipfire "DHCPCD Fail" |
9c16cd92 MT |
70 | $(exit "$RET") |
71 | evaluate_retval | |
72 | fi | |
73 | ;; | |
74 | ||
75 | down) | |
76 | boot_mesg -n "Stopping dhcpcd on the $1 interface..." | |
77 | # Do nothing with the client daemon if we have an infinate | |
78 | # lease time as the client exits when started in this case, | |
79 | # just echo OK. | |
80 | DHCP_STOP="-k" | |
81 | if [ -e $LEASEINFO ] | |
82 | then | |
83 | . $LEASEINFO | |
84 | ||
85 | if [ "$LEASETIME" = "4294967295" ] | |
86 | then | |
87 | # do nothing, just echo ok | |
88 | echo "" | |
89 | echo_ok | |
90 | else | |
91 | if [ -n "$DHCP_STOP" ] | |
92 | then | |
93 | /sbin/dhcpcd $1 $DHCP_STOP &> /dev/null | |
94 | RET="$?" | |
95 | if [ "$RET" -eq 0 ]; then | |
96 | echo "" | |
97 | echo_ok | |
98 | elif [ "$RET" -eq 1 ]; then | |
99 | boot_mesg "dhcpcd not running!" ${WARNING} | |
100 | echo_warning | |
101 | else | |
102 | echo "" | |
103 | echo_failure | |
104 | fi | |
105 | else | |
106 | echo "" | |
107 | killproc dhcpcd | |
108 | fi | |
109 | fi | |
110 | else | |
111 | boot_mesg -n "LEASEINFO Test failed! - " ${WARNING} | |
112 | boot_mesg "dhcpcd is not running!" ${WARNING} | |
113 | echo_warning | |
114 | exit 1 | |
115 | fi | |
116 | ;; | |
117 | ||
118 | *) | |
119 | echo "Usage: $0 [interface] {up|down}" | |
120 | exit 1 | |
121 | ;; | |
122 | esac | |
123 | ||
124 | # End $network_devices/services/dhcpcd |