#!/usr/bin/env bash # Migrate calendars from La Suite Calendars (CalDAV) to Stalwart (CalDAV). # # Exports all calendars per user from the old CalDAV endpoint and imports them # into Stalwart's CalDAV endpoint. # # Prerequisites: # - curl # - Port-forward to both old calendars-backend and new Stalwart: # kubectl port-forward -n lasuite svc/calendars-backend 8081:80 & # kubectl port-forward -n stalwart svc/stalwart 8080:8080 & # # Usage: # ./migrate-calendars.sh \ # --old-url http://127.0.0.1:8081 \ # --new-url http://127.0.0.1:8080 \ # --new-user admin --new-password \ # --users "sienna@sunbeam.pt,amber@sunbeam.pt,lonni@sunbeam.pt" set -euo pipefail EXPORT_DIR="$(mktemp -d)/calendar-export" mkdir -p "$EXPORT_DIR" OLD_URL="" NEW_URL="" NEW_USER="" NEW_PASS="" USERS="" while [[ $# -gt 0 ]]; do case "$1" in --old-url) OLD_URL="$2"; shift 2 ;; --new-url) NEW_URL="$2"; shift 2 ;; --new-user) NEW_USER="$2"; shift 2 ;; --new-password) NEW_PASS="$2"; shift 2 ;; --users) USERS="$2"; shift 2 ;; *) echo "Unknown arg: $1"; exit 1 ;; esac done if [[ -z "$OLD_URL" || -z "$NEW_URL" || -z "$NEW_USER" || -z "$NEW_PASS" || -z "$USERS" ]]; then echo "Usage: $0 --old-url --new-url --new-user --new-password --users " exit 1 fi IFS=',' read -ra USER_LIST <<< "$USERS" echo "==> Exporting calendars from La Suite..." for user in "${USER_LIST[@]}"; do user_dir="$EXPORT_DIR/$user" mkdir -p "$user_dir" echo " Exporting calendars for $user..." # NOTE: The exact CalDAV path depends on La Suite's CalDAV implementation. # La Suite Calendars uses /caldav// or similar. Adjust as needed. # This PROPFIND discovers all calendars for the user. curl -s -X PROPFIND \ -H "Content-Type: application/xml" \ -d ' ' \ "$OLD_URL/caldav/$user/" \ -o "$user_dir/calendars.xml" 2>/dev/null || true # Export each calendar as .ics via CalDAV REPORT # NOTE: This is a simplified template. The actual export depends on # the La Suite CalDAV response format. You may need to parse the # PROPFIND response to discover calendar URLs, then issue # calendar-multiget or calendar-query REPORT requests. # # A simpler alternative: if La Suite exposes /ical/ export endpoints # (seen in pingora config: /ical/ → calendars-backend), use those: # # curl -s "$OLD_URL/ical/$user/calendar.ics" -o "$user_dir/calendar.ics" # echo " Exported to $user_dir/" done echo "" echo "==> Importing calendars into Stalwart..." for user in "${USER_LIST[@]}"; do user_dir="$EXPORT_DIR/$user" for ics_file in "$user_dir"/*.ics; do [[ -f "$ics_file" ]] || continue cal_name=$(basename "$ics_file" .ics) echo " Importing $cal_name for $user..." # Upload .ics to Stalwart CalDAV. # Stalwart CalDAV path: /dav/calendars/user/// curl -s -X PUT \ -u "$NEW_USER:$NEW_PASS" \ -H "Content-Type: text/calendar" \ --data-binary "@$ics_file" \ "$NEW_URL/dav/calendars/user/$user/$cal_name.ics" || { echo " ⚠️ Failed to import $cal_name for $user" } done done echo "" echo "==> Migration complete. Exported data is in: $EXPORT_DIR" echo "" echo "Verify by comparing event counts:" echo " Old: curl -s '$OLD_URL/caldav//' -X PROPFIND | grep -c VEVENT" echo " New: curl -s -u admin:pw '$NEW_URL/dav/calendars/user//' -X PROPFIND | grep -c VEVENT"