From c62a80a6dd9936226dab4ed205c60f12489d8c65 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Mon, 6 Sep 2021 18:08:17 +0200 Subject: First working version tested under FreeBSD 13 --- bday.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bday.sh diff --git a/bday.sh b/bday.sh new file mode 100644 index 0000000..da4daf8 --- /dev/null +++ b/bday.sh @@ -0,0 +1,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 -- cgit v1.2.3