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