blob: bf5d570e3e493a73ffc80e34dcd3462ae8e911bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#!/bin/sh
CONFIG_FILE="$(dirname "$0")/config.sh"
[ ! -e "$CONFIG_FILE" ] && {
echo "please create $CONFIG_FILE"
exit 1
}
VDIRSYNCER_PREFIX="$XDG_DATA_HOME/vdirsyncer"
VDIRSYNCER_STATUS_PATH="$VDIRSYNCER_PREFIX/status"
# generate a valid storage/pair name from an invalid one
safeify() { echo "$1" | sha1sum | cut -c1-40 ; }
# safeify() { echo "$1" | tr -c '0-9A-Za-z' '_' | sed 's/_\+/_/g' ; }
[ -z "$EXPORT_LIB" ] && cat << EOF
# THIS FILE IS AUTO-GENERATED AND SHOULD NOT BE SAVED TO DISK!!! Use with
# vdirsyncer by piping the output of this script to a named pipe.
[general]
status_path = "$VDIRSYNCER_STATUS_PATH"
EOF
[ -n "$EXPORT_LIB" ] && _cfg_dav() { true ; }
[ -z "$EXPORT_LIB" ] && _cfg_dav() {
cat << EOF
[pair $ID]
a = "${ID}_local"
b = "${ID}_remote"
collections = ["from a", "from b"]
metadata = ["displayname", "color"]
[storage ${ID}_local]
type = "filesystem"
path = "$VDIRSYNCER_PREFIX/$ID/"
fileext = "$FILEEXT"
[storage ${ID}_remote]
type = "$DAV_TYPE"
url = "$BASE_URL"
EOF
[ -n "$USERNAME" ] && echo "username = \"$USERNAME\""
[ -n "$PASSWORD" ] && echo "password = \"$PASSWORD\""
echo # trailing blank line
}
[ -n "$EXPORT_LIB" ] && _cfg_ical() { true ; }
[ -z "$EXPORT_LIB" ] && _cfg_ical() {
cat << EOF
[pair $ID]
a = "${ID}_remote"
b = "${ID}_local"
collections = null
[storage ${ID}_local]
type = "filesystem"
path = "$VDIRSYNCER_PREFIX/$ID/"
fileext = ".ics"
[storage ${ID}_remote]
type = "http"
url = "${URL}"
EOF
[ -n "$USERNAME" ] && echo "username = \"$USERNAME\""
[ -n "$PASSWORD" ] && echo "password = \"$PASSWORD\""
echo # trailing blank line
}
ical() {
URL="$1"
USERNAME="$2" # optional
PASSWORD="$3" # optional
NAME="${NAME-"$(basename "$URL")"}"
ID="$(safeify "$NAME")"
_cfg_ical
}
caldav() { DAV_TYPE="caldav" dav "$@" ; }
carddav() { DAV_TYPE="carddav" dav "$@" ; }
dav() {
BASE_URL="$1"
USERNAME="$2" # optional
PASSWORD="$3" # optional
ID="$(safeify "$(echo "$BASE_URL$DAV_TYPE" | sed -e 's#^https\?://##' -e 's#/.*##')")"
[ "$DAV_TYPE" = "caldav" ] && FILEEXT=".ics"
[ "$DAV_TYPE" = "carddav" ] && FILEEXT=".vcf"
# only generate specific DAV config if explicitly defined
if [ -n "$DAV_TYPE" ] ; then
_cfg_dav
return
fi
# else generate both
caldav "$@"
carddav "$@"
}
# load "actual" config file
[ -z "$EXPORT_LIB" ] && . "$CONFIG_FILE"
# make inspecting output easier
[ -z "$EXPORT_LIB" ] && printf '# %s:%s=%s\n' vim ft dosini
|