From eab3b281c0af4acefdf398272d5993c2ea4caea3 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 21 Oct 2023 04:33:58 +0200 Subject: [PATCH] fetch-calendar: Make script also work on (most) Linux systems Do this by adding an OS type check and also adding the relevant date commands for Linux. Also check for OS type FreeBSD, since the script should work on there, if it works on Darwin. --- fetch-calendar.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fetch-calendar.sh b/fetch-calendar.sh index 6586fdb..fac7c5d 100755 --- a/fetch-calendar.sh +++ b/fetch-calendar.sh @@ -2,8 +2,23 @@ set -eu ICAL_URL=https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/6CJcM7XDfoYire5d -START_TIME=$(date -v-1d +%s) # yesterday -END_TIME=$(date -v+1m +%s) # now + 1 month OUTFILE=data/calendar.json +# See here for uname -s outputs: https://en.wikipedia.org/wiki/Uname#Examples +OS_TYPE=$(uname -s) +if [ "$OS_TYPE" = "Linux" ]; then + START_TIME=$(date --date="-1 day" +%s) # yesterday + END_TIME=$(date --date="+1 month" +%s) # now + 1 month +elif [ "$OS_TYPE" = "Darwin" ] || [ "$OS_TYPE" = "FreeBSD" ]; then + START_TIME=$(date -v-1d +%s) # yesterday + END_TIME=$(date -v+1m +%s) # now + 1 month +else + echo "ERROR: Unsupported OS type" + return 1 +fi + +mkdir -p $(dirname $OUTFILE) + +echo "loading calendar file..." curl -s $ICAL_URL\?export\&accept=jcal\&expand\=1\&start\=$START_TIME\&end\=$END_TIME | jq '.[2]|map({_type:.[0]}+(.[1]|map({key:.[0],value:.[3]})|from_entries))' > $OUTFILE +echo "...done"