diff options
| -rw-r--r-- | bday.sh | 42 |
1 files changed, 42 insertions, 0 deletions
| @@ -0,0 +1,42 @@ | |||
| 1 | #!/bin/sh -x | ||
| 2 | # tested under FreeBSD 13 | ||
| 3 | |||
| 4 | for requirement in "curl" "awk" "uuidgen"; do | ||
| 5 | which $requirement 2>/dev/null || (echo $requirement not found. please install it. && exit) | ||
| 6 | done | ||
| 7 | |||
| 8 | test -d $1 || (echo The first parameter has to be the name of a directory with vcf-files in it. && exit) | ||
| 9 | |||
| 10 | NOW=`date +%Y%m%dT%H%M%SZ` | ||
| 11 | |||
| 12 | test -z "$NOW" && (echo could not determine the current date, the date command is incompatible. && exit) | ||
| 13 | |||
| 14 | for 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 | |||
| 27 | cat <<-EOF > BD-$UUID.ics | ||
| 28 | BEGIN:VCALENDAR | ||
| 29 | VERSION:2.0 | ||
| 30 | BEGIN:VEVENT | ||
| 31 | CREATED:$NOW | ||
| 32 | UID:$UUID | ||
| 33 | SUMMARY:$FN $AGE birthday | ||
| 34 | DTSTART;VALUE=DATE:$DAY | ||
| 35 | RRULE:FREQ=YEARLY | ||
| 36 | DESCRIPTION:$DESCRIPTION | ||
| 37 | END:VEVENT | ||
| 38 | END:VCALENDAR | ||
| 39 | EOF | ||
| 40 | fi | ||
| 41 | fi | ||
| 42 | done | ||
