aboutsummaryrefslogtreecommitdiff
path: root/bday.sh
blob: da4daf862c0340f8eee3a9ff1caa627541959bfc (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
#!/bin/sh -x
# tested under FreeBSD 13

for requirement in "curl" "awk" "uuidgen"; do
        which $requirement 2>/dev/null || (echo $requirement not found. please install it. && exit)
done

test -d $1 || (echo The first parameter has to be the name of a directory with vcf-files in it. && exit)

NOW=`date +%Y%m%dT%H%M%SZ`

test -z "$NOW" && (echo could not determine the current date, the date command is incompatible. && exit)

for filename in $1/*.vcf; do

        eval `awk -F':' 'BEGIN{RS="\r\n"} /FN:/{fn=$2} /BDAY:/{bday=$2} END{printf "export FN=\"%s\" BDAY=\"%s\"\n", fn, bday}' $filename`

        if ! test -z  "$BDAY" && ! test -z "$FN" ; then

                AGE=$(expr `date +%Y` - `date -juf '%Y-%m-%d' $BDAY +%Y` || echo 0)
                DAY=`date -juf '%Y-%m-%d' $BDAY +%Y%m%dT000000Z`
                UUID=`uuidgen`

                if ! test -z "$AGE" && test "$AGE" -gt 0 && ! test -z "$DAY" && ! test -z "$UUID" ; then
                        printf '%02d %s %s\n' "$AGE" "$BDAY" "$FN"

cat <<-EOF >  BD-$UUID.ics
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
CREATED:$NOW
UID:$UUID
SUMMARY:$FN $AGE birthday
DTSTART;VALUE=DATE:$DAY
RRULE:FREQ=YEARLY
DESCRIPTION:$DESCRIPTION
END:VEVENT
END:VCALENDAR
EOF
                fi
        fi
done
..