From ca132309e2d94a8ec22e9d98728594dbcd431b8b Mon Sep 17 00:00:00 2001 From: B Stack Date: Sun, 21 May 2017 16:37:24 -0400 Subject: release candidate for rbup.sh --- etc/rbup/rbup.conf | 13 +++- usr/share/rbup/rbup.sh | 191 +++++++++++++++++++++++++++++++------------------ 2 files changed, 133 insertions(+), 71 deletions(-) diff --git a/etc/rbup/rbup.conf b/etc/rbup/rbup.conf index 34d3615..157c9f9 100644 --- a/etc/rbup/rbup.conf +++ b/etc/rbup/rbup.conf @@ -5,14 +5,20 @@ # flags given to rbup.sh RBUP_NOW="$( date "+%Y-%m-%dT%H%M%S" )" RBUP_SYNC_CMD=/bin/rsync -RBUP_SYNC_OPTS="-rlptgODwhatever" +RBUP_SYNC_OPTS="-rlptgoDEA" RBUP_SYNC_OPT_VERBOSE="-v" -RBUP_SYNC_OPT_APPLY="-n" -RBUP_DEST_MOUNT_CMD="mount -v jonathan:/volume1/sword /mnt/jonathan/" +RBUP_SYNC_OPT_NOT_VERBOSE="" +RBUP_SYNC_OPT_APPLY="" +RBUP_SYNC_OPT_NOT_APPLY="-n" +RBUP_DEST_MOUNT_CMD="mount jonathan:/volume1/sword /mnt/jonathan/" RBUP_DEST_UMOUNT_CMD="umount -l /mnt/jonathan/" RBUP_DEST=/mnt/jonathan RBUP_LOG_DIR=/var/log/rbup +# RBUP_ENABLED value determines if the actual operation occurs. +#if true, will use the SYNC_OPT_NOT_APPLY option +RBUP_ENABLED=yes + RBUP_VERBOSE=yes # can be overridden by the -v/-q flag or by the job options # JOB SPECIFIC VALUES @@ -22,3 +28,4 @@ RBUP_CHECKSUM_COUNT=1 RBUP_CHECKSUM_1_FILE="/var/storage1/shares/public/Age Of Empires/Installing-AoFE-on-Linux 2016-01-29.odt" RBUP_CHECKSUM_1_SHA256SUM=407ad21ce6b6ddb9a7f6a907134155431306a6b0450fedc3981d65311ff91c06 RBUP_LOG_FILE=${RBUP_LOG_DIR}/${RBUP_JOB_NAME}.${RBUP_NOW}.log +#RBUP_LOG_FILE=/dev/null diff --git a/usr/share/rbup/rbup.sh b/usr/share/rbup/rbup.sh index c5b9608..aed4876 100755 --- a/usr/share/rbup/rbup.sh +++ b/usr/share/rbup/rbup.sh @@ -13,6 +13,7 @@ # /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: +# provide a reverse-direction listing-only mechanism fiversion="2017-04-29a" rbupversion="2017-05-21a" @@ -31,8 +32,9 @@ Return values: 3 Incorrect OS type 4 Unable to find dependency 5 Not run as root or sudo -6 Unable to mount destination +6 Already running or problem with lockfile or log dir 7 Invalid checksum(s) on file(s) +8 Unable to mount destination or checksum mismatch ENDUSAGE } @@ -50,16 +52,11 @@ get_conf() { /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 + fistruthy "${RBUP_NO_CLEANUP}" || rm -rf "${tmpdir}" "${lockfile}" 1>/dev/null 2>&1 : } @@ -83,7 +80,10 @@ parseFlag() { "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}";; + "c" | "conf" | "config" | "conffile" ) getval; conffile="${tempval}";; + "r" | "n" | "dry" | "dryrun" ) export RBUP_ENABLED=no;; + "a" | "apply" ) export RBUP_ENABLED=yes;; + "clean" ) clean_rbup; exit 0;; esac debuglev 10 && { test ${hasval} -eq 1 && ferror "flag: ${flag} = ${tempval}" || ferror "flag: ${flag}"; } @@ -91,17 +91,7 @@ parseFlag() { # 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 @@ -113,8 +103,11 @@ test -z "${frameworkscript}" && echo "$0: framework not found. Aborted." 1>&2 && . ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2 infile1= outfile1= -logfile=${scriptdir}/${scripttrim}.${today}.out +default_conffile=/home/bgirton-local/rpmbuild/SOURCES/rbup-0.0-1/etc/rbup/rbup.conf +conffile="${default_conffile}" +logfile=${scriptdir}/${scripttrim}.${today}.out # not used here. See RBUP_LOG_FILE interestedparties="bgstack15@gmail.com" +lockfile=/tmp/.rbup.lock # REACT TO OPERATING SYSTEM TYPE case $( uname -s ) in @@ -123,18 +116,18 @@ case $( uname -s ) in *) 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 +# 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< "${lockfile}" +fi + +if ! mkdir -p "${RBUP_LOG_DIR}"; +then + ferror "Could not make log dir ${RBUP_LOG_DIR}. Aborted." + exit 6 +fi + # MAIN LOOP -#{ - [ ] - set | grep -iE "^RBUP_" -#} | tee -a ${logfile} +{ + flecho "${scripttrim} STARTED" + + # Show used values + debuglev 5 && { + ferror "Using values" + # used values: RBUP_(NOW|SYNC_CMD|SYNC_OPTS|SYNC_OPT_VERBOSE|SYNC_OPT_APPLY|DEST_MOUNT_CMD|DEST_UMOUNT_CMD|DEST|LOG_DIR|VERBOSE|JOB_NAME|SOURCE|CHECKSUM_COUNT|CHECKSUM_1_FILE|CHECKSUM_1_SHA256SUM|LOG_FILE|NO_CLEANUP)" + set | grep -iE "^RBUP_" 1>&2 + } + + # flow: + # 1. confirm checksums are valid + # 2. mount dest + # 3. execute rsync + # 4. umount dest + + # Confirm checksums are valid before running mount command + _x=0 + if test -n "${RBUP_CHECKSUM_COUNT}" && fisnum "${RBUP_CHECKSUM_COUNT}"; + then + while test ${_x} -lt ${RBUP_CHECKSUM_COUNT}; + do + _x=$(( _x + 1 )) + eval thischeckedfile=\"\${RBUP_CHECKSUM_${_x}_FILE}\" + eval thissum=\"\${RBUP_CHECKSUM_${_x}_SHA256SUM}\" + thischeckedfilesum="$( /bin/sha256sum "${thischeckedfile}" | awk '{print $1}' )" + if test ! "${thischeckedfilesum}" = "${thissum}"; + then + ferror "ERROR 8. Checksum mismatch for ${thischeckedfile}." + ferror "Expected checksum: \"${thissum}\"" + ferror "Actual checksum: \"${thischeckedfilesum}\"" + ferror "Aborted." + exit 8 + else + debuglev 4 && ferror "Checksum valid for ${thischeckedfile}." + fi + done + fi + + # Mount destination + if test -n "${RBUP_DEST_MOUNT_CMD}"; + then + ${RBUP_DEST_MOUNT_CMD} && debuglev 2 && ferror "Mount successful." + fi + + # Determine apply and verbose states + applystate="${RBUP_SYNC_OPT_NOT_APPLY}" + verbosestate="${RBUP_SYNC_OPT_NOT_VERBOSE}" + fistruthy "${RBUP_ENABLED}" && applystate="${RBUP_SYNC_OPT_APPLY}" + fistruthy "${RBUP_VERBOSE}" && verbosestate="${RBUP_SYNC_OPT_VERBOSE}" + + fullcommand="$( echo "${RBUP_SYNC_CMD} ${RBUP_SYNC_OPTS} ${applystate} ${verbosestate} ${RBUP_SOURCE} ${RBUP_DEST}" | sed -r -e 's/[[:space:]]+/ /g;' )" + debuglev 1 && ferror "${fullcommand}" + + # Unmount destination + if test -n "${RBUP_DEST_UMOUNT_CMD}"; + then + ${RBUP_DEST_UMOUNT_CMD} && debuglev 2 && ferror "Umount successful." + fi + + flecho "${scripttrim} STOPPED" + +} | tee -a ${RBUP_LOG_FILE} # EMAIL LOGFILE #${sendsh} ${sendopts} "${server} ${scriptfile} out" ${logfile} ${interestedparties} -- cgit