source: systemd-units/blfs/services/dhclient@ be67218

systemd-11177
Last change on this file since be67218 was be67218, checked in by Krejzi <krejzi@…>, 10 years ago

Merge more Christopher's work. Import systemd units.

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/branches/systemd@13507 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 3.1 KB
Line 
1#!/bin/sh
2# Begin services/dhclient
3
4# Origianlly based upon lfs-bootscripts-1.12 $NETWORK_DEVICES/if{down,up}
5# Rewritten by Nathan Coulson <nathan@linuxfromscratch.org>
6# Adapted for dhclient by DJ Lucas <dj@linuxfromscratch.org>
7# Update for LFS 7.0 by Ken Moffat <ken@linuxfromscratch.org>
8
9# Call with: IFCONFIG=<filename> /lib/services/dhclient <IFACE> <up | down>
10
11#$LastChangedBy: krejzi $
12#$Date: 2013-02-11 17:22:35 +0100 (Mon, 11 Feb 2013) $
13
14. /lib/lsb/init-functions
15. $IFCONFIG
16
17PIDFILE=/run/dhclient-$1.pid
18LFILE=/var/lib/dhclient/dhclient-$1.leases
19
20getipstats()
21{
22 # Print the last 16 lines of dhclient.leases
23 sed -e :a -e '$q;N;17,$D;ba' ${LFILE}
24}
25
26# Make compatible with older versions of init-functions
27unset is_true
28
29is_true()
30{
31 [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] ||
32 [ "$1" = "y" ] || [ "$1" = "t" ]
33}
34
35case "$2" in
36 up)
37
38 if [ -e ${PIDFILE} ]; then
39 ps $(cat ${PIDFILE}) | grep dhclient >/dev/null
40 if [ "$?" = "0" ]; then
41 log_warning_msg "\n dhclient appears to be running on $1"
42 exit 0
43 else
44 rm ${PIDFILE}
45 fi
46 fi
47
48 log_info_msg "\n Starting dhclient on the $1 interface..."
49
50 /sbin/dhclient -lf ${LFILE} -pf ${PIDFILE} $DHCP_START $1
51
52 if [ "$?" != "0" ]; then
53 log_failure_msg2
54 exit 1
55 fi
56
57 # Print the assigned settings if requested
58 if is_true "$PRINTIP" -o is_true "$PRINTALL"; then
59 # Get info from dhclient.leases file
60
61 IPADDR=`getipstats | grep "fixed-address" | \
62 sed 's/ fixed-address //' | \
63 sed 's/\;//'`
64
65 NETMASK=`getipstats | grep "subnet-mask" | \
66 sed 's/ option subnet-mask //' | \
67 sed 's/\;//'`
68
69 GATEWAY=`getipstats | grep "routers" | \
70 sed 's/ option routers //' | \
71 sed 's/\;//'`
72
73 DNS=`getipstats | grep "domain-name-servers" | \
74 sed 's/ option domain-name-servers //' | \
75 sed 's/\;//' | sed 's/,/ and /'`
76
77 if [ "$PRINTALL" = "yes" ]; then
78 # This is messy, the messages are on one very long
79 # line on the screen and in the log
80 log_info_msg " DHCP Assigned Settings for $1:"
81 log_info_msg " IP Address: $IPADDR"
82 log_info_msg " Subnet Mask: $NETMASK"
83 log_info_msg " Default Gateway: $GATEWAY"
84 log_info_msg " DNS Server: $DNS"
85 else
86 log_info_msg " IP Addresss:""$IPADDR"
87 fi
88 fi
89
90 log_success_msg2
91 ;;
92
93 down)
94 if [ ! -e ${PIDFILE} ]; then
95 log_warning_msg "\n dhclient doesn't appear to be running on $1"
96 exit 0
97 fi
98
99 log_info_msg "\n Stopping dhclient on the $1 interface..."
100
101 /sbin/dhclient -r -lf ${LFILE} -pf ${PIDFILE} $DHCP_STOP $1
102
103 ps $(cat ${PIDFILE}) | grep dhclient >/dev/null
104 if [ "$?" != "0" ]; then
105 rm -f ${PIDFILE}
106 fi
107
108 evaluate_retval
109 ;;
110
111 *)
112 echo "Usage: $0 [interface] {up|down}"
113 exit 1
114 ;;
115esac
116
117# End services/dhclient
Note: See TracBrowser for help on using the repository browser.