#!/bin/sh
# Hook for systemd-sleep: run converge --sync for each logged-in user after resume.
# Installed to /usr/lib/systemd/system-sleep/converge-wake.
# Called with $1 = "pre" (before sleep) or "post" (after resume).

if [ "$1" = "post" ]; then
    # The converge-wake.service has After=network-online.target, so systemd
    # won't run the actual sync until the network stack is restored. This
    # hook only needs to request the start.
    loginctl list-users --no-legend 2>/dev/null | while read uid name rest; do
        [ "$uid" -ge 1000 ] 2>/dev/null || continue
        su "$name" -c "XDG_RUNTIME_DIR=/run/user/$uid systemctl --user start converge-wake.service" 2>/dev/null || true
    done
fi
