]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/networking/dhcpcd.exe
Remove newline from ip-address files if red=dhcp.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / networking / dhcpcd.exe
1 ########################################################################
2 # Begin
3 #
4 # Description : DHCP Client Script
5 #
6 # Authors : Arne Fitzenreiter - arne_f@ipfire.org
7 #
8 # Version : 02.00
9 #
10 # Notes :
11 #
12 ########################################################################
13
14 . /etc/sysconfig/rc
15 . $rc_functions
16
17
18 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
19 eval $(/usr/local/bin/readhash /var/ipfire/dns/settings)
20
21 dhcpcd_up()
22 {
23 set | grep "^new_" | sed "s|^new_||g" | \
24 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
25
26 # Only if RED_TYPE=DHCP update /var/ipfire/red
27 if [ "$RED_TYPE" == "DHCP" ]; then
28
29 #Check if we have to restart the services at update
30 [ ! -e "/var/ipfire/red/active" ] update=1;
31 if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then
32 update=1;
33 fi
34 if [ "$old_ip_address" != "$new_ip_address" ]; then
35 update=1;
36 fi
37 if [ "$old_routers" != "$new_routers" ]; then
38 update=1;
39 fi
40
41 #Get DNS from dhcp
42 if [ -n "$DNS0" ] && [ -n "$DNS1" ]; then
43 logger -p local0.info -t dhcpcd.exe[$$] "Overwritting DNS-Server addresses with ${DNS0},${DNS1}"
44 echo -n ${DNS0} > /var/ipfire/red/dns1
45 echo -n ${DNS1} > /var/ipfire/red/dns2
46 else
47 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1
48 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2
49 fi
50
51 #Get IP Address
52 echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress
53
54 #Get default gateway
55 grep -v " gateway$" /etc/hosts > /tmp/hosts
56 echo "$new_routers gateway" >> /tmp/hosts
57 mv /tmp/hosts /etc/hosts
58
59 fi
60 if [ $update ]; then
61 [ -e "/var/ipfire/red/active" ] || touch /var/ipfire/red/active
62 echo -n "$new_routers" > /var/ipfire/red/remote-ipaddress
63 logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address"
64 run_subdir ${rc_base}/init.d/networking/red.up/
65 touch /var/ipfire/red/active
66 fi
67 }
68
69 dhcpcd_down()
70 {
71 set | grep "^new_" | sed "s|^new_||g" | \
72 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
73
74 # Only if RED_TYPE=DHCP update /var/ipfire/red
75 if [ "$RED_TYPE" == "DHCP" ]; then
76 logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down"
77 rm -f /var/ipfire/red/active
78 run_subdir ${rc_base}/init.d/networking/red.down/
79 fi
80 }
81
82 case "$reason" in
83 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) dhcpcd_up;;
84 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) dhcpcd_down;;
85 esac