]> git.ipfire.org Git - people/stevee/network.git/blame - functions.dhclient
Add basic support as a DHCP client.
[people/stevee/network.git] / functions.dhclient
CommitLineData
e9ea243e
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 IPFire Network Development Team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22dhclient_start() {
23 local interface=${1}
24 local proto=${2}
25
26 assert isset interface
27 assert device_exists ${interface}
28
29 local service=$(dhclient_proto2service ${proto})
30 assert isset service
31
32 service_start "${service}@${interface}"
33}
34
35dhclient_stop() {
36 local interface=${1}
37 local proto=${2}
38
39 local service=$(dhclient_proto2service ${proto})
40 assert isset service
41
42 service_stop "${service}@${interface}"
43}
44
45dhclient_proto2service() {
46 local proto=${1}
47 assert isset proto
48
49 local service
50
51 case "${proto}" in
52 ipv4)
53 service="dhclient4"
54 ;;
55 ipv6)
56 service="dhclient6"
57 ;;
58 *)
59 return ${EXIT_ERROR}
60 ;;
61 esac
62
63 assert isset service
64
65 echo "${service}"
66 return ${EXIT_OK}
67}
68
69dhclient_write_config() {
70 local interface=${1}
71 local file=${2}
72 shift 2
73
74 assert isset interface
75 assert isset file
76
77 local hostname=${HOSTNAME%%.*}
78 local vendor=$(distro_get_pretty_name)
79
80 while [ $# -gt 0 ]; do
81 case "${1}" in
82 --hostname=*)
83 hostname=$(cli_get_val ${1})
84 ;;
85 --vendor=*)
86 vendor=$(cli_get_val ${1})
87 ;;
88 *)
89 log WARNING $"Unknown configuration option passed: ${1}."
90 ;;
91 esac
92 shift
93 done
94
95 # Clear configuration file (if any).
96 mkdir -p $(dirname ${file}) 2>/dev/null
97 : > ${file}
98
99 # Print the header.
100 ( echo "#"
101 echo "# This is a dhclient daemon configuration file for ${interface}."
102 echo "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE"
103 echo "# ANY CUSTOM CHANGES!"
104 echo "#"
105 echo "# $(date -u)"
106 echo "#"
107 echo
108 ) >>${file}
109
110 # Global options.
111 echo "send vendor-class-identifier \"${vendor}\";" >>${file}
112 echo
113
114 # Interface options.
115 (
116 echo "interface \"${interface}\" {"
117
118 if isset hostname; then
119 echo " send host-name \"${hostname}\";"
120 fi
121
122 echo "}"
123 ) >>${file}
124
125 return ${EXIT_OK}
126}