From a9b7fff4f3f88d6f1cb7e980e5f83d9956dcc010 Mon Sep 17 00:00:00 2001 From: B Stack Date: Mon, 29 May 2017 06:34:41 -0400 Subject: renamed package to ddtools --- usr/bin/dhcpd-control | 1 + usr/bin/updatezone | 2 +- usr/share/ddtools/dhcpd-control.sh | 300 +++++++++++++++++ usr/share/ddtools/docs/README.txt | 48 +++ usr/share/ddtools/docs/ddtools.spec | 60 ++++ usr/share/ddtools/docs/files-for-versioning.txt | 3 + .../ddtools/examples/ipa.smith122.com.conf.example | 7 + usr/share/ddtools/inc/get-files | 40 +++ usr/share/ddtools/inc/pack | 116 +++++++ usr/share/ddtools/updatezone.sh | 371 +++++++++++++++++++++ usr/share/updatezone/dhcpd-control.sh | 300 ----------------- usr/share/updatezone/docs/README.txt | 46 --- usr/share/updatezone/docs/files-for-versioning.txt | 3 - usr/share/updatezone/docs/packaging.txt | 1 - usr/share/updatezone/docs/updatezone.spec | 57 ---- .../examples/ipa.smith122.com.conf.example | 7 - usr/share/updatezone/inc/get-files | 40 --- usr/share/updatezone/inc/pack | 116 ------- usr/share/updatezone/updatezone.sh | 371 --------------------- 19 files changed, 947 insertions(+), 942 deletions(-) create mode 120000 usr/bin/dhcpd-control create mode 100755 usr/share/ddtools/dhcpd-control.sh create mode 100644 usr/share/ddtools/docs/README.txt create mode 100644 usr/share/ddtools/docs/ddtools.spec create mode 100644 usr/share/ddtools/docs/files-for-versioning.txt create mode 100644 usr/share/ddtools/examples/ipa.smith122.com.conf.example create mode 100755 usr/share/ddtools/inc/get-files create mode 100755 usr/share/ddtools/inc/pack create mode 100755 usr/share/ddtools/updatezone.sh delete mode 100755 usr/share/updatezone/dhcpd-control.sh delete mode 100644 usr/share/updatezone/docs/README.txt delete mode 100644 usr/share/updatezone/docs/files-for-versioning.txt delete mode 100644 usr/share/updatezone/docs/packaging.txt delete mode 100644 usr/share/updatezone/docs/updatezone.spec delete mode 100644 usr/share/updatezone/examples/ipa.smith122.com.conf.example delete mode 100755 usr/share/updatezone/inc/get-files delete mode 100755 usr/share/updatezone/inc/pack delete mode 100755 usr/share/updatezone/updatezone.sh (limited to 'usr') diff --git a/usr/bin/dhcpd-control b/usr/bin/dhcpd-control new file mode 120000 index 0000000..2eb517b --- /dev/null +++ b/usr/bin/dhcpd-control @@ -0,0 +1 @@ +../share/ddtools/dhcpd-control.sh \ No newline at end of file diff --git a/usr/bin/updatezone b/usr/bin/updatezone index dcc38ab..bbe52a3 120000 --- a/usr/bin/updatezone +++ b/usr/bin/updatezone @@ -1 +1 @@ -../share/updatezone/updatezone.sh \ No newline at end of file +../share/ddtools/updatezone.sh \ No newline at end of file diff --git a/usr/share/ddtools/dhcpd-control.sh b/usr/share/ddtools/dhcpd-control.sh new file mode 100755 index 0000000..a334a93 --- /dev/null +++ b/usr/share/ddtools/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/ddtools/docs/README.txt b/usr/share/ddtools/docs/README.txt new file mode 100644 index 0000000..db65caf --- /dev/null +++ b/usr/share/ddtools/docs/README.txt @@ -0,0 +1,48 @@ +File: usr/share/ddtools/docs/README.txt +Package: ddtools +Author: bgstack15 +Startdate: 2017-05-26 +Title: Readme file for ddtools +Purpose: All packages should come with a readme +Usage: Read it. +Reference: README.txt +Improve: +Document: Below this line + +### WELCOME +ddtools is a suite of shell scripts that help manage dns and dhcpd. +Updatezone provides an easy way to update dns zone files. Intended primarily for bind9 zone files, experimentation is encouraged. +Instead of running the series of commands manually: rndc freeze, vi zonefile, rndc thaw and so on, use updatezone. +dhcpd-control helps manage paired dhcpd servers. + +### CONFIGURATION +The conf files belong in /etc/ddtools/. See example in /usr/share/ddtools/examples/. + +### USING THIS TOOL + +$ updatezone ipa.smith122.com +Where this file exists: /etc/ddtools/ipa.smith122.com.conf + + UZ_ZONE_NAME=ipa.smith122.com + UZ_FORWARD_ZONE=ipa.smith122.com + UZ_FORWARD_FILE=/var/named/data/db.ipa.smith122.com + UZ_REVERSE_ZONE=1.168.192.in-addr.arpa + UZ_REVERSE_FILE=/var/named/data/db.192.168.1 + UZ_SLAVE_COUNT=1 + UZ_SLAVE_1=dns2 + +The updatezone tool searches for the value of UZ_ZONE_NAME to declare a match and use that configuration file. +The zone definitions are used in the freeze/thaw/retransfer commands. + +This tool will only request updates for zones that are updated. Also, you do not need to adjust the serial number at all. The script will detect changes and then increment the serial number for you. + +You can also specify multiple zones on the command line. +$ updatezone ipa.smith122.com ad.smith122.com + +### NOTES + +### REFERENCE + +### CHANGELOG +2017-05-27 B Stack 0.0-2 +- Initial package construction diff --git a/usr/share/ddtools/docs/ddtools.spec b/usr/share/ddtools/docs/ddtools.spec new file mode 100644 index 0000000..2e614cf --- /dev/null +++ b/usr/share/ddtools/docs/ddtools.spec @@ -0,0 +1,60 @@ +# ref: http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html +Summary: suite of scripts for managing dns and dhcpd +Name: ddtools +Version: 0.0 +Release: 2 +License: CC BY-SA 4.0 +Group: Applications/System +Source: ddtools.tgz +URL: https://bgstack15.wordpress.com/ +#Distribution: +#Vendor: +Packager: B Stack +Requires: bgscripts-core >= 1.2-11 +Obsoletes: updatezone <= %{version}-%{release} +Buildarch: noarch + +%description +ddtools provides shell scripts that help manage dns and dhcpd. +updatezone.sh takes a simple config file for selecting the dns zone files to edit. Bind is the only supported dns server right now, but experimentation is encouraged. +dhcpd-control helps manage paired dhcpd servers. + +#%global _python_bytecompile_errors_terminate_build 0 + +%prep +%setup + +%build + +%install +rm -rf %{buildroot} +rsync -a . %{buildroot}/ --exclude='**/.*.swp' --exclude='**/.git' + +%post +exit 0 + +%preun +exit 0 + +%postun +exit 0 + +%files +%dir /etc/updatezone +%dir /usr/share/updatezone +%dir /usr/share/updatezone/inc +%dir /usr/share/updatezone/examples +%dir /usr/share/updatezone/docs +/usr/share/updatezone/inc/pack +/usr/share/updatezone/inc/get-files +%config %attr(666, -, -) /usr/share/updatezone/examples/ipa.smith122.com.conf.example +%doc %attr(444, -, -) /usr/share/updatezone/docs/files-for-versioning.txt +%doc %attr(444, -, -) /usr/share/updatezone/docs/packaging.txt +%doc %attr(444, -, -) /usr/share/updatezone/docs/README.txt +/usr/share/updatezone/docs/updatezone.spec +/usr/share/updatezone/updatezone.sh +%verify(link) /usr/bin/updatezone + +%changelog +* Sat May 27 2017 B Stack 0.0-1 +- Initial rpm release diff --git a/usr/share/ddtools/docs/files-for-versioning.txt b/usr/share/ddtools/docs/files-for-versioning.txt new file mode 100644 index 0000000..f160609 --- /dev/null +++ b/usr/share/ddtools/docs/files-for-versioning.txt @@ -0,0 +1,3 @@ +docs/README.txt +docs/ddtools.spec +docs/debian-ddtools/control diff --git a/usr/share/ddtools/examples/ipa.smith122.com.conf.example b/usr/share/ddtools/examples/ipa.smith122.com.conf.example new file mode 100644 index 0000000..9f74dd8 --- /dev/null +++ b/usr/share/ddtools/examples/ipa.smith122.com.conf.example @@ -0,0 +1,7 @@ +UZ_ZONE_NAME=ipa.smith122.com +UZ_FORWARD_ZONE=ipa.smith122.com +UZ_FORWARD_FILE=/var/named/data/db.ipa.smith122.com +UZ_REVERSE_ZONE=1.168.192.in-addr.arpa +UZ_REVERSE_FILE=/var/named/data/db.192.168.1 +UZ_SLAVE_COUNT=1 +UZ_SLAVE_1=dns2 diff --git a/usr/share/ddtools/inc/get-files b/usr/share/ddtools/inc/get-files new file mode 100755 index 0000000..3302cc5 --- /dev/null +++ b/usr/share/ddtools/inc/get-files @@ -0,0 +1,40 @@ +#!/bin/sh +# File: get-files +case "${1}" in + rpm) +if test -n "${package}"; then cd ${rpmbuilddir}/SOURCES/"${package}-${version}"; else cd $( pwd | sed -r -e 's/(SOURCES\/[^\/]+\/).*/\1/;' ); fi + +### for rpm +find * -type d -regextype grep \ + \( -regex 'usr\/share\/ddtools*' -o -regex 'etc\/ddtools*' \) \ + ! -regex '.*gui.*' \ + | sed -e 's/^/%dir \//;' +find * -mindepth 1 ! -name "${package}.spec.$$.swp" \ + ! -type d -regextype grep \ + ! -regex '.*.swp' \ + ! -regex '.*DEBIAN.*' \ + | sed -r -e ' +s/^/\//; +s/(.*\.txt)/%doc %attr(444, -, -) \1/; +s/(.*bin.*)/%verify(link) \1/; +s/(.*)\.py$/\1\.py\n\1\.pyc\n\1\.pyo/; +s/(.*\.conf)/%config %attr(666, -, -) \1/; +s/(\/usr)?\/lib\/systemd\/system\/(.*)/%{_unitdir}\/\2/; +' + + ;; + deb) + +### for deb +find . -mindepth 1 ! -name "${package}.spec\.$$\.swp" \ + ! -type d -regextype grep \ + ! -regex '.*hg.*' ! -regex '.*?debian-binary.*' \ + ! -regex '.*DEBIAN.*' ! -regex '.*\.swp' ! -regex '.*\.git.*' ! -name 'README.md' \ + -printf '%P ' + + ;; + *) + echo "FATAL ERROR: check ./pack or get-files-core. Please use [ rpm | deb ] option. Aborted." 1>&2 + exit 1 + ;; +esac diff --git a/usr/share/ddtools/inc/pack b/usr/share/ddtools/inc/pack new file mode 100755 index 0000000..5173a22 --- /dev/null +++ b/usr/share/ddtools/inc/pack @@ -0,0 +1,116 @@ +#!/bin/bash + +# DETERMINE LOCATION OF FRAMEWORK +while read flocation; do if test -x ${flocation} && test "$( ${flocation} --fcheck )" -ge 20170111; then frameworkscript="${flocation}"; break; fi; done <&2 && exit 4 + +. ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2 + +type=""; + +case "${thisflavor}" in + redhat|rhel|centos|fedora|korora) type=rpm;; + debian|ubuntu) type=dpkg;; + *) type=targz;; +esac + +echo " $@ " | grep -qiE -- "help|usage|\s-h\s|\s-\?" 1>/dev/null 2>&1 && { + # display help and exit + less -F </dev/null 2>&1 && type=rpm +echo " $@ " | grep -qiE -- "debian|ubuntu|deb\s|dpkg" 1>/dev/null 2>&1 && type=dpkg +echo " $@ " | grep -qiE -- "tar|tgz|gz" 1>/dev/null 2>&1 && type=targz +echo " $@ " | grep -qiE -- "scrub" 1>/dev/null 2>&1 && type=scrub + +# Display information +echo "packaging ${package}-${version} as ${type}" +echo " $@ " | grep -qiE -- "debug|\s-d[ 0-9]{0,3}\s" 1>/dev/null 2>&1 && exit 0 + +case "${type}" in + rpm) + +########## PACKAGING for rhel/centos +# if you copy-paste this, be sure to define package, version, shortversion +rpmbuilddir=~/rpmbuild/ +packagespecfile="${package}-${version}/usr/share/${package}/docs/${package}.spec" +sed -n -e '1,/^\%files$/p;' "${rpmbuilddir}/SOURCES/${packagespecfile}" > "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" # removes files and changelog +cd ${rpmbuilddir}/SOURCES/"${package}-${version}" +"${rpmbuilddir}/SOURCES/${package}-${version}/usr/share/${package}/inc/get-files" rpm >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" +{ printf '\n'; sed -n -e '/^\%changelog/,$p' "${rpmbuilddir}/SOURCES/${packagespecfile}"; } >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" +mv -f "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" "${rpmbuilddir}/SOURCES/${packagespecfile}" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}"; cp -prf "${rpmbuilddir}/SOURCES/${package}-${version}" "${rpmbuilddir}/SOURCES/${package}-${shortversion}" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/DEBIAN" +cd "${rpmbuilddir}/SOURCES" +rm -rf "${package}.tgz"; tar -zc --exclude='.git*' --exclude='README.md' -f "${package}.tgz" "${package}-${shortversion}" +cp -p "${rpmbuilddir}/SOURCES/${packagespecfile}" "${rpmbuilddir}/SPECS" +mkdir -p "${rpmbuilddir}/RPMS/noarch"; cd "${rpmbuilddir}/RPMS/noarch" +rpmbuild -bb "${rpmbuilddir}/SPECS/${package}.spec" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/" "${rpmbuilddir}/SOURCES/${package}.tgz" + + ;; + dpkg) + +########## PACKAGING for ubuntu +# You need package dpkg-dev to build packages. +# if you copy-paste this, be sure to define package, version +debdir=~/deb +debiandirmain="${package}-${version}/usr/share/${package}/docs/debian-${package}" +cd "${debdir}/${package}-${version}" +"${debdir}/${package}-${version}/usr/share/${package}/inc/get-files" deb | xargs md5sum > "${debdir}/${debiandirmain}/md5sums" +#mkdir -p "${debdir}/$$"; mv "${debdir}/${package}-${version}/.git" "${debdir}/${package}-${version}/README.md" "${debdir}/$$/" +cd "${debdir}" + +# main +rm -rf "${debdir}/${package}-${version}/DEBIAN/" 2>/dev/null; mkdir -p "${debdir}/${package}-${version}/DEBIAN/" +cp -pf "${debdir}/${debiandirmain}"/* "${debdir}/${package}-${version}/DEBIAN/" +mkdir "${debdir}/${package}" 2>/dev/null; rm -rf "${debdir}/${package}-${version}-work.tgz" +tar -zc --exclude='.git*' --exclude='README.md' -f "${debdir}/${package}-${version}-work.tgz" -C "${debdir}/${package}-${version}" $( awk '{print $2}' "${debdir}/${package}-${version}/DEBIAN/md5sums" ) DEBIAN +tar -zx -C "${debdir}/${package}" -f "${debdir}/${package}-${version}-work.tgz" +fakeroot dpkg-deb -b "${debdir}/${package}" +mv -f "${debdir}/${package}.deb" "${debdir}/${package}-${version}.deb" +rm -rf "${debdir}/${package}-${version}-work.tgz" "${debdir}/${package}" + +#mv "${debdir}/$$/.git" "${debdir}/$$/"* "${debdir}/${package}-${version}/"; rmdir "${debdir}/$$" + + ;; + targz) + +########## PACKAGING in a master.tgz +# if you copy-paste this, be sure to define package, version +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +rm -rf ./"${package}-${version}".master.tgz +tar -zcf "${package}-${version}".master.tgz "${package}-${version}"/ + + ;; + scrub) + +########## SCRUB for publication +# if you copy-paste this, be sure to define package, version +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +cd "$( find . -name "*scrub.txt" | grep -iE "${package}-${version}\/" | xargs dirname )" +/usr/share/bgscripts/scrub.py + + ;; + unknown) + echo "error: check $0 for errors on type ${type}." 1>&2 + ;; +esac diff --git a/usr/share/ddtools/updatezone.sh b/usr/share/ddtools/updatezone.sh new file mode 100755 index 0000000..d6d01c0 --- /dev/null +++ b/usr/share/ddtools/updatezone.sh @@ -0,0 +1,371 @@ +#!/bin/sh +# Filename: updatezone.sh +# Location: +# Author: bgstack15@gmail.com +# Startdate: 2017-05-26 07:02:47 +# Title: Script that Updates a DNS Zone +# Purpose: Provides a single command to update dns zones +# Package: updatezone +# History: +# Usage: +# Primarily intended for updating forward and reverse zones for bind9. +# Reference: ftemplate.sh 2017-05-24a; framework.sh 2017-05-24a +# Improve: +# Dependencies: +# rndc +# ssh with password-less authentication to slave servers +# each zone file has only a single zone +fiversion="2017-05-24a" +updatezoneversion="2017-05-27a" + +usage() { + less -F >&2 <> "${zones_to_thaw_file}" + + # prepare temp file + cp -p "${zone_real_file}" "${zone_temp_file}" + fi + fi +} + +zone_action() { + # call: zone_action ${forwardzone} + debuglev 9 && ferror "zone_action $@" + local action="$1" + local zone="$2" + case "${action}" in + freeze|thaw) + rndc "${action}" "${zone}" 2>&1 | grep -viE "a zone reload and thaw|Check the logs to see" + ;; + *) + ferror "${scriptfile} minor error: ignoring unknown zone_action $@" + ;; + esac +} + +update_real_zone_if_updated() { + # call: update_real_zone_if_updated "${UZ_REVERSE_ZONE}" "${UZ_REVERSE_FILE}" "${temp_rev_file}" + debuglev 9 && ferror "update_real_zone_if_updated $@" + local zone_name="$1" + local zone_real_file="$2" + local zone_temp_file="$3" + if test -n "${zone_temp_file}" && test -f "${zone_temp_file}"; + then + if ! cmp -s "${zone_real_file}" "${zone_temp_file}"; + then + # a change occurred, so increment the serial number and replace the original zone file + increment_serial_in_zone_file "${zone_temp_file}" + cat "${zone_temp_file}" > "${zone_real_file}" + + # plan to notify the dns slaves + echo "${zone_name}" >> "${zones_to_update_file}" + fi + fi + + # If the temp file does not exist, it was deleted because the real file was invalid for whatever reason. +} + +increment_serial_in_zone_file() { + # call: increment_serial_in_zone_file "${zone_temp_file}" + # dependencies: a single zone in the zone file, with the ";serial" comment after the number. + debuglev 9 && ferror "increment_serial_in_zone_file $@" + local infile="$1" + currentnum="$( grep -iE "[0-9]+\s*;\s*serial" "${infile}" | grep -oIE "[0-9]+" )" + nextnum=$(( currentnum + 1 )) + sed -i -r -e "s/${currentnum}(\s*;\s*serial)/${nextnum}\1/" "${infile}" +} + +# DEFINE TRAPS + +clean_updatezone() { + rm -rf ${tempdir} > /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 + exit 0 +} + +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 ${updatezoneversion}"; exit 1;; + #"i" | "infile" | "inputfile" ) getval;infile1=${tempval};; + "c" | "conf" | "config" | "conffile" ) getval;conffile=${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 +define_if_new interestedparties "bgstack15@gmail.com" +# SIMPLECONF +#define_if_new default_conffile "/etc/updatezone/updatezone.conf" +#define_if_new defuser_conffile ~/.config/updatezone/updatezone.conf +define_if_new EDITOR vi +define_if_new default_dir "/etc/updatezone" + +# 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 + +# VALIDATE PARAMETERS +# objects before the dash are options, which get filled with the optvals +# to debug flags, use option DEBUG. Variables set in framework: fallopts +validateparams - "$@" + +# CONFIRM TOTAL NUMBER OF FLAGLESSVALS IS CORRECT +#if test ${thiscount} -lt 1; +#then +# #ferror "${scriptfile}: 2. Fewer than 2 flaglessvals. Aborted." +# #exit 2 +#fi + +# CONFIGURE VARIABLES AFTER PARAMETERS + +## LOAD CONFIG FROM SIMPLECONF +## This section follows a simple hierarchy of precedence, with first being used: +## 1. parameters and flags +## 2. environment +## 3. config file +## 4. default user config: ~/.config/script/script.conf +## 5. default config: /etc/script/script.conf +#if test -f "${conffile}"; +#then +# get_conf "${conffile}" +#else +# #if test "${conffile}" = "${default_conffile}" || test "${conffile}" = "${defuser_conffile}"; then :; else +# ferror "${scriptfile}: Ignoring conf file which is not found: ${conffile}." +# #fi +#fi +#test -f "${defuser_conffile}" && get_conf "${defuser_conffile}" +#test -f "${default_conffile}" && get_conf "${default_conffile}" + +## REACT TO BEING A CRONJOB +#if test ${is_cronjob} -eq 1; +#then +# [ ] +#else +# [ ] +#fi + +# SET TRAPS +trap "CTRLC" 2 +#trap "CTRLZ" 18 +trap "clean_updatezone" 0 + +## DEBUG SIMPLECONF +#debuglev 5 && { +# ferror "Using values" +# # used values: EX_(OPT1|OPT2|VERBOSE) +# set | grep -iE "^UZ_" 1>&2 +#} + +# MAKE TEMP LOCATIONS +tempdir=/tmp/updatezone/ +if ! mkdir -p "${tempdir}"; +then + ferror "${scriptfile}: 4. Unable to make temp directory ${tempdir}. Aborted." + exit 4 +fi + +# MAIN LOOP +main() { + # call: main "${conffile}" + get_conf "$1" + # DEBUG SIMPLECONF + debuglev 5 && { + ferror "Using values" + # used values: EX_(OPT1|OPT2|VERBOSE) + set | grep -iE "^UZ_" 1>&2 + } + local temp_for_file="$( mktemp -p "${tempdir}" forward.XXXX 2>/dev/null )" + local temp_rev_file="$( mktemp -p "${tempdir}" reverse.XXXX 2>/dev/null )" + local zones_to_thaw_file="$( mktemp -p "${tempdir}" thaw.XXXX )" + local zones_to_update_file="$( mktemp -p "${tempdir}" update.XXXX )" + for word in "${temp_for_file}" "${temp_rev_file}"; + do + if test ! -f "${word}"; + then + ferror "${scriptfile}: 4. Unable to make temp file ${word}. Aborted." + exit 4 + fi + done + + local pause_to_show_error=0 + # Check forward zone file and freeze + check_zone_file forward "${UZ_FORWARD_ZONE}" "${UZ_FORWARD_FILE}" "${temp_for_file}" + + # Check reverse zone file and freeze + check_zone_file reverse "${UZ_REVERSE_ZONE}" "${UZ_REVERSE_FILE}" "${temp_rev_file}" + + # Slow down to show errors if any + fistruthy "${pause_to_show_error}" && sleep 1.3 + + # Allow user to edit files that exist + local these_temp_files="$( find "${temp_for_file}" "${temp_rev_file}" 2>/dev/null | xargs )" + test -n "${these_temp_files}" && $EDITOR ${these_temp_files} + + # Update the real zone if the temp file was updated + update_real_zone_if_updated "${UZ_FORWARD_ZONE}" "${UZ_FORWARD_FILE}" "${temp_for_file}" + update_real_zone_if_updated "${UZ_REVERSE_ZONE}" "${UZ_REVERSE_FILE}" "${temp_rev_file}" + # Thaw zones that need it + while read thiszone; + do + zone_action thaw "${thiszone}" + done < "${zones_to_thaw_file}" + + # Transfer zones that need it + # This section exists because my automatic zone transfers/updates do not work. + + # Build list of commands to run on each dns slave server + transfercommand="" + while read thiszone; + do + transfercommand="${transfercommand}rndc retransfer ${thiszone}; " + done < "${zones_to_update_file}" + + # Execute command on each slave server + if test -n "${transfercommand}"; + then + x=0 + while test ${x} -lt ${UZ_SLAVE_COUNT}; + do + x=$(( x + 1 )) + eval this_dns_slave=\"\${UZ_SLAVE_${x}}\" + debuglev 5 && ferror "ssh ${this_dns_slave} ${transfercommand}" + ssh ${this_dns_slave} ${transfercommand} + done + fi + +} #| tee -a ${logfile} + + +if test -n "${conffile}"; +then + ( main "${conffile}"; ) +else + # assume the $opt items are the zone names + y=0 + while test $y -lt $thiscount; + do + y=$(( y + 1 )) + eval "thiszonename=\${opt${y}}" + debuglev 1 && ferror "Will try to update zone ${thiszonename}" + file_for_this_zone="$( grep -liE "UZ_ZONE_NAME=${thiszonename}" "${default_dir}/"*.conf 2>/dev/null )" + if test -n "${file_for_this_zone}" && test -f "${file_for_this_zone}"; + then + ( main "${file_for_this_zone}"; ) + else + ferror "Skipping zone ${thiszonename} for which no file was found in ${default_dir}/" + fi + done +fi + +# EMAIL LOGFILE +#${sendsh} ${sendopts} "${server} ${scriptfile} out" ${logfile} ${interestedparties} + +## STOP THE READ CONFIG FILE +#exit 0 +#fi; done; } diff --git a/usr/share/updatezone/dhcpd-control.sh b/usr/share/updatezone/dhcpd-control.sh deleted file mode 100755 index a334a93..0000000 --- a/usr/share/updatezone/dhcpd-control.sh +++ /dev/null @@ -1,300 +0,0 @@ -#!/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/README.txt b/usr/share/updatezone/docs/README.txt deleted file mode 100644 index 76bb4b4..0000000 --- a/usr/share/updatezone/docs/README.txt +++ /dev/null @@ -1,46 +0,0 @@ -File: usr/share/updatezone/docs/README.txt -Package: updatezone -Author: bgstack15 -Startdate: 2017-05-26 -Title: Readme file for updatezone -Purpose: All packages should come with a readme -Usage: Read it. -Reference: README.txt -Improve: -Document: Below this line - -### WELCOME -Updatezone provides an easy way to update dns zone files. Intended primarily for bind9 zone files, experimentation is encouraged. -Instead of running the series of commands manually: rndc freeze, vi zonefile, rndc thaw and so on, use updatezone. - -### CONFIGURATION -The conf files belong in /etc/updatezone/. See example in /usr/share/updatezone/examples/. - -### USING THIS TOOL - -$ updatezone ipa.smith122.com -Where this file exists: /etc/updatezone/ipa.smith122.com.conf - - UZ_ZONE_NAME=ipa.smith122.com - UZ_FORWARD_ZONE=ipa.smith122.com - UZ_FORWARD_FILE=/var/named/data/db.ipa.smith122.com - UZ_REVERSE_ZONE=1.168.192.in-addr.arpa - UZ_REVERSE_FILE=/var/named/data/db.192.168.1 - UZ_SLAVE_COUNT=1 - UZ_SLAVE_1=dns2 - -The updatezone tool searches for the value of UZ_ZONE_NAME to declare a match and use that configuration file. -The zone definitions are used in the freeze/thaw/retransfer commands. - -This tool will only request updates for zones that are updated. Also, you do not need to adjust the serial number at all. The script will detect changes and then increment the serial number for you. - -You can also specify multiple zones on the command line. -$ updatezone ipa.smith122.com ad.smith122.com - -### NOTES - -### REFERENCE - -### CHANGELOG -2017-05-27 B Stack 0.0-1 -- Initial package construction diff --git a/usr/share/updatezone/docs/files-for-versioning.txt b/usr/share/updatezone/docs/files-for-versioning.txt deleted file mode 100644 index c08c65a..0000000 --- a/usr/share/updatezone/docs/files-for-versioning.txt +++ /dev/null @@ -1,3 +0,0 @@ -docs/README.txt -docs/updatezone.spec -docs/debian-updatezone/control diff --git a/usr/share/updatezone/docs/packaging.txt b/usr/share/updatezone/docs/packaging.txt deleted file mode 100644 index beb1ccb..0000000 --- a/usr/share/updatezone/docs/packaging.txt +++ /dev/null @@ -1 +0,0 @@ -delete this file please. diff --git a/usr/share/updatezone/docs/updatezone.spec b/usr/share/updatezone/docs/updatezone.spec deleted file mode 100644 index d08942e..0000000 --- a/usr/share/updatezone/docs/updatezone.spec +++ /dev/null @@ -1,57 +0,0 @@ -# ref: http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html -Summary: update dns zone files easily -Name: updatezone -Version: 0.0 -Release: 2 -License: CC BY-SA 4.0 -Group: Applications/System -Source: updatezone.tgz -URL: https://bgstack15.wordpress.com/ -#Distribution: -#Vendor: -Packager: B Stack -Requires: bgscripts-core >= 1.2-11 -Buildarch: noarch - -%description -updatezone provides updatezone.sh which takes a simple config file for selecting the dns zone files to edit. Bind is the only supported dns server right now, but experimentation is encouraged. - -#%global _python_bytecompile_errors_terminate_build 0 - -%prep -%setup - -%build - -%install -rm -rf %{buildroot} -rsync -a . %{buildroot}/ --exclude='**/.*.swp' --exclude='**/.git' - -%post -exit 0 - -%preun -exit 0 - -%postun -exit 0 - -%files -%dir /etc/updatezone -%dir /usr/share/updatezone -%dir /usr/share/updatezone/inc -%dir /usr/share/updatezone/examples -%dir /usr/share/updatezone/docs -/usr/share/updatezone/inc/pack -/usr/share/updatezone/inc/get-files -%config %attr(666, -, -) /usr/share/updatezone/examples/ipa.smith122.com.conf.example -%doc %attr(444, -, -) /usr/share/updatezone/docs/files-for-versioning.txt -%doc %attr(444, -, -) /usr/share/updatezone/docs/packaging.txt -%doc %attr(444, -, -) /usr/share/updatezone/docs/README.txt -/usr/share/updatezone/docs/updatezone.spec -/usr/share/updatezone/updatezone.sh -%verify(link) /usr/bin/updatezone - -%changelog -* Sat May 27 2017 B Stack 0.0-1 -- Initial rpm release diff --git a/usr/share/updatezone/examples/ipa.smith122.com.conf.example b/usr/share/updatezone/examples/ipa.smith122.com.conf.example deleted file mode 100644 index 9f74dd8..0000000 --- a/usr/share/updatezone/examples/ipa.smith122.com.conf.example +++ /dev/null @@ -1,7 +0,0 @@ -UZ_ZONE_NAME=ipa.smith122.com -UZ_FORWARD_ZONE=ipa.smith122.com -UZ_FORWARD_FILE=/var/named/data/db.ipa.smith122.com -UZ_REVERSE_ZONE=1.168.192.in-addr.arpa -UZ_REVERSE_FILE=/var/named/data/db.192.168.1 -UZ_SLAVE_COUNT=1 -UZ_SLAVE_1=dns2 diff --git a/usr/share/updatezone/inc/get-files b/usr/share/updatezone/inc/get-files deleted file mode 100755 index fd3e45a..0000000 --- a/usr/share/updatezone/inc/get-files +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# File: get-files -case "${1}" in - rpm) -if test -n "${package}"; then cd ${rpmbuilddir}/SOURCES/"${package}-${version}"; else cd $( pwd | sed -r -e 's/(SOURCES\/[^\/]+\/).*/\1/;' ); fi - -### for rpm -find * -type d -regextype grep \ - \( -regex 'usr\/share\/updatezone.*' -o -regex 'etc\/updatezone.*' \) \ - ! -regex '.*gui.*' \ - | sed -e 's/^/%dir \//;' -find * -mindepth 1 ! -name "${package}.spec.$$.swp" \ - ! -type d -regextype grep \ - ! -regex '.*.swp' \ - ! -regex '.*DEBIAN.*' \ - | sed -r -e ' -s/^/\//; -s/(.*\.txt)/%doc %attr(444, -, -) \1/; -s/(.*bin.*)/%verify(link) \1/; -s/(.*)\.py$/\1\.py\n\1\.pyc\n\1\.pyo/; -s/(.*\.conf)/%config %attr(666, -, -) \1/; -s/(\/usr)?\/lib\/systemd\/system\/(.*)/%{_unitdir}\/\2/; -' - - ;; - deb) - -### for deb -find . -mindepth 1 ! -name "${package}.spec\.$$\.swp" \ - ! -type d -regextype grep \ - ! -regex '.*hg.*' ! -regex '.*?debian-binary.*' \ - ! -regex '.*DEBIAN.*' ! -regex '.*\.swp' ! -regex '.*\.git.*' ! -name 'README.md' \ - -printf '%P ' - - ;; - *) - echo "FATAL ERROR: check ./pack or get-files-core. Please use [ rpm | deb ] option. Aborted." 1>&2 - exit 1 - ;; -esac diff --git a/usr/share/updatezone/inc/pack b/usr/share/updatezone/inc/pack deleted file mode 100755 index 6c5d72f..0000000 --- a/usr/share/updatezone/inc/pack +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash - -# DETERMINE LOCATION OF FRAMEWORK -while read flocation; do if test -x ${flocation} && test "$( ${flocation} --fcheck )" -ge 20170111; then frameworkscript="${flocation}"; break; fi; done <&2 && exit 4 - -. ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2 - -type=""; - -case "${thisflavor}" in - redhat|rhel|centos|fedora|korora) type=rpm;; - debian|ubuntu) type=dpkg;; - *) type=targz;; -esac - -echo " $@ " | grep -qiE -- "help|usage|\s-h\s|\s-\?" 1>/dev/null 2>&1 && { - # display help and exit - less -F </dev/null 2>&1 && type=rpm -echo " $@ " | grep -qiE -- "debian|ubuntu|deb\s|dpkg" 1>/dev/null 2>&1 && type=dpkg -echo " $@ " | grep -qiE -- "tar|tgz|gz" 1>/dev/null 2>&1 && type=targz -echo " $@ " | grep -qiE -- "scrub" 1>/dev/null 2>&1 && type=scrub - -# Display information -echo "packaging ${package}-${version} as ${type}" -echo " $@ " | grep -qiE -- "debug|\s-d[ 0-9]{0,3}\s" 1>/dev/null 2>&1 && exit 0 - -case "${type}" in - rpm) - -########## PACKAGING for rhel/centos -# if you copy-paste this, be sure to define package, version, shortversion -rpmbuilddir=~/rpmbuild/ -packagespecfile="${package}-${version}/usr/share/${package}/docs/${package}.spec" -sed -n -e '1,/^\%files$/p;' "${rpmbuilddir}/SOURCES/${packagespecfile}" > "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" # removes files and changelog -cd ${rpmbuilddir}/SOURCES/"${package}-${version}" -"${rpmbuilddir}/SOURCES/${package}-${version}/usr/share/${package}/inc/get-files" rpm >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" -{ printf '\n'; sed -n -e '/^\%changelog/,$p' "${rpmbuilddir}/SOURCES/${packagespecfile}"; } >> "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" -mv -f "${rpmbuilddir}/SOURCES/${packagespecfile}.$$.swp" "${rpmbuilddir}/SOURCES/${packagespecfile}" -rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}"; cp -prf "${rpmbuilddir}/SOURCES/${package}-${version}" "${rpmbuilddir}/SOURCES/${package}-${shortversion}" -rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/DEBIAN" -cd "${rpmbuilddir}/SOURCES" -rm -rf "${package}.tgz"; tar -zc --exclude='.git*' --exclude='README.md' -f "${package}.tgz" "${package}-${shortversion}" -cp -p "${rpmbuilddir}/SOURCES/${packagespecfile}" "${rpmbuilddir}/SPECS" -mkdir -p "${rpmbuilddir}/RPMS/noarch"; cd "${rpmbuilddir}/RPMS/noarch" -rpmbuild -bb "${rpmbuilddir}/SPECS/${package}.spec" -rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/" "${rpmbuilddir}/SOURCES/${package}.tgz" - - ;; - dpkg) - -########## PACKAGING for ubuntu -# You need package dpkg-dev to build packages. -# if you copy-paste this, be sure to define package, version -debdir=~/deb -debiandirmain="${package}-${version}/usr/share/${package}/docs/debian-${package}" -cd "${debdir}/${package}-${version}" -"${debdir}/${package}-${version}/usr/share/${package}/inc/get-files" deb | xargs md5sum > "${debdir}/${debiandirmain}/md5sums" -#mkdir -p "${debdir}/$$"; mv "${debdir}/${package}-${version}/.git" "${debdir}/${package}-${version}/README.md" "${debdir}/$$/" -cd "${debdir}" - -# main -rm -rf "${debdir}/${package}-${version}/DEBIAN/" 2>/dev/null; mkdir -p "${debdir}/${package}-${version}/DEBIAN/" -cp -pf "${debdir}/${debiandirmain}"/* "${debdir}/${package}-${version}/DEBIAN/" -mkdir "${debdir}/${package}" 2>/dev/null; rm -rf "${debdir}/${package}-${version}-work.tgz" -tar -zc --exclude='.git*' --exclude='README.md' -f "${debdir}/${package}-${version}-work.tgz" -C "${debdir}/${package}-${version}" $( awk '{print $2}' "${debdir}/${package}-${version}/DEBIAN/md5sums" ) DEBIAN -tar -zx -C "${debdir}/${package}" -f "${debdir}/${package}-${version}-work.tgz" -fakeroot dpkg-deb -b "${debdir}/${package}" -mv -f "${debdir}/${package}.deb" "${debdir}/${package}-${version}.deb" -rm -rf "${debdir}/${package}-${version}-work.tgz" "${debdir}/${package}" - -#mv "${debdir}/$$/.git" "${debdir}/$$/"* "${debdir}/${package}-${version}/"; rmdir "${debdir}/$$" - - ;; - targz) - -########## PACKAGING in a master.tgz -# if you copy-paste this, be sure to define package, version -cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES -rm -rf ./"${package}-${version}".master.tgz -tar -zcf "${package}-${version}".master.tgz "${package}-${version}"/ - - ;; - scrub) - -########## SCRUB for publication -# if you copy-paste this, be sure to define package, version -cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES -cd "$( find . -name "*scrub.txt" | grep -iE "${package}-${version}\/" | xargs dirname )" -/usr/share/bgscripts/scrub.py - - ;; - unknown) - echo "error: check $0 for errors on type ${type}." 1>&2 - ;; -esac diff --git a/usr/share/updatezone/updatezone.sh b/usr/share/updatezone/updatezone.sh deleted file mode 100755 index d6d01c0..0000000 --- a/usr/share/updatezone/updatezone.sh +++ /dev/null @@ -1,371 +0,0 @@ -#!/bin/sh -# Filename: updatezone.sh -# Location: -# Author: bgstack15@gmail.com -# Startdate: 2017-05-26 07:02:47 -# Title: Script that Updates a DNS Zone -# Purpose: Provides a single command to update dns zones -# Package: updatezone -# History: -# Usage: -# Primarily intended for updating forward and reverse zones for bind9. -# Reference: ftemplate.sh 2017-05-24a; framework.sh 2017-05-24a -# Improve: -# Dependencies: -# rndc -# ssh with password-less authentication to slave servers -# each zone file has only a single zone -fiversion="2017-05-24a" -updatezoneversion="2017-05-27a" - -usage() { - less -F >&2 <> "${zones_to_thaw_file}" - - # prepare temp file - cp -p "${zone_real_file}" "${zone_temp_file}" - fi - fi -} - -zone_action() { - # call: zone_action ${forwardzone} - debuglev 9 && ferror "zone_action $@" - local action="$1" - local zone="$2" - case "${action}" in - freeze|thaw) - rndc "${action}" "${zone}" 2>&1 | grep -viE "a zone reload and thaw|Check the logs to see" - ;; - *) - ferror "${scriptfile} minor error: ignoring unknown zone_action $@" - ;; - esac -} - -update_real_zone_if_updated() { - # call: update_real_zone_if_updated "${UZ_REVERSE_ZONE}" "${UZ_REVERSE_FILE}" "${temp_rev_file}" - debuglev 9 && ferror "update_real_zone_if_updated $@" - local zone_name="$1" - local zone_real_file="$2" - local zone_temp_file="$3" - if test -n "${zone_temp_file}" && test -f "${zone_temp_file}"; - then - if ! cmp -s "${zone_real_file}" "${zone_temp_file}"; - then - # a change occurred, so increment the serial number and replace the original zone file - increment_serial_in_zone_file "${zone_temp_file}" - cat "${zone_temp_file}" > "${zone_real_file}" - - # plan to notify the dns slaves - echo "${zone_name}" >> "${zones_to_update_file}" - fi - fi - - # If the temp file does not exist, it was deleted because the real file was invalid for whatever reason. -} - -increment_serial_in_zone_file() { - # call: increment_serial_in_zone_file "${zone_temp_file}" - # dependencies: a single zone in the zone file, with the ";serial" comment after the number. - debuglev 9 && ferror "increment_serial_in_zone_file $@" - local infile="$1" - currentnum="$( grep -iE "[0-9]+\s*;\s*serial" "${infile}" | grep -oIE "[0-9]+" )" - nextnum=$(( currentnum + 1 )) - sed -i -r -e "s/${currentnum}(\s*;\s*serial)/${nextnum}\1/" "${infile}" -} - -# DEFINE TRAPS - -clean_updatezone() { - rm -rf ${tempdir} > /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 - exit 0 -} - -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 ${updatezoneversion}"; exit 1;; - #"i" | "infile" | "inputfile" ) getval;infile1=${tempval};; - "c" | "conf" | "config" | "conffile" ) getval;conffile=${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 -define_if_new interestedparties "bgstack15@gmail.com" -# SIMPLECONF -#define_if_new default_conffile "/etc/updatezone/updatezone.conf" -#define_if_new defuser_conffile ~/.config/updatezone/updatezone.conf -define_if_new EDITOR vi -define_if_new default_dir "/etc/updatezone" - -# 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 - -# VALIDATE PARAMETERS -# objects before the dash are options, which get filled with the optvals -# to debug flags, use option DEBUG. Variables set in framework: fallopts -validateparams - "$@" - -# CONFIRM TOTAL NUMBER OF FLAGLESSVALS IS CORRECT -#if test ${thiscount} -lt 1; -#then -# #ferror "${scriptfile}: 2. Fewer than 2 flaglessvals. Aborted." -# #exit 2 -#fi - -# CONFIGURE VARIABLES AFTER PARAMETERS - -## LOAD CONFIG FROM SIMPLECONF -## This section follows a simple hierarchy of precedence, with first being used: -## 1. parameters and flags -## 2. environment -## 3. config file -## 4. default user config: ~/.config/script/script.conf -## 5. default config: /etc/script/script.conf -#if test -f "${conffile}"; -#then -# get_conf "${conffile}" -#else -# #if test "${conffile}" = "${default_conffile}" || test "${conffile}" = "${defuser_conffile}"; then :; else -# ferror "${scriptfile}: Ignoring conf file which is not found: ${conffile}." -# #fi -#fi -#test -f "${defuser_conffile}" && get_conf "${defuser_conffile}" -#test -f "${default_conffile}" && get_conf "${default_conffile}" - -## REACT TO BEING A CRONJOB -#if test ${is_cronjob} -eq 1; -#then -# [ ] -#else -# [ ] -#fi - -# SET TRAPS -trap "CTRLC" 2 -#trap "CTRLZ" 18 -trap "clean_updatezone" 0 - -## DEBUG SIMPLECONF -#debuglev 5 && { -# ferror "Using values" -# # used values: EX_(OPT1|OPT2|VERBOSE) -# set | grep -iE "^UZ_" 1>&2 -#} - -# MAKE TEMP LOCATIONS -tempdir=/tmp/updatezone/ -if ! mkdir -p "${tempdir}"; -then - ferror "${scriptfile}: 4. Unable to make temp directory ${tempdir}. Aborted." - exit 4 -fi - -# MAIN LOOP -main() { - # call: main "${conffile}" - get_conf "$1" - # DEBUG SIMPLECONF - debuglev 5 && { - ferror "Using values" - # used values: EX_(OPT1|OPT2|VERBOSE) - set | grep -iE "^UZ_" 1>&2 - } - local temp_for_file="$( mktemp -p "${tempdir}" forward.XXXX 2>/dev/null )" - local temp_rev_file="$( mktemp -p "${tempdir}" reverse.XXXX 2>/dev/null )" - local zones_to_thaw_file="$( mktemp -p "${tempdir}" thaw.XXXX )" - local zones_to_update_file="$( mktemp -p "${tempdir}" update.XXXX )" - for word in "${temp_for_file}" "${temp_rev_file}"; - do - if test ! -f "${word}"; - then - ferror "${scriptfile}: 4. Unable to make temp file ${word}. Aborted." - exit 4 - fi - done - - local pause_to_show_error=0 - # Check forward zone file and freeze - check_zone_file forward "${UZ_FORWARD_ZONE}" "${UZ_FORWARD_FILE}" "${temp_for_file}" - - # Check reverse zone file and freeze - check_zone_file reverse "${UZ_REVERSE_ZONE}" "${UZ_REVERSE_FILE}" "${temp_rev_file}" - - # Slow down to show errors if any - fistruthy "${pause_to_show_error}" && sleep 1.3 - - # Allow user to edit files that exist - local these_temp_files="$( find "${temp_for_file}" "${temp_rev_file}" 2>/dev/null | xargs )" - test -n "${these_temp_files}" && $EDITOR ${these_temp_files} - - # Update the real zone if the temp file was updated - update_real_zone_if_updated "${UZ_FORWARD_ZONE}" "${UZ_FORWARD_FILE}" "${temp_for_file}" - update_real_zone_if_updated "${UZ_REVERSE_ZONE}" "${UZ_REVERSE_FILE}" "${temp_rev_file}" - # Thaw zones that need it - while read thiszone; - do - zone_action thaw "${thiszone}" - done < "${zones_to_thaw_file}" - - # Transfer zones that need it - # This section exists because my automatic zone transfers/updates do not work. - - # Build list of commands to run on each dns slave server - transfercommand="" - while read thiszone; - do - transfercommand="${transfercommand}rndc retransfer ${thiszone}; " - done < "${zones_to_update_file}" - - # Execute command on each slave server - if test -n "${transfercommand}"; - then - x=0 - while test ${x} -lt ${UZ_SLAVE_COUNT}; - do - x=$(( x + 1 )) - eval this_dns_slave=\"\${UZ_SLAVE_${x}}\" - debuglev 5 && ferror "ssh ${this_dns_slave} ${transfercommand}" - ssh ${this_dns_slave} ${transfercommand} - done - fi - -} #| tee -a ${logfile} - - -if test -n "${conffile}"; -then - ( main "${conffile}"; ) -else - # assume the $opt items are the zone names - y=0 - while test $y -lt $thiscount; - do - y=$(( y + 1 )) - eval "thiszonename=\${opt${y}}" - debuglev 1 && ferror "Will try to update zone ${thiszonename}" - file_for_this_zone="$( grep -liE "UZ_ZONE_NAME=${thiszonename}" "${default_dir}/"*.conf 2>/dev/null )" - if test -n "${file_for_this_zone}" && test -f "${file_for_this_zone}"; - then - ( main "${file_for_this_zone}"; ) - else - ferror "Skipping zone ${thiszonename} for which no file was found in ${default_dir}/" - fi - done -fi - -# EMAIL LOGFILE -#${sendsh} ${sendopts} "${server} ${scriptfile} out" ${logfile} ${interestedparties} - -## STOP THE READ CONFIG FILE -#exit 0 -#fi; done; } -- cgit