From fdc71ceda3adb23b28c8fb19ab6ddee9ff14b724 Mon Sep 17 00:00:00 2001 From: deajan Date: Thu, 14 Apr 2016 18:01:18 +0200 Subject: [PATCH] Fixed installer paths --- dev/debug_obackup.sh | 87 +++++++++++++++++++++++++++++++++++++++++++- dev/ofunctions.sh | 87 +++++++++++++++++++++++++++++++++++++++++++- install.sh | 14 +++---- obackup.sh | 86 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 261 insertions(+), 13 deletions(-) diff --git a/dev/debug_obackup.sh b/dev/debug_obackup.sh index f34e70a..f36dbe4 100755 --- a/dev/debug_obackup.sh +++ b/dev/debug_obackup.sh @@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre PROGRAM_BUILD=2016041201 IS_STABLE=no -## FUNC_BUILD=2016041202 +## FUNC_BUILD=2016041402 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -102,7 +102,7 @@ function _Logger { # Special case in daemon mode where systemctl doesn't need double timestamps if [ "$sync_on_changes" == "1" ]; then cat <<< "$evalue" 1>&2 # Log to stderr in daemon mode - elif [ $_SILENT -eq 0 ]; then + elif [ "$_SILENT" -eq 0 ]; then echo -e "$svalue" fi } @@ -181,6 +181,7 @@ function KillChilds { fi } +# Script specific email alert function, please use SendEmail function for generic sends function SendAlert { __CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG @@ -302,6 +303,85 @@ function SendAlert { fi } +# Generic email sending function. Usage: +# SendEmail "subject" "Body text" "receiver@email.fr receiver2@otheremail.fr" "/path/to/attachment.file" +function SendEmail { + local subject="${1}" + local message="${2}" + local destination_mails="${3}" + local attachment="{$4}" + + __CheckArguments 4 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG + + local mail_no_attachment= + local attachment_command= + + if [ ! -f "$attachment" ]; then + attachment_command="-a $ALERT_LOG_FILE" + mail_no_attachment=1 + else + mail_no_attachment=0 + fi + + if type mutt > /dev/null 2>&1 ; then + echo "$message" | $(type -p mutt) -x -s "$subject" "$destination_mails" $attachment_command + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN" + else + Logger "Sent alert mail using mutt." "NOTICE" + return 0 + fi + fi + + if type mail > /dev/null 2>&1 ; then + if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then + attachment_command="-A $attachment" + elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then + attachment_command="-a$attachment" + else + attachment_command="" + fi + echo "$message" | $(type -p mail) $attachment_command -s "$subject" "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN" + echo "$message" | $(type -p mail) -s "$subject" "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN" + else + Logger "Sent alert mail using mail command without attachment." "NOTICE" + return 0 + fi + else + Logger "Sent alert mail using mail command." "NOTICE" + return 0 + fi + fi + + if type sendmail > /dev/null 2>&1 ; then + echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN" + else + Logger "Sent alert mail using sendmail command without attachment." "NOTICE" + return 0 + fi + fi + + # pfSense specific + if [ -f /usr/local/bin/mail.php ]; then + echo "$message" | /usr/local/bin/mail.php -s="$subject" + if [ $? != 0 ]; then + Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN" + else + Logger "Sent alert mail using pfSense mail.php." "NOTICE" + return 0 + fi + fi + + # If function has not returned 0 yet, assume it's critical that no alert can be sent + Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue +} + function TrapError { local job="$0" local line="$1" @@ -366,10 +446,12 @@ function Spinner { esac } +# obsolete, use StripQuotes function SedStripQuotes { echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g") } +# Usage: var=$(StripSingleQuotes "$var") function StripSingleQuotes { local string="${1}" string="${string/#\'/}" # Remove singlequote if it begins string @@ -377,6 +459,7 @@ function StripSingleQuotes { echo "$string" } +# Usage: var=$(StripDoubleQuotes "$var") function StripDoubleQuotes { local string="${1}" string="${string/#\"/}" diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index dcbee15..3a97b5f 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,4 +1,4 @@ -## FUNC_BUILD=2016041202 +## FUNC_BUILD=2016041402 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -92,7 +92,7 @@ function _Logger { # Special case in daemon mode where systemctl doesn't need double timestamps if [ "$sync_on_changes" == "1" ]; then cat <<< "$evalue" 1>&2 # Log to stderr in daemon mode - elif [ $_SILENT -eq 0 ]; then + elif [ "$_SILENT" -eq 0 ]; then echo -e "$svalue" fi } @@ -171,6 +171,7 @@ function KillChilds { fi } +# Script specific email alert function, please use SendEmail function for generic sends function SendAlert { __CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG @@ -292,6 +293,85 @@ function SendAlert { fi } +# Generic email sending function. Usage: +# SendEmail "subject" "Body text" "receiver@email.fr receiver2@otheremail.fr" "/path/to/attachment.file" +function SendEmail { + local subject="${1}" + local message="${2}" + local destination_mails="${3}" + local attachment="{$4}" + + __CheckArguments 4 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG + + local mail_no_attachment= + local attachment_command= + + if [ ! -f "$attachment" ]; then + attachment_command="-a $ALERT_LOG_FILE" + mail_no_attachment=1 + else + mail_no_attachment=0 + fi + + if type mutt > /dev/null 2>&1 ; then + echo "$message" | $(type -p mutt) -x -s "$subject" "$destination_mails" $attachment_command + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN" + else + Logger "Sent alert mail using mutt." "NOTICE" + return 0 + fi + fi + + if type mail > /dev/null 2>&1 ; then + if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then + attachment_command="-A $attachment" + elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then + attachment_command="-a$attachment" + else + attachment_command="" + fi + echo "$message" | $(type -p mail) $attachment_command -s "$subject" "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN" + echo "$message" | $(type -p mail) -s "$subject" "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN" + else + Logger "Sent alert mail using mail command without attachment." "NOTICE" + return 0 + fi + else + Logger "Sent alert mail using mail command." "NOTICE" + return 0 + fi + fi + + if type sendmail > /dev/null 2>&1 ; then + echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN" + else + Logger "Sent alert mail using sendmail command without attachment." "NOTICE" + return 0 + fi + fi + + # pfSense specific + if [ -f /usr/local/bin/mail.php ]; then + echo "$message" | /usr/local/bin/mail.php -s="$subject" + if [ $? != 0 ]; then + Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN" + else + Logger "Sent alert mail using pfSense mail.php." "NOTICE" + return 0 + fi + fi + + # If function has not returned 0 yet, assume it's critical that no alert can be sent + Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue +} + function TrapError { local job="$0" local line="$1" @@ -356,10 +436,12 @@ function Spinner { esac } +# obsolete, use StripQuotes function SedStripQuotes { echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g") } +# Usage: var=$(StripSingleQuotes "$var") function StripSingleQuotes { local string="${1}" string="${string/#\'/}" # Remove singlequote if it begins string @@ -367,6 +449,7 @@ function StripSingleQuotes { echo "$string" } +# Usage: var=$(StripDoubleQuotes "$var") function StripDoubleQuotes { local string="${1}" string="${string/#\"/}" diff --git a/install.sh b/install.sh index fb6f59e..75769b0 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ PROGRAM=obackup PROGRAM_VERSION=2.0-pre PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BATCH=$PROGRAM"-batch.sh" -SCRIPT_BUILD=2016040801 +SCRIPT_BUILD=2016041401 ## osync / obackup / pmocr / zsnap install script ## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10 @@ -78,20 +78,20 @@ else echo "Config directory [$CONF_DIR] exists." fi -if [ -f "./sync.conf" ]; then - cp "./sync.conf" "/etc/$PROGRAM/sync.conf.example" +if [ -f "./sync.conf.example" ]; then + cp "./sync.conf.example" "/etc/$PROGRAM/sync.conf.example" fi -if [ -f "./host_backup.conf" ]; then - cp "./host_backup.conf" "/etc/$PROGRAM/host_backup.conf.example" +if [ -f "./host_backup.conf.example" ]; then + cp "./host_backup.conf.example" "/etc/$PROGRAM/host_backup.conf.example" fi if [ -f "./exlude.list.example" ]; then cp "./exclude.list.example" "/etc/$PROGRAM" fi -if [ -f "./snapshot.conf" ]; then - cp "./snapshot.conf" "/etc/$PROGRAM/snapshot.conf.example" +if [ -f "./snapshot.conf.example" ]; then + cp "./snapshot.conf.example" "/etc/$PROGRAM/snapshot.conf.example" fi cp "./$PROGRAM_BINARY" "$BIN_DIR" diff --git a/obackup.sh b/obackup.sh index 775b369..875802f 100755 --- a/obackup.sh +++ b/obackup.sh @@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre PROGRAM_BUILD=2016041201 IS_STABLE=no -## FUNC_BUILD=2016041202 +## FUNC_BUILD=2016041402 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -97,7 +97,7 @@ function _Logger { # Special case in daemon mode where systemctl doesn't need double timestamps if [ "$sync_on_changes" == "1" ]; then cat <<< "$evalue" 1>&2 # Log to stderr in daemon mode - elif [ $_SILENT -eq 0 ]; then + elif [ "$_SILENT" -eq 0 ]; then echo -e "$svalue" fi } @@ -170,6 +170,7 @@ function KillChilds { fi } +# Script specific email alert function, please use SendEmail function for generic sends function SendAlert { local mail_no_attachment= @@ -290,6 +291,84 @@ function SendAlert { fi } +# Generic email sending function. Usage: +# SendEmail "subject" "Body text" "receiver@email.fr receiver2@otheremail.fr" "/path/to/attachment.file" +function SendEmail { + local subject="${1}" + local message="${2}" + local destination_mails="${3}" + local attachment="{$4}" + + + local mail_no_attachment= + local attachment_command= + + if [ ! -f "$attachment" ]; then + attachment_command="-a $ALERT_LOG_FILE" + mail_no_attachment=1 + else + mail_no_attachment=0 + fi + + if type mutt > /dev/null 2>&1 ; then + echo "$message" | $(type -p mutt) -x -s "$subject" "$destination_mails" $attachment_command + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN" + else + Logger "Sent alert mail using mutt." "NOTICE" + return 0 + fi + fi + + if type mail > /dev/null 2>&1 ; then + if [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V | grep "GNU" > /dev/null; then + attachment_command="-A $attachment" + elif [ "$mail_no_attachment" -eq 0 ] && $(type -p mail) -V > /dev/null; then + attachment_command="-a$attachment" + else + attachment_command="" + fi + echo "$message" | $(type -p mail) $attachment_command -s "$subject" "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN" + echo "$message" | $(type -p mail) -s "$subject" "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN" + else + Logger "Sent alert mail using mail command without attachment." "NOTICE" + return 0 + fi + else + Logger "Sent alert mail using mail command." "NOTICE" + return 0 + fi + fi + + if type sendmail > /dev/null 2>&1 ; then + echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) "$destination_mails" + if [ $? != 0 ]; then + Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN" + else + Logger "Sent alert mail using sendmail command without attachment." "NOTICE" + return 0 + fi + fi + + # pfSense specific + if [ -f /usr/local/bin/mail.php ]; then + echo "$message" | /usr/local/bin/mail.php -s="$subject" + if [ $? != 0 ]; then + Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN" + else + Logger "Sent alert mail using pfSense mail.php." "NOTICE" + return 0 + fi + fi + + # If function has not returned 0 yet, assume it's critical that no alert can be sent + Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue +} + function TrapError { local job="$0" local line="$1" @@ -353,10 +432,12 @@ function Spinner { esac } +# obsolete, use StripQuotes function SedStripQuotes { echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g") } +# Usage: var=$(StripSingleQuotes "$var") function StripSingleQuotes { local string="${1}" string="${string/#\'/}" # Remove singlequote if it begins string @@ -364,6 +445,7 @@ function StripSingleQuotes { echo "$string" } +# Usage: var=$(StripDoubleQuotes "$var") function StripDoubleQuotes { local string="${1}" string="${string/#\"/}"