#!/bin/sh /etc/rc.common
# nomad-swap: phase-B of the power-off SIM-swap flow.
# Runs VERY early (START=05) so we finalize the IMEI BEFORE the
# cellular stack does its first attach. Otherwise the operator would
# see the throwaway IMEI on the network – defeating the whole point.
#
# Idempotent: when no swap is pending, the underlying CLI returns
# immediately and the boot continues as normal.

START=05
USE_PROCD=1

NOMAD="/etc/nomad"

start_service() {
    procd_open_instance
    procd_set_param command sh -c \
        "PYTHONPATH=$NOMAD exec python3 -m nomad.cli swap complete-on-boot"
    procd_set_param stdout 1
    procd_set_param stderr 1
    # NO respawn – this is a one-shot. `respawn 0 0 0` does NOT mean
    # "don't respawn" in procd; it means "respawn without limits".
    # Omitting the directive entirely is what gives us proper one-shot
    # semantics: when the CLI exits, procd records the exit and stays
    # quiet.
    procd_close_instance
}
