name: "Start recovery on tty1"
stages:
  initramfs:
    - name: "Starts kairos-recovery and generate a temporary pass"
      if: |
        grep -q "kairos.remote_recovery_mode" /proc/cmdline && \
        ( [ -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-recovery
    - name: "Starts kairos-recovery for openRC based systems"
      if: grep -q "kairos.remote_recovery_mode" /proc/cmdline && [ -f "/sbin/openrc" ]
      commands:
        - sed -i -e 's/tty1.*//g' /etc/inittab
        - echo "tty1::respawn:/usr/bin/kairos-agent recovery tty1" >> /etc/inittab
  boot:
    - name: "Recovery"
      if: '[ -f "/run/cos/recovery_mode" ]'
      hostname: "cos-recovery"
      commands:
        - |
          . /etc/os-release
          [ -f "/etc/kairos-release" ] && . /etc/kairos-release
          echo >> /etc/issue
          echo "You are booting from recovery mode. Run 'kairos-agent reset' to reset the system to $VERSION" >> /etc/issue
          echo " or 'kairos-agent upgrade' to upgrade the active partition" >> /etc/issue
          echo >> /etc/issue
