From 657f828c74dd55b5ecf0419060340e8548e9e7bd Mon Sep 17 00:00:00 2001 From: deajan Date: Tue, 2 Oct 2018 21:21:23 +0200 Subject: [PATCH] Updated common installer and batch --- dev/common_batch.sh | 44 ++++++++++++++----------------------------- dev/common_install.sh | 37 +++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/dev/common_batch.sh b/dev/common_batch.sh index d01d6e7..508c8ac 100755 --- a/dev/common_batch.sh +++ b/dev/common_batch.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash SUBPROGRAM=[prgname] PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones -AUTHOR="(L) 2013-2017 by Orsiris de Jong" +AUTHOR="(L) 2013-2018 by Orsiris de Jong" CONTACT="http://www.netpower.fr - ozy@netpower.fr" -PROGRAM_BUILD=2016120401 +PROGRAM_BUILD=2018100201 ## Runs an osync /obackup instance for every conf file found ## If an instance fails, run it again if time permits @@ -26,36 +26,20 @@ else LOG_FILE=./$SUBPROGRAM-batch.log fi +## Default directory where to store temporary run files +if [ -w /tmp ]; then + RUN_DIR=/tmp +elif [ -w /var/tmp ]; then + RUN_DIR=/var/tmp +else + RUN_DIR=. +fi + +trap TrapQuit TERM EXIT HUP QUIT + # No need to edit under this line ############################################################## -function _logger { - local value="${1}" # What to log - echo -e "$value" >> "$LOG_FILE" -} - -function Logger { - local value="${1}" # What to log - local level="${2}" # Log level: DEBUG, NOTICE, WARN, ERROR, CRITIAL - - prefix="$(date) - " - - if [ "$level" == "CRITICAL" ]; then - _logger "$prefix\e[41m$value\e[0m" - elif [ "$level" == "ERROR" ]; then - _logger "$prefix\e[91m$value\e[0m" - elif [ "$level" == "WARN" ]; then - _logger "$prefix\e[93m$value\e[0m" - elif [ "$level" == "NOTICE" ]; then - _logger "$prefix$value" - elif [ "$level" == "DEBUG" ]; then - if [ "$DEBUG" == "yes" ]; then - _logger "$prefix$value" - fi - else - _logger "\e[41mLogger function called without proper loglevel.\e[0m" - _logger "$prefix$value" - fi -} +include #### Logger SUBSET #### function CheckEnvironment { ## osync / obackup executable full path can be set here if it cannot be found on the system diff --git a/dev/common_install.sh b/dev/common_install.sh index 4aab2eb..dd43d44 100755 --- a/dev/common_install.sh +++ b/dev/common_install.sh @@ -10,14 +10,14 @@ PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BATCH=$PROGRAM"-batch.sh" SSH_FILTER="ssh_filter.sh" -SCRIPT_BUILD=2018090301 +SCRIPT_BUILD=2018100201 INSTANCE_ID="installer-$SCRIPT_BUILD" ## osync / obackup / pmocr / zsnap install script ## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11 ## Please adapt this to fit your distro needs -include #### _OFUNCTIONS_BOOTSTRAP SUBSET #### +include #### OFUNCTIONS MICRO SUBSET #### # Get current install.sh path from http://stackoverflow.com/a/246128/2635443 SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" @@ -86,7 +86,6 @@ else LOG_FILE="./$PROGRAM-install.log" fi -include #### Logger SUBSET #### include #### UrlEncode SUBSET #### include #### GetLocalOS SUBSET #### include #### GetConfFileValue SUBSET #### @@ -345,19 +344,27 @@ function Usage { exit 127 } +function TrapQuit { + local exitcode=0 + + # Get ERROR / WARN alert flags from subprocesses that call Logger + if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID.$TSTAMP" ]; then + WARN_ALERT=true + exitcode=2 + fi + if [ -f "$RUN_DIR/$PROGRAM.Logger.error.$SCRIPT_PID.$TSTAMP" ]; then + ERROR_ALERT=true + exitcode=1 + fi + + CleanUp + exit $exitcode +} + ############################## Script entry point -if [ "$LOGFILE" == "" ]; then - if [ -w /var/log ]; then - LOG_FILE="/var/log/$PROGRAM.$INSTANCE_ID.log" - elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then - LOG_FILE="$HOME/$PROGRAM.$INSTANCE_ID.log" - else - LOG_FILE="./$PROGRAM.$INSTANCE_ID.log" - fi -else - LOG_FILE="$LOGFILE" -fi +trap TrapQuit TERM EXIT HUP QUIT + if [ ! -w "$(dirname $LOG_FILE)" ]; then echo "Cannot write to log [$(dirname $LOG_FILE)]." else @@ -382,7 +389,7 @@ else if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "pmocr" ]; then CopyServiceFiles fi - Logger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM" "SIMPLE" + Logger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM_BINARY" "SIMPLE" if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then echo "" Logger "If connecting remotely, consider setup ssh filter to enhance security." "SIMPLE"