diff options
Diffstat (limited to 'usr/share')
-rw-r--r-- | usr/share/rbup/docs/README.txt | 22 | ||||
-rw-r--r-- | usr/share/rbup/docs/files-for-versioning.txt | 3 | ||||
-rw-r--r-- | usr/share/rbup/docs/rbup.spec | 44 | ||||
-rwxr-xr-x | usr/share/rbup/inc/get-files | 38 | ||||
-rwxr-xr-x | usr/share/rbup/inc/pack | 136 | ||||
-rwxr-xr-x | usr/share/rbup/rbup.sh | 218 | ||||
-rwxr-xr-x | usr/share/rbup/rbup.sh.2017-05-21.01 | 247 |
7 files changed, 708 insertions, 0 deletions
diff --git a/usr/share/rbup/docs/README.txt b/usr/share/rbup/docs/README.txt new file mode 100644 index 0000000..456ce3a --- /dev/null +++ b/usr/share/rbup/docs/README.txt @@ -0,0 +1,22 @@ +File: usr/share/rbup/docs/README.txt +Package: rbup +Author: bgstack15 +Startdate: 2017-05-21 +Title: Readme file for rbup +Purpose: All packages should come with a readme +Usage: Read it. +Reference: README.txt +Improve: +Document: Below this line + +### WELCOME +Please read /etc/rbup/rbup.conf to learn how to configure rbup. + +### NOTES + +### REFERENCE + +### CHANGELOG + +2017-05-21 B Stack <bgstack15@gmail.com> 0.0-1 +- Initial rpm release. diff --git a/usr/share/rbup/docs/files-for-versioning.txt b/usr/share/rbup/docs/files-for-versioning.txt new file mode 100644 index 0000000..306563d --- /dev/null +++ b/usr/share/rbup/docs/files-for-versioning.txt @@ -0,0 +1,3 @@ +docs/README.txt +docs/rbup.spec +docs/debian-rbup/control diff --git a/usr/share/rbup/docs/rbup.spec b/usr/share/rbup/docs/rbup.spec new file mode 100644 index 0000000..f561baf --- /dev/null +++ b/usr/share/rbup/docs/rbup.spec @@ -0,0 +1,44 @@ +# ref: http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html +Summary: rbup for EL7 +Name: rbup +Version: 0.0 +Release: 1 +License: CC BY-SA 4.0 +Group: Applications/System +Source: rbup.tgz +URL: https://bgstack15.wordpress.com/ +#Distribution: +#Vendor: +Packager: B Stack <bgstack15@gmail.com> +Requires: bgscripts-core >= 1.2-10 +Buildarch: noarch + +%description +rbup is a shell script for conducting regular backups. It provides features such as auto-mount and dismount of the destination location. + +%prep +%setup + +%build + +%install +rm -rf %{buildroot} +rsync -a . %{buildroot}/ --exclude='**/.*.swp' --exclude='**/.git' + +%clean +rm -rf %{buildroot} + +%preun +exit 0 + +%postun +exit 0 + +%post +exit 0 + +%files + +%changelog +* Sun May 21 2017 B Stack <bgstack15@gmail.com> 0.0-1 +- Initial rpm release. See docs/README.txt. diff --git a/usr/share/rbup/inc/get-files b/usr/share/rbup/inc/get-files new file mode 100755 index 0000000..9c875c5 --- /dev/null +++ b/usr/share/rbup/inc/get-files @@ -0,0 +1,38 @@ +#!/bin/sh +# File: get-files +case "${1}" in + rpm) + +### for rpm +find * -type d -regextype grep \ + \( -regex 'usr\/share\/rbup.*' -o -regex 'etc\/rbup.*' \) \ + | 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. Please use [ rpm | deb ] option. Aborted." 1>&2 + exit 1 + ;; +esac diff --git a/usr/share/rbup/inc/pack b/usr/share/rbup/inc/pack new file mode 100755 index 0000000..4928237 --- /dev/null +++ b/usr/share/rbup/inc/pack @@ -0,0 +1,136 @@ +#!/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 <<EOFLOCATIONS +/usr/share/bgscripts/framework.sh +../framework.sh +usr/share/bgscripts/framework.sh +~/rpmbuild/SOURCES/bgscripts-1.1-31/usr/share/bgscripts/framework.sh +EOFLOCATIONS +test -z "${frameworkscript}" && echo "$0: framework not found. Aborted." 1>&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 <<EOF +pack utility version 2017-05-21a-rbup +usage: pack [ rpm | deb | tar | scrub ] [ --debug | -d {0-10} ] +Provides a single command for building a package. This script is customized to each package. +optional arguments: + [ rpm | deb | tar | scrub ] Build that type of package. Scrub calls the scrub.py script. + The default depends on the local os flavor. This system is "${thisflavor}" + [ --debug {0-10} | -d {0-10} ] Display package type to build and exit. Debuglev not implemented here. +EOF +exit 1 +} + +# Derive package name and version number, for my simple package versions only. +fullname="$( pwd | sed -e 's/.*\(SOURCES\|deb\)\///;s/\/.*//;' )" +version="$( echo "${fullname}" | grep -oiE -- "-[0-9]{0,3}\.[0-9a-zA-Z]{0,5}-[0-9]{0,4}" | sed -e 's/^-//;' )" +shortversion="$( echo "${version}" | sed -e 's/-.*//;' )" +package="$( echo "${fullname}" | sed -e "s/-${version}//;" )" + +echo " $@ " | grep -qiE -- "rpm|rhel|redhat|centos|fedora|korora" 1>/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/ +sub1="core" +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%%files ${sub1}\n" ; "${rpmbuilddir}/SOURCES/${package}-${version}/usr/share/${package}/inc/get-files-${sub1}" 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 +sub1="core" +debiandirmain="${package}-${version}/usr/share/${package}/docs/debian-${package}" +debiandirsub1="${package}-${version}/usr/share/${package}/docs/debian-${package}-${sub1}" +cd "${debdir}/${package}-${version}" +"${debdir}/${package}-${version}/usr/share/${package}/inc/get-files" deb | xargs md5sum > "${debdir}/${debiandirmain}/md5sums" +"${debdir}/${package}-${version}/usr/share/${package}/inc/get-files-${sub1}" deb | xargs md5sum > "${debdir}/${debiandirsub1}/md5sums" +#mkdir -p "${debdir}/$$"; mv "${debdir}/${package}-${version}/.git" "${debdir}/${package}-${version}/README.md" "${debdir}/$$/" +cd "${debdir}" + +# sub1 +rm -rf "${debdir}/${package}-${version}/DEBIAN/" 2>/dev/null; mkdir -p "${debdir}/${package}-${version}/DEBIAN/" +cp -pf "${debdir}/${debiandirsub1}"/* "${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}-${sub1}-${version}.deb" +rm -rf "${debdir}/${package}-${version}-work.tgz" "${debdir}/${package}" + +# 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 +echo "Gotta say unh. Feature not yet implemented: scrub. Aborted." 1>&2 +exit 1 + + ;; + unknown) + echo "error: check $0 for errors on type ${type}." 1>&2 + ;; +esac diff --git a/usr/share/rbup/rbup.sh b/usr/share/rbup/rbup.sh new file mode 100755 index 0000000..c5b9608 --- /dev/null +++ b/usr/share/rbup/rbup.sh @@ -0,0 +1,218 @@ +#!/bin/sh +# Filename: rbup.sh +# Location: /usr/share/rbup/ +# Author: bgstack15@gmail.com +# Startdate: 2017-05-21 09:25:16 +# Title: Script that Performs Regular Backups +# Purpose: Allows customizable jobs from an easy config file +# Package: rbup +# History: +# 2016 +# Usage: +# Reference: ftemplate.sh 2017-04-17a; framework.sh 2017-04-17a +# /mnt/bgirton/Backups/bup_data.sh which itself was modified from darmok:/usr/local/bin/sync_smash.sh +# dnskeepalive.sh from package bgscripts-core +# Improve: +fiversion="2017-04-29a" +rbupversion="2017-05-21a" + +usage() { + less -F >&2 <<ENDUSAGE +usage: rbup.sh [-duV] [-c <conffile>] +version ${rbupversion} + -d debug Show debugging info, including parsed variables. + -u usage Show this usage block. + -V version Show script version number. + -c conffile Use this conf instead of default, which is /etc/rbup/rbup.conf +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 +6 Unable to mount destination +7 Invalid checksum(s) on file(s) +ENDUSAGE +} + +# DEFINE FUNCTIONS +get_conf() { + local _infile="$1" + local _tmpfile1="$( mktemp )" + grep -viE '^\s*((#).*)?$' "${_infile}" | while read _line; + do + local _left="$( echo "${_line}" | cut -d'=' -f1 )" + eval "_thisval=\"\${${_left}}\"" + test -z "${_thisval}" && echo "${_line}" >> "${_tmpfile1}" + done + test -f "${_tmpfile1}" && . "${_tmpfile1}" 1>/dev/null 2>&1 + /bin/rm -rf "${_tmpfile1}" +} + +log() { + # WORKHERE: figure out how logging will work + echo "$@" +} + +# DEFINE TRAPS + +clean_rbup() { + #use at end of entire script if you need to clean up tmpfiles + fistruthy "${RBUP_NO_CLEANUP}" || rm -rf "${tmpdir}" 1>/dev/null 2>&1 + : +} + +CTRLC() { + #trap "CTRLC" 2 + [ ] #useful for controlling the ctrl+c keystroke + clean_rbup +} + +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 ${rbupversion}"; exit 1;; + #"i" | "infile" | "inputfile" ) getval;infile1=${tempval};; + "c" | "conf" | "config" | "conffile" | "configfile" ) 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 20170111; then frameworkscript="${flocation}"; break; fi; done <<EOFLOCATIONS +./framework.sh +${scriptdir}/framework.sh +~/bin/bgscripts/framework.sh +~/bin/framework.sh +~/bgscripts/framework.sh +~/framework.sh +/usr/local/bin/bgscripts/framework.sh +/usr/local/bin/framework.sh +/usr/bin/bgscripts/framework.sh +/usr/bin/framework.sh +/bin/bgscripts/framework.sh +/usr/share/bgscripts/framework.sh +EOFLOCATIONS +test -z "${frameworkscript}" && echo "$0: framework not found. Aborted." 1>&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 +interestedparties="bgstack15@gmail.com" + +# 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<<EOFSENDSH # if $1="1" then setvalout="critical-fail" on failure +#/usr/share/bgscripts/send.sh -hs # setvalout maybe be "fail" otherwise +#/usr/local/bin/send.sh -hs # on success, setvalout="valid-sendsh" +#/usr/bin/mail -s +#EOFSENDSH +#test "${setvalout}" = "critical-fail" && ferror "${scriptfile}: 4. mailer not found. Aborted." && exit 4 + +# 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 2; +#then +# ferror "${scriptfile}: 2. Fewer than 2 flaglessvals. Aborted." +# exit 2 +#fi + +# CONFIGURE VARIABLES AFTER PARAMETERS + +## START READ CONFIG FILE TEMPLATE +get_conf /home/bgirton-local/rpmbuild/SOURCES/rbup-0.0-1/etc/rbup/rbup.conf +#oIFS="${IFS}"; IFS="$( printf '\n' )" +#infiledata=$( ${sed} ':loop;/^\/\*/{s/.//;:ccom;s,^.[^*]*,,;/^$/n;/^\*\//{s/..//;bloop;};bccom;}' "${infile1}") #the crazy sed removes c style multiline comments +#IFS="${oIFS}"; infilelines=$( echo "${infiledata}" | wc -l ) +#{ echo "${infiledata}"; echo "ENDOFFILE"; } | { +# while read line; do +# # the crazy sed removes leading and trailing whitespace, blank lines, and comments +# if test ! "${line}" = "ENDOFFILE"; +# then +# line=$( echo "${line}" | sed -e 's/^\s*//;s/\s*$//;/^[#$]/d;s/\s*[^\]#.*$//;' ) +# if test -n "${line}"; +# then +# debuglev 8 && ferror "line=\"${line}\"" +# if echo "${line}" | grep -qiE "\[.*\]"; +# then +# # new zone +# zone=$( echo "${line}" | tr -d '[]' ) +# debuglev 7 && ferror "zone=${zone}" +# else +# # directive +# varname=$( echo "${line}" | awk -F= '{print $1}' ) +# varval=$( echo "${line}" | awk -F= '{$1=""; printf "%s", $0}' | sed 's/^ //;' ) +# debuglev 7 && ferror "${zone}${varname}=\"${varval}\"" +# # simple define variable +# eval "${zone}${varname}=\${varval}" +# fi +# ## this part is untested +# #read -p "Please type something here:" response < ${thistty} +# #echo "${response}" +# fi +# else + +## REACT TO BEING A CRONJOB +#if test ${is_cronjob} -eq 1; +#then +# [ ] +#else +# [ ] +#fi + +# SET TRAPS +trap "CTRLC" 2 +#trap "CTRLZ" 18 +trap "clean_rbup" 0 + +# MAIN LOOP +#{ + [ ] + set | grep -iE "^RBUP_" +#} | 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/rbup/rbup.sh.2017-05-21.01 b/usr/share/rbup/rbup.sh.2017-05-21.01 new file mode 100755 index 0000000..631319a --- /dev/null +++ b/usr/share/rbup/rbup.sh.2017-05-21.01 @@ -0,0 +1,247 @@ +#!/bin/sh +# Filename: rbup.sh +# Location: /usr/share/rbup/ +# Author: bgstack15@gmail.com +# Startdate: 2017-05-21 09:25:16 +# Title: Script that Performs Regular Backups +# Purpose: Allows customizable jobs from an easy config file +# Package: rbup +# History: +# 2016 +# Usage: +# Reference: ftemplate.sh 2017-04-17a; framework.sh 2017-04-17a +# /mnt/bgirton/Backups/bup_data.sh which itself was modified from darmok:/usr/local/bin/sync_smash.sh +# dnskeepalive.sh from package bgscripts-core +# Improve: +fiversion="2017-04-29a" +rbupversion="2017-05-21a" + +usage() { + less -F >&2 <<ENDUSAGE +usage: rbup.sh [-duV] [-c <conffile>] [ -j <jobname>] +version ${rbupversion} + -d debug Show debugging info, including parsed variables. + -u usage Show this usage block. + -V version Show script version number. + -i infile Overrides default infile value. Default is none. + -c conffile Use this conf instead of default, which is /etc/rbup/rbup.conf + -j jobname Run only this job. Can be repeated. +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 +6 Unable to mount destination +7 Invalid checksum(s) on file(s) +ENDUSAGE +} + +# DEFINE FUNCTIONS +get_conf() { + # call: get_conf /etc/rbup/rbup.conf [ job1 [ job2 ... ] ] + # copied in from dnskeepalive, but modified + local _infile="$1" + #local _tmpfile1="$( mktemp -p /tmp/rbup )" + shift; local _requestedzones="default $@" + local _zone="" + grep -viE '^\s*((#).*)?$' "${_infile}" | while read _line; + do + local _left="$( echo "${_line}" | cut -d'=' -f1 )" + # check if line is a zone [rbup:default] + if echo "${_left}" | grep -qiE '^\[rbup:.*\]'; + then + _zone="$( echo "${_left}" | sed -r -e 's/^.*://;s/\]$//;' )" + echo "new zone ${_zone}" + else + eval "_thisval=\"\${${_left}}\"" + if test -z "${_thisval}" && { test -z "$@" || echo "${_requestedzones}" | grep -qiE "${_zone}"; }; + then + echo "${_line}" >> "/tmp/rbup/${_zone}.conf" + echo "${_line} added to /tmp/rbup/${_zone}.conf" + fi + fi + done + #test -f "${_tmpfile1}" && . "${_tmpfile1}" 1>/dev/null 2>&1 + #/bin/rm -rf "${_tmpfile1}" +} + +reset_vars() { + for word in $( set | grep -oIE "^RBUP_.+=" | sed -r -e 's/=$//;' ); do unset ${word}; done +} + +log() { + # WORKHERE: figure out how logging will work + echo "$@" +} + +# DEFINE TRAPS + +clean_rbup() { + #use at end of entire script if you need to clean up tmpfiles + test "${RBUP_CLEANUP}"="1" || rm -rf "${tmpdir}" 1>/dev/null 2>&1 + : +} + +CTRLC() { + #trap "CTRLC" 2 + [ ] #useful for controlling the ctrl+c keystroke + clean_rbup +} + +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 ${rbupversion}"; exit 1;; + #"i" | "infile" | "inputfile" ) getval;infile1=${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 20170111; then frameworkscript="${flocation}"; break; fi; done <<EOFLOCATIONS +./framework.sh +${scriptdir}/framework.sh +~/bin/bgscripts/framework.sh +~/bin/framework.sh +~/bgscripts/framework.sh +~/framework.sh +/usr/local/bin/bgscripts/framework.sh +/usr/local/bin/framework.sh +/usr/bin/bgscripts/framework.sh +/usr/bin/framework.sh +/bin/bgscripts/framework.sh +/usr/share/bgscripts/framework.sh +EOFLOCATIONS +test -z "${frameworkscript}" && echo "$0: framework not found. Aborted." 1>&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 +interestedparties="bgstack15@gmail.com" +tmpdir=/tmp/rbup +mkdir -p "${tmpdir}" 2>/dev/null || { ferror "${script}: 4. Unable to make ${tmpdir} temporary directory. Aborted."; exit 4; } + +# 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<<EOFSENDSH # if $1="1" then setvalout="critical-fail" on failure +#/usr/share/bgscripts/send.sh -hs # setvalout maybe be "fail" otherwise +#/usr/local/bin/send.sh -hs # on success, setvalout="valid-sendsh" +#/usr/bin/mail -s +#EOFSENDSH +#test "${setvalout}" = "critical-fail" && ferror "${scriptfile}: 4. mailer not found. Aborted." && exit 4 + +# 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 2; +#then +# ferror "${scriptfile}: 2. Fewer than 2 flaglessvals. Aborted." +# exit 2 +#fi + +# CONFIGURE VARIABLES AFTER PARAMETERS + +## START READ CONFIG FILE TEMPLATE +get_conf /home/bgirton-local/rpmbuild/SOURCES/rbup-0.0-1/etc/rbup/rbup.conf +#oIFS="${IFS}"; IFS="$( printf '\n' )" +#infiledata=$( ${sed} ':loop;/^\/\*/{s/.//;:ccom;s,^.[^*]*,,;/^$/n;/^\*\//{s/..//;bloop;};bccom;}' "${infile1}") #the crazy sed removes c style multiline comments +#IFS="${oIFS}"; infilelines=$( echo "${infiledata}" | wc -l ) +#{ echo "${infiledata}"; echo "ENDOFFILE"; } | { +# while read line; do +# # the crazy sed removes leading and trailing whitespace, blank lines, and comments +# if test ! "${line}" = "ENDOFFILE"; +# then +# line=$( echo "${line}" | sed -e 's/^\s*//;s/\s*$//;/^[#$]/d;s/\s*[^\]#.*$//;' ) +# if test -n "${line}"; +# then +# debuglev 8 && ferror "line=\"${line}\"" +# if echo "${line}" | grep -qiE "\[.*\]"; +# then +# # new zone +# zone=$( echo "${line}" | tr -d '[]' ) +# debuglev 7 && ferror "zone=${zone}" +# else +# # directive +# varname=$( echo "${line}" | awk -F= '{print $1}' ) +# varval=$( echo "${line}" | awk -F= '{$1=""; printf "%s", $0}' | sed 's/^ //;' ) +# debuglev 7 && ferror "${zone}${varname}=\"${varval}\"" +# # simple define variable +# eval "${zone}${varname}=\${varval}" +# fi +# ## this part is untested +# #read -p "Please type something here:" response < ${thistty} +# #echo "${response}" +# fi +# else + +## REACT TO BEING A CRONJOB +#if test ${is_cronjob} -eq 1; +#then +# [ ] +#else +# [ ] +#fi + +# SET TRAPS +trap "CTRLC" 2 +#trap "CTRLZ" 18 +trap "clean_rbup" 0 + +# MAIN LOOP +#{ + [ ] + for word in $( cd "${tmpdir}"; find -type f -regextype grep ! -regex './default.conf' ! -regex './cli.conf' ); + do + echo "working on ${word}" + reset_vars + . /tmp/rbup/default.conf + . /tmp/rbup/"${word}" + set | grep -iE "^RBUP_" + done +#} | tee -a ${logfile} + +# EMAIL LOGFILE +#${sendsh} ${sendopts} "${server} ${scriptfile} out" ${logfile} ${interestedparties} + +## STOP THE READ CONFIG FILE +#exit 0 +#fi; done; } |