sync.sh: remove uuidgen dependancy (static MIME string)

This commit is contained in:
2022-04-23 13:37:55 +02:00
parent 1b818570c2
commit 3699e9f9eb

View File

@@ -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).
@@ -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,12 +315,18 @@ 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
# we prepare attachment only if a mark line was found
if (( has_mark_line == 1 )); then
printf "\n--%s\n" "$MIMESTR" printf "\n--%s\n" "$MIMESTR"
if [[ "$ZIPMAIL" == cat ]]; then if [[ "$ZIPMAIL" == cat ]]; then
printf 'Content-Type: text/plain; charset=UTF-8\n' printf 'Content-Type: text/plain; charset=UTF-8\n'
@@ -333,6 +338,7 @@ exit_handler() {
printf "Content-Transfer-Encoding: base64\n" printf "Content-Transfer-Encoding: base64\n"
printf '\n' printf '\n'
$ZIPMAIL | base64 $ZIPMAIL | base64
fi
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).