From 0c4f2b7c4564326c071173a661fab3f83031596c Mon Sep 17 00:00:00 2001 From: zertrin Date: Sat, 30 Sep 2017 22:50:03 +0800 Subject: [PATCH] Improved version parsing. Fix bug on MacOS (thanks @ErebusBat) --- duplicity-backup.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 255283c..739fab3 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -126,12 +126,22 @@ version_compare() { fi } +# set a flag if duplicity's version is lower than 0.7, for usage later in the script version_compare "${DUPLICITY_VERSION}" 0.7 case $? in 2) LT07=1;; *) LT07=0;; esac -# Read the version string from the file VERSION -DBSH_DIRPATH=$(dirname "$(readlink -f "$0")") -DBSH_VERSION=$(<"${DBSH_DIRPATH}/VERSION") +# Read the version string from the file named VERSION in the same directory as the script. +if [[ "$(uname)" == "Darwin" ]]; then + DBSH_VERPATH="$(dirname "$(readlink "$0")")/VERSION" +else + DBSH_VERPATH="$(dirname "$(readlink -f "$0")")/VERSION" +fi + +if [ -r "${DBSH_VERPATH}" ]; then + DBSH_VERSION=$(<"${DBSH_VERPATH}") +else + DBSH_VERSION=unknown +fi version(){ echo "duplicity-backup.sh ${DBSH_VERSION}"