-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimport-contacts.sh
More file actions
executable file
·42 lines (40 loc) · 900 Bytes
/
Copy pathimport-contacts.sh
File metadata and controls
executable file
·42 lines (40 loc) · 900 Bytes
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
#!/bin/bash
F=
PHOTO=
while IFS= read -r line; do
line="${line%%[[:space:]]}"
if [ -n "$PHOTO" ] ; then
if [[ "$line" =~ ^" " ]] ; then
PHOTO="${PHOTO}${line##[[:space:]]}"
continue
fi
echo -n "PHOTO;ENCODING=b;TYPE=jpeg:" >> $F
curl -o - -s --show-error "$PHOTO" | base64 -w0 >> $F
echo "" >> $F
PHOTO=
fi
if [ "$line" = "BEGIN:VCARD" ] ; then
uid=`uuidgen`
uid=${uid%%[[:space:]]}
F=$uid.vcf
echo "$line" > $F
continue
fi
if [[ "$line" =~ ^"VERSION:" ]] ; then
echo "$line" >> $F
echo UID:$uid >> $F
continue
fi
if [ "$line" = "END:VCARD" ] ; then
echo REV:`date --iso-8601=seconds --utc | sed 's/+00:00$/Z/'` >> $F
echo X-RADICALE-NAME:$F >> $F
echo "$line" >> $F
F=
continue
fi
if [[ "$line" =~ ^"PHOTO:" ]] ; then
PHOTO="${line#PHOTO:}"
continue
fi
echo "$line" >> $F
done