Fix README text
[carddav-git-backup.git] / backup.sh
1 #!/bin/sh
2 # download vcard contacts into contacts/ and commit them to git
3 set -e
4
5 export GIT_AUTHOR_NAME="vcard backup"
6 export GIT_AUTHOR_EMAIL="vcard-backup@home.cweiske.de"
7 export GIT_COMMITTER_NAME="vcard backup"
8 export GIT_COMMITTER_EMAIL="vcard-backup@home.cweiske.de"
9
10 [ -d contacts ] || mkdir contacts
11
12 cd contacts
13 [ -d .git ] || git init
14 [ -f .gitignore ] || cp ../.gitignore-contacts .gitignore
15
16 if [ ! -f vdirsyncer-config ]; then
17     cp ../vdirsyncer-config.example vdirsyncer-config
18     echo "Adjust contacts/vdirsyncer-config first"
19     exit 1
20 fi
21
22 # commit configuration files if necessary
23 conffiles=".gitignore vdirsyncer-config"
24 metamod=$(git status --porcelain $conffiles)
25 if [ -n "$metamod" ]; then
26     git add $conffiles
27     git commit $conffiles -m 'Update configuration'
28 fi
29
30 # sync and commit vcards
31 vdirsyncer --config=vdirsyncer-config --verbosity WARNING sync
32 numchanged=$(git status --porcelain | wc -l)
33 if [ $numchanged -eq 0 ]; then
34     exit 0
35 fi
36
37 git add .
38 ../create-commit-message.sh > tmp-msg
39 git commit --quiet --file=tmp-msg
40 rm tmp-msg