#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2012 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### dhclient_start() { local interface=${1} local proto=${2} assert isset interface assert device_exists ${interface} local service=$(dhclient_proto2service ${proto} ${interface}) service_start ${service} } dhclient_stop() { local interface=${1} local proto=${2} local service=$(dhclient_proto2service ${proto} ${interface}) service_stop ${service} } dhclient_status() { local interface=${1} local proto=${2} local service=$(dhclient_proto2service ${proto} ${interface}) service_status ${service} } dhclient_proto2service() { local proto=${1} assert isset proto local interface=${2} assert isset interface local service case "${proto}" in ipv4) service="dhclient4@${interface}.service" ;; ipv6) service="dhclient6@${interface}.service" ;; *) return ${EXIT_ERROR} ;; esac assert isset service echo "${service}" return ${EXIT_OK} } dhclient_write_config() { local interface=${1} local file=${2} shift 2 assert isset interface assert isset file local hostname=${HOSTNAME%%.*} local vendor=$(distro_get_pretty_name) while [ $# -gt 0 ]; do case "${1}" in --hostname=*) hostname=$(cli_get_val ${1}) ;; --vendor=*) vendor=$(cli_get_val ${1}) ;; *) log WARNING $"Unknown configuration option passed: ${1}." ;; esac shift done # Clear configuration file (if any). mkdir -p $(dirname ${file}) 2>/dev/null : > ${file} # Print the header. ( echo "#" echo "# This is a dhclient daemon configuration file for ${interface}." echo "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE" echo "# ANY CUSTOM CHANGES!" echo "#" echo "# $(date -u)" echo "#" echo ) >>${file} # Global options. echo "send vendor-class-identifier \"${vendor}\";" >>${file} echo # Interface options. ( echo "interface \"${interface}\" {" if isset hostname; then echo " send host-name \"${hostname}\";" fi echo "}" ) >>${file} return ${EXIT_OK} }