#!/usr/bin/env bash
source /usr/bin/pwnlib

if is_crypted_mode; then
  while ! is_decrypted; do
    echo "Waiting for decryption..."
    sleep 1
  done
fi

if brcm_hard_failure && ! brcm_chip_alive; then
  if brcm_reboot_allowed; then
    echo "wifi chip hard-failed and is not responding -- rebooting to re-init it"
    reboot
  else
    echo "wifi chip hard-failed, not responding, reboot budget exhausted -- continuing"
  fi
  sleep 10
fi

if ! is_interface_up 'mon0'; then
  start_monitor_interface
else
  stop_monitor_interface
  start_monitor_interface
fi

if is_auto_mode_no_delete; then
  /usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0
else
  /usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0
fi
