sync.sh: remove uuidgen dependancy (static MIME string)
This commit is contained in:
56
bash/sync.sh
56
bash/sync.sh
@@ -77,8 +77,7 @@
|
|||||||
# you should receive an email with the following command :
|
# you should receive an email with the following command :
|
||||||
# echo "Subject: sendmail test" | sendmail -v youremail@example.com
|
# echo "Subject: sendmail test" | sendmail -v youremail@example.com
|
||||||
#
|
#
|
||||||
# Additionnaly, you will also need the "uuidgen", "gzip" and "base64"
|
# Additionnaly, you will also need the "base64" and "gzip" utilities.
|
||||||
# utilities.
|
|
||||||
#
|
#
|
||||||
# CONFIGURATION FILE
|
# CONFIGURATION FILE
|
||||||
# TODO: Write documentation. See example (sync-conf-example.sh).
|
# TODO: Write documentation. See example (sync-conf-example.sh).
|
||||||
@@ -278,7 +277,7 @@ exit_handler() {
|
|||||||
exec 0<<<"" # force empty input for the following
|
exec 0<<<"" # force empty input for the following
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SECS=$(($(date +%s)-STARTTIME))
|
SECS=$(( $(date +%s) - STARTTIME ))
|
||||||
|
|
||||||
# Warning: no logs allowed here (before next braces), as stdout is no
|
# Warning: no logs allowed here (before next braces), as stdout is no
|
||||||
# more handled the final way.
|
# more handled the final way.
|
||||||
@@ -303,7 +302,7 @@ exit_handler() {
|
|||||||
{
|
{
|
||||||
if [[ -n $MAILTO ]]; then
|
if [[ -n $MAILTO ]]; then
|
||||||
{
|
{
|
||||||
MIMESTR=$(uuidgen)
|
MIMESTR="FEDCBA_0987654321"
|
||||||
|
|
||||||
# email header
|
# email header
|
||||||
printf "Subject: %s\n" "${SUBJECT}"
|
printf "Subject: %s\n" "${SUBJECT}"
|
||||||
@@ -316,23 +315,30 @@ exit_handler() {
|
|||||||
printf 'Content-Type: text/plain; charset=UTF-8\n'
|
printf 'Content-Type: text/plain; charset=UTF-8\n'
|
||||||
printf '\n'
|
printf '\n'
|
||||||
|
|
||||||
# send first lines in message body (until the mark line)
|
# send first lines in message body (until the mark line or EOF)
|
||||||
|
has_mark_line=0
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
[[ $line =~ ^\*+\ Mark$ ]] && break
|
if [[ $line =~ ^\*+\ Mark$ ]]; then
|
||||||
|
has_mark_line=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
printf "%s\n" "$line"
|
printf "%s\n" "$line"
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "\n--%s\n" "$MIMESTR"
|
# we prepare attachment only if a mark line was found
|
||||||
if [[ "$ZIPMAIL" == cat ]]; then
|
if (( has_mark_line == 1 )); then
|
||||||
printf 'Content-Type: text/plain; charset=UTF-8\n'
|
printf "\n--%s\n" "$MIMESTR"
|
||||||
printf 'Content-Disposition: attachment; filename="sync-log.txt"\n'
|
if [[ "$ZIPMAIL" == cat ]]; then
|
||||||
else
|
printf 'Content-Type: text/plain; charset=UTF-8\n'
|
||||||
printf "Content-Type: application/gzip\n"
|
printf 'Content-Disposition: attachment; filename="sync-log.txt"\n'
|
||||||
printf 'Content-Disposition: attachment; filename="sync-log.txt.gz"\n'
|
else
|
||||||
|
printf "Content-Type: application/gzip\n"
|
||||||
|
printf 'Content-Disposition: attachment; filename="sync-log.txt.gz"\n'
|
||||||
|
fi
|
||||||
|
printf "Content-Transfer-Encoding: base64\n"
|
||||||
|
printf '\n'
|
||||||
|
$ZIPMAIL | base64
|
||||||
fi
|
fi
|
||||||
printf "Content-Transfer-Encoding: base64\n"
|
|
||||||
printf '\n'
|
|
||||||
$ZIPMAIL | base64
|
|
||||||
printf "\n--%s--\n" "$MIMESTR"
|
printf "\n--%s--\n" "$MIMESTR"
|
||||||
} | sendmail -i -- "${MAILTO}"
|
} | sendmail -i -- "${MAILTO}"
|
||||||
else
|
else
|
||||||
@@ -370,9 +376,17 @@ TODO=()
|
|||||||
log -l -t "Starting $CMDNAME"
|
log -l -t "Starting $CMDNAME"
|
||||||
log "bash version: ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}"
|
log "bash version: ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}"
|
||||||
|
|
||||||
|
log ""
|
||||||
|
log "Hostname: $(hostname)"
|
||||||
|
log "Operating System: $(uname -sr) on $(uname -m)"
|
||||||
|
log "Config : ${CONFIG}"
|
||||||
|
log "Src dir: ${SOURCEDIR}"
|
||||||
|
log "Dst dir: ${SERVER}:${DESTDIR}"
|
||||||
|
log "Actions: ${TODO[*]}"
|
||||||
|
|
||||||
# check availability of necessary commands
|
# check availability of necessary commands
|
||||||
declare -a cmdavail=()
|
declare -a cmdavail=()
|
||||||
for cmd in rsync gzip base64 sendmail uuidgen; do
|
for cmd in rsync gzip base64 sendmail; do
|
||||||
log -n "Checking for $cmd... "
|
log -n "Checking for $cmd... "
|
||||||
if type -p "$cmd" > /dev/null; then
|
if type -p "$cmd" > /dev/null; then
|
||||||
log "ok"
|
log "ok"
|
||||||
@@ -386,14 +400,6 @@ if (( ${#cmdavail[@]} )); then
|
|||||||
error_handler $LINENO 1
|
error_handler $LINENO 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log ""
|
|
||||||
log "Hostname: $(hostname)"
|
|
||||||
log "Operating System: $(uname -sr) on $(uname -m)"
|
|
||||||
log "Config : ${CONFIG}"
|
|
||||||
log "Src dir: ${SOURCEDIR}"
|
|
||||||
log "Dst dir: ${SERVER}:${DESTDIR}"
|
|
||||||
log "Actions: ${TODO[*]}"
|
|
||||||
|
|
||||||
log -s "Mark" # to separate email body
|
log -s "Mark" # to separate email body
|
||||||
|
|
||||||
# select handling depending on local or networked target (ssh or not).
|
# select handling depending on local or networked target (ssh or not).
|
||||||
|
Reference in New Issue
Block a user