Files
sbbb/scripts/migrate-calendars.sh
Sienna Meridian Satterwhite 8662c79212 checkpoint: stalwart deploy, beam-design, migration scripts, config tweaks
Stalwart + Bulwark mail server deployment with OIDC, TLS cert, vault
secrets. Beam design service. Pingora config cleanup. SeaweedFS
replication fix. Kratos values tweak. Migration scripts for mbox/messages
/calendars from La Suite to Stalwart.
2026-04-06 17:52:30 +01:00

116 lines
3.6 KiB
Bash
Executable File

#!/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 <pw> \
# --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 <url> --new-url <url> --new-user <user> --new-password <pw> --users <comma-separated>"
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/<user>/ or similar. Adjust as needed.
# This PROPFIND discovers all calendars for the user.
curl -s -X PROPFIND \
-H "Content-Type: application/xml" \
-d '<?xml version="1.0" encoding="utf-8"?>
<d:propfind xmlns:d="DAV:" xmlns:cs="urn:ietf:params:xml:ns:caldav">
<d:prop>
<d:displayname/>
<d:resourcetype/>
</d:prop>
</d:propfind>' \
"$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/<user>/<calendar-name>/
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/<user>/' -X PROPFIND | grep -c VEVENT"
echo " New: curl -s -u admin:pw '$NEW_URL/dav/calendars/user/<user>/' -X PROPFIND | grep -c VEVENT"