#!/bin/sh

# Disable waydroid-container.service and stop the service leaving it entirely D-Bus activated which
# has been supported since v1.4.0 and avoids problematic behavior of "waydroid upgrade -o" running
# too early in boot previously breaking launch of Waydroid by the user following a reboot
enabled_service="/etc/systemd/system/multi-user.target.wants/waydroid-container.service"
if [ -f "$enabled_service" ]; then
    rm -v "$enabled_service" \
          /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/waydroid-container.service \
          /var/lib/systemd/deb-systemd-helper-enabled/waydroid-container.service.dsh-also

    # Exit with "CONFIG" so the service won't auto-restart until activated next time by D-Bus instead
    exit 78
fi

# Perform the usual expected ExecStart task of waydroid-container.service
exec /usr/bin/waydroid -w container start
