aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Christian Pohle2021-09-06 18:08:17 +0200
committerMax Christian Pohle2021-09-06 18:08:17 +0200
commitc62a80a6dd9936226dab4ed205c60f12489d8c65 (patch)
tree8dadac8c437844ffa9b3597650d4a86b8912e548
downloadvcf-to-bday-ics-c62a80a6dd9936226dab4ed205c60f12489d8c65.tar.bz2
vcf-to-bday-ics-c62a80a6dd9936226dab4ed205c60f12489d8c65.zip
First working version
tested under FreeBSD 13
-rw-r--r--bday.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/bday.sh b/bday.sh
new file mode 100644
index 0000000..da4daf8
--- /dev/null
+++ b/bday.sh
@@ -0,0 +1,42 @@
1#!/bin/sh -x
2# tested under FreeBSD 13
3
4for requirement in "curl" "awk" "uuidgen"; do
5 which $requirement 2>/dev/null || (echo $requirement not found. please install it. && exit)
6done
7
8test -d $1 || (echo The first parameter has to be the name of a directory with vcf-files in it. && exit)
9
10NOW=`date +%Y%m%dT%H%M%SZ`
11
12test -z "$NOW" && (echo could not determine the current date, the date command is incompatible. && exit)
13
14for filename in $1/*.vcf; do
15
16 eval `awk -F':' 'BEGIN{RS="\r\n"} /FN:/{fn=$2} /BDAY:/{bday=$2} END{printf "export FN=\"%s\" BDAY=\"%s\"\n", fn, bday}' $filename`
17
18 if ! test -z "$BDAY" && ! test -z "$FN" ; then
19
20 AGE=$(expr `date +%Y` - `date -juf '%Y-%m-%d' $BDAY +%Y` || echo 0)
21 DAY=`date -juf '%Y-%m-%d' $BDAY +%Y%m%dT000000Z`
22 UUID=`uuidgen`
23
24 if ! test -z "$AGE" && test "$AGE" -gt 0 && ! test -z "$DAY" && ! test -z "$UUID" ; then
25 printf '%02d %s %s\n' "$AGE" "$BDAY" "$FN"
26
27cat <<-EOF > BD-$UUID.ics
28BEGIN:VCALENDAR
29VERSION:2.0
30BEGIN:VEVENT
31CREATED:$NOW
32UID:$UUID
33SUMMARY:$FN $AGE birthday
34DTSTART;VALUE=DATE:$DAY
35RRULE:FREQ=YEARLY
36DESCRIPTION:$DESCRIPTION
37END:VEVENT
38END:VCALENDAR
39EOF
40 fi
41 fi
42done
..