]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | dhclient_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 | ||
35 | dhclient_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 | ||
45 | dhclient_status() { | |
46 | local interface=${1} | |
47 | local proto=${2} | |
48 | ||
49 | local service=$(dhclient_proto2service ${proto}) | |
50 | assert isset service | |
51 | ||
52 | service_status "${service}@${interface}" | |
53 | } | |
54 | ||
55 | dhclient_proto2service() { | |
56 | local proto=${1} | |
57 | assert isset proto | |
58 | ||
59 | local service | |
60 | ||
61 | case "${proto}" in | |
62 | ipv4) | |
63 | service="dhclient4" | |
64 | ;; | |
65 | ipv6) | |
66 | service="dhclient6" | |
67 | ;; | |
68 | *) | |
69 | return ${EXIT_ERROR} | |
70 | ;; | |
71 | esac | |
72 | ||
73 | assert isset service | |
74 | ||
75 | echo "${service}" | |
76 | return ${EXIT_OK} | |
77 | } | |
78 | ||
79 | dhclient_write_config() { | |
80 | local interface=${1} | |
81 | local file=${2} | |
82 | shift 2 | |
83 | ||
84 | assert isset interface | |
85 | assert isset file | |
86 | ||
87 | local hostname=${HOSTNAME%%.*} | |
88 | local vendor=$(distro_get_pretty_name) | |
89 | ||
90 | while [ $# -gt 0 ]; do | |
91 | case "${1}" in | |
92 | --hostname=*) | |
93 | hostname=$(cli_get_val ${1}) | |
94 | ;; | |
95 | --vendor=*) | |
96 | vendor=$(cli_get_val ${1}) | |
97 | ;; | |
98 | *) | |
99 | log WARNING $"Unknown configuration option passed: ${1}." | |
100 | ;; | |
101 | esac | |
102 | shift | |
103 | done | |
104 | ||
105 | # Clear configuration file (if any). | |
106 | mkdir -p $(dirname ${file}) 2>/dev/null | |
107 | : > ${file} | |
108 | ||
109 | # Print the header. | |
110 | ( echo "#" | |
111 | echo "# This is a dhclient daemon configuration file for ${interface}." | |
112 | echo "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE" | |
113 | echo "# ANY CUSTOM CHANGES!" | |
114 | echo "#" | |
115 | echo "# $(date -u)" | |
116 | echo "#" | |
117 | echo | |
118 | ) >>${file} | |
119 | ||
120 | # Global options. | |
121 | echo "send vendor-class-identifier \"${vendor}\";" >>${file} | |
122 | echo | |
123 | ||
124 | # Interface options. | |
125 | ( | |
126 | echo "interface \"${interface}\" {" | |
127 | ||
128 | if isset hostname; then | |
129 | echo " send host-name \"${hostname}\";" | |
130 | fi | |
131 | ||
132 | echo "}" | |
133 | ) >>${file} | |
134 | ||
135 | return ${EXIT_OK} | |
136 | } |