name: "Start reset on tty1"
stages:
  initramfs:
    - name: "Starts kairos-reset for systemd based systems"
      if: |
        (grep -q "kairos.reset" /proc/cmdline || [ -f /run/cos/autoreset_mode ]) && \
        ( [ -e "/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ] || [ -e "/usr/sbin/systemctl" ] || [ -e "/usr/bin/systemctl" ] )
      commands:
        - systemctl disable getty@tty1
        - systemctl stop getty@tty1
        - systemctl mask getty@tty1
        - systemctl enable kairos-reset
    - name: "Starts kairos-reset for openRC-based systems"
      if: grep -q "kairos.reset" /proc/cmdline && [ -f "/sbin/openrc" ]
      commands:
        - sed -i -e 's/tty1.*//g' /etc/inittab
        - echo "tty1::respawn:/usr/bin/kairos-agent reset --unattended --reboot tty1" >> /etc/inittab
