diff -r 2c10a7d30ffd -r 66728b983b41 vcs-backup.sh --- a/vcs-backup.sh Sat Apr 20 20:20:32 2019 +0200 +++ b/vcs-backup.sh Sat Apr 20 22:17:38 2019 +0200 @@ -63,6 +63,15 @@ echo "$1" | sed -E 's@^[^:]+://@@g'; } +# Environment: all +# $1 = optional value (if missing, reads STDIN) +escapeRecfileValue() { if [[ $# = 0 ]]; then awk '{ if (NR > 1) { printf "+ " } print $_ }'; else echo "${@}" | ${FUNCNAME[0]}; fi } + +# Environment: all +# $1 = key +# $2 = value +printRecfileKeyValue() { echo -n "$1: "; escapeRecfileValue "$2"; } + # --- Public interface functions: ------------------------------------------------------------------ # Environment: client @@ -180,13 +189,13 @@ elif [[ "$vcsType" == "git" ]]; then lastCommit=$(git -C "$VCS_BACKUP_CURRENT_DIR/$d" log --max-count=1 --pretty="%ai"); else lastCommit=""; fi - echo "type: $vcsType"; - echo "url: $url"; - echo "state: $state"; - echo "public: $public"; - echo "serverPath: $VCS_BACKUP_CURRENT_DIR/$d"; - echo "size: $sizeBytes"; - echo "lastCommit: $lastCommit"; + printRecfileKeyValue "type" "$vcsType"; + printRecfileKeyValue "url" "$url"; + printRecfileKeyValue "state" "$state"; + printRecfileKeyValue "public" "$public"; + printRecfileKeyValue "serverPath" "$VCS_BACKUP_CURRENT_DIR/$d"; + printRecfileKeyValue "size" "$sizeBytes"; + printRecfileKeyValue "lastCommit" "$lastCommit"; echo; done }