#!/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