From b3b9c8adf8307223000986f0ad83452d993708aa Mon Sep 17 00:00:00 2001 From: B Stack Date: Sun, 28 May 2017 21:37:53 -0400 Subject: starting to add dhcpd-control --- etc/sysconfig/dhcpd-control | 5 + etc/updatezone/dhcpd-control.conf | 1 + usr/share/updatezone/dhcpd-control.sh | 300 ++++++++++++++++++++++++++++++ usr/share/updatezone/docs/updatezone.spec | 2 +- 4 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 etc/sysconfig/dhcpd-control create mode 100644 etc/updatezone/dhcpd-control.conf create mode 100755 usr/share/updatezone/dhcpd-control.sh diff --git a/etc/sysconfig/dhcpd-control b/etc/sysconfig/dhcpd-control new file mode 100644 index 0000000..3073169 --- /dev/null +++ b/etc/sysconfig/dhcpd-control @@ -0,0 +1,5 @@ +DHCPD_CONTROL_COMBINED_FILE=/etc/dhcp/dhcpd.combined.conf +DHCPD_CONTROL_DHCPD_FILE=/etc/dhcp/dhcpd.conf +DHCPD_CONTROL_LEASES_FILE=/var/lib/dhcpd/dhcpd.leases +DHCPD_CONTROL_LEASES_TEMP_FILE=/var/lib/dhcpd/dhcpd.leases~ +DHCPD_CONTROL_SERVICE=dhcpd diff --git a/etc/updatezone/dhcpd-control.conf b/etc/updatezone/dhcpd-control.conf new file mode 100644 index 0000000..ef8bc52 --- /dev/null +++ b/etc/updatezone/dhcpd-control.conf @@ -0,0 +1 @@ +[dhcpd-control] diff --git a/usr/share/updatezone/dhcpd-control.sh b/usr/share/updatezone/dhcpd-control.sh new file mode 100755 index 0000000..a334a93 --- /dev/null +++ b/usr/share/updatezone/dhcpd-control.sh @@ -0,0 +1,300 @@ +#!/bin/sh +# Filename: dhcpd-control.sh +# Location: +# Author: bgstack15@gmail.com +# Startdate: 2017-05-28 18:18:46 +# Title: Script that Facilitates the Configuration of DHCPD +# Purpose: +# Package: +# History: +# Usage: +# Reference: ftemplate.sh 2017-05-24a; framework.sh 2017-05-24a +# Improve: +fiversion="2017-05-24a" +dhcpdcontrolversion="2017-05-28a" + +usage() { + less -F >&2 < ] [ --force ] +version ${dhcpdcontrolversion} + -d debug Show debugging info, including parsed variables. + -u usage Show this usage block. + -V version Show script version number. + --flush Clears all current leases + --edit Edit the combined file-- the one shared by both servers. + --edit-local Edit the local file. + --remove-mac Clears the leases for this MAC address. +Return values: +0 Normal +1 Help or version info displayed +2 Count or type of flaglessvals is incorrect +3 Incorrect OS type +4 Unable to find dependency +5 Not run as root or sudo +ENDUSAGE +} + +# DEFINE FUNCTIONS + +# DEFINE TRAPS + +clean_dhcpdcontrol() { + #rm -f ${logfile} > /dev/null 2>&1 + [ ] #use at end of entire script if you need to clean up tmpfiles +} + +CTRLC() { + #trap "CTRLC" 2 + [ ] #useful for controlling the ctrl+c keystroke +} + +CTRLZ() { + #trap "CTRLZ" 18 + [ ] #useful for controlling the ctrl+z keystroke +} + +parseFlag() { + flag="$1" + hasval=0 + case ${flag} in + # INSERT FLAGS HERE + "d" | "debug" | "DEBUG" | "dd" ) setdebug; ferror "debug level ${debug}";; + "u" | "usage" | "help" | "h" ) usage; exit 1;; + "V" | "fcheck" | "version" ) ferror "${scriptfile} version ${dhcpdcontrolversion}"; exit 1;; + #"i" | "infile" | "inputfile" ) getval;infile1=${tempval};; + "f" | "force" ) DHCPD_CONTROL_FORCE=1;; + "flush" ) action="flush";; + "edit-local" ) action="edit-local";; + "edit" ) action="edit";; + "remove-mac" ) getval; DHCPD_CONTROL_MAC_TO_REMOVE="${tempval}";; + esac + + debuglev 10 && { test ${hasval} -eq 1 && ferror "flag: ${flag} = ${tempval}" || ferror "flag: ${flag}"; } +} + +# DETERMINE LOCATION OF FRAMEWORK +while read flocation; do if test -x ${flocation} && test "$( ${flocation} --fcheck )" -ge 20170524; then frameworkscript="${flocation}"; break; fi; done <&2 && exit 4 + +# INITIALIZE VARIABLES +# variables set in framework: +# today server thistty scriptdir scriptfile scripttrim +# is_cronjob stdin_piped stdout_piped stderr_piped sendsh sendopts +. ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2 +infile1= +outfile1= +logfile=${scriptdir}/${scripttrim}.${today}.out +action="" +define_if_new interestedparties "bgstack15@gmail.com" +# SIMPLECONF +#define_if_new default_conffile "/etc/sysconfig/dhcpd-control" +define_if_new default_conffile "/home/bgirton/rpmbuild/SOURCES/updatezone-0.0-2/etc/sysconfig/dhcpd-control" +#define_if_new defuser_conffile ~/.config/dhcpdcontrol/dhcpdcontrol.conf +define_if_new EDITOR vi + +# REACT TO OPERATING SYSTEM TYPE +case $( uname -s ) in + Linux) [ ];; + FreeBSD) [ ];; + *) echo "${scriptfile}: 3. Indeterminate OS: $( uname -s )" 1>&2 && exit 3;; +esac + +## REACT TO ROOT STATUS +#case ${is_root} in +# 1) # proper root +# [ ] ;; +# sudo) # sudo to root +# [ ] ;; +# "") # not root at all +# #ferror "${scriptfile}: 5. Please run as root or sudo. Aborted." +# #exit 5 +# [ ] +# ;; +#esac + +# SET CUSTOM SCRIPT AND VALUES +#setval 1 sendsh sendopts<&2 + } + + please_update_other_server_conf=0 + please_update_other_server_leases=0 + please_update_other_server_service=0 + # WORKHERE: add local service, other_server_service + case "${action}" in + + "flush") + # Clear temorary leases file + debuglev 4 && ferror "Flushing all leases" + if test -z "${DHCPD_CONTROL_LEASES_TEMP_FILE}"; + then + ferror "Skipping leases temp file. Variable not defined: DHCPD_CONTROL_LEASES_TEMP_FILE." + else + if test -f "${DHCPD_CONTROL_LEASES_TEMP_FILE}"; + then + case "${DHCPD_CONTROL_LEASES_TEMP_FILE}" in + /var/lib/dhcp*) + rm -f "${DHCPD_CONTROL_LEASES_TEMP_FILE}" + please_update_other_server_conf=1 + ;; + *) + ferror "Will not delete unsafe leases temp file ${DHCPD_CONTROL_LEASES_TEMP_FILE}." + ;; + esac + fi + fi + # Clear leases file + if test -z "${DHCPD_CONTROL_LEASES_FILE}"; + then + ferror "Skipping leases file. Variable not defined: DHCPD_CONTROL_LEASES_FILE." + else + if test -f "${DHCPD_CONTROL_LEASES_FILE}"; + then + case "${DHCPD_CONTROL_LEASES_FILE}" in + /var/lib/dhcp*) + printf "" > "${DHCPD_CONTROL_LEASES_FILE}" + please_update_other_server_conf=1 + ;; + *) + ferror "Will not clear unsafe leases file ${DHCPD_CONTROL_LEASES_FILE}." + ;; + esac + fi + fi + ;; + esac + + # Update other server if necessary + if fistruthy "${please_update_other_server}"; + then + if test -n "${DHCPD_CONTROL_OTHER_SERVER}"; + then + echo "please notify other server ${DHCPD_CONTROL_OTHER_SERVER}" + fi + fi + +#} | tee -a ${logfile} + +# EMAIL LOGFILE +#${sendsh} ${sendopts} "${server} ${scriptfile} out" ${logfile} ${interestedparties} + +## STOP THE READ CONFIG FILE +#exit 0 +#fi; done; } diff --git a/usr/share/updatezone/docs/updatezone.spec b/usr/share/updatezone/docs/updatezone.spec index bbab362..d08942e 100644 --- a/usr/share/updatezone/docs/updatezone.spec +++ b/usr/share/updatezone/docs/updatezone.spec @@ -2,7 +2,7 @@ Summary: update dns zone files easily Name: updatezone Version: 0.0 -Release: 1 +Release: 2 License: CC BY-SA 4.0 Group: Applications/System Source: updatezone.tgz -- cgit