4f90cc7440d7b06c6106112ca70d08f53e524317

Author
Matthias Rampke <matthias@rampke.de>
Committer
Matthias Rampke <matthias@rampke.de>
Date

Message

add support for DragonFly and OpenBSD

DragonFly is a FreeBSD derivative, so the same `du` flags as for FreeBSD
and Darwin apply. OpenBSD does not support exclusion.

The correct invocation for in-place `sed` without backup varies. GNU Sed
allows just leaving out the suffix, but BSD Sed requires an empty suffix
(which in turn GNU Sed doesn't accept). OpenBSD Sed has no in-place
option, use `ed` instead.

`mail` works the same on all BSD.

explicitly list `bash` dependency, it's not installed on most BSD by default.

Diff

 1diff --git a/README.md b/README.md
 2index 6f2ef92524076dea3c1c0392a1dea6ae43659d20..01fe4a3a8dbc69c44348c76f35d8bd6ac5d4404b 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -36,7 +36,7 @@ Be sure to make the script executable (`chmod +x`) before you hit the gas.
 6 ## Requirements
 7 
 8 * [duplicity](http://duplicity.nongnu.org/)
 9-* Basic utilities like: [which](http://unixhelp.ed.ac.uk/CGI/man-cgi?which) and [tee](http://linux.die.net/man/1/tee) (should already be available on most Linux systems)
10+* Basic utilities like: [bash](https://www.gnu.org/software/bash/), [which](http://unixhelp.ed.ac.uk/CGI/man-cgi?which) and [tee](http://linux.die.net/man/1/tee) (should already be available on most Linux systems)
11 * [gpg](http://www.gnupg.org/) *`optional`*
12 * [Amazon S3](http://aws.amazon.com/s3/) *`optional`*
13 * [s3cmd](http://s3tools.org/s3cmd) *`optional`*
14diff --git a/duplicity-backup.sh b/duplicity-backup.sh
15index 75a67a213fce89c7a063bc8a446723faaa860fb9..3123510f679a83f94d0d5d64b3486d4e2673b6e9 100755
16--- a/duplicity-backup.sh
17+++ b/duplicity-backup.sh
18@@ -297,11 +297,14 @@ email_logfile()
19             EMAIL_FROM=${EMAIL_FROM:+"-r ${EMAIL_FROM}"}
20             cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO}
21           elif [ "$MAIL" = "mail" ]; then
22-            if [[ `uname` == "FreeBSD" || `uname` == 'Darwin' ]]; then
23-               cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" ${EMAIL_TO} --
24-            else
25+            case `uname` in
26+              FreeBSD|Darwin|DragonFly|OpenBSD)
27+                cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" ${EMAIL_TO} --
28+                ;;
29+              *)
30                cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO} -- -f ${EMAIL_FROM}
31-            fi
32+               ;;
33+            esac
34           elif [[ "$MAIL" = "sendmail" ]]; then
35             (echo """Subject: ${EMAIL_SUBJECT}""" ; cat ${LOGFILE}) | ${MAILCMD} -f ${EMAIL_FROM} ${EMAIL_TO}
36           elif [ "$MAIL" = "nail" ]; then
37@@ -337,10 +340,18 @@ get_source_file_size()
38   OLDIFS=$IFS
39   IFS=$(echo -en "\t\n")
40 
41-  DUEXCFLAG="--exclude-from="
42-  if [[ `uname` == 'FreeBSD' || `uname` == 'Darwin' ]]; then
43-     DUEXCFLAG="-I "
44-  fi
45+  case `uname` in
46+    FreeBSD|Darwin|DragonFly)
47+     DUEXCFLAG="-I -"
48+     ;;
49+   OpenBSD)
50+     echo "WARNING: OpenBSD du does not support exclusion, sizes may be off" >> ${LOGFILE}
51+     DUEXCFLAG=""
52+     ;;
53+   *)
54+    DUEXCFLAG="--exclude-from=-"
55+    ;;
56+esac
57 
58   for exclude in ${EXCLIST[@]}; do
59     DUEXCLIST="${DUEXCLIST}${exclude}\n"
60@@ -349,7 +360,7 @@ get_source_file_size()
61   for include in ${INCLIST[@]}
62     do
63       echo -e '"'$DUEXCLIST'"' | \
64-      du -hs ${DUEXCFLAG}"-" ${include} | \
65+      du -hs ${DUEXCFLAG} ${include} | \
66       awk '{ FS="\t"; $0=$0; print $1"\t"$2 }' \
67       >> ${LOGFILE}
68   done
69@@ -479,7 +490,21 @@ get_file_sizes()
70   get_source_file_size
71   get_remote_file_size
72 
73-  sed -i -e '/^--*$/d' ${LOGFILE}
74+  case `uname` in
75+    FreeBSD|Darwin|DragonFly)
76+      sed -i '' -e '/^--*$/d' ${LOGFILE}
77+      ;;
78+    OpenBSD)
79+      ed -s ${LOGFILE} <<-"EOF"
80+      g/^--*$/d
81+      w
82+      q
83+EOF
84+      ;;
85+    *)
86+      sed -i -e '/^--*$/d' ${LOGFILE}
87+      ;;
88+  esac
89   chown ${LOG_FILE_OWNER} ${LOGFILE}
90 }
91