#!/sbin/openrc-run
# USB-only PAM-free fallback sshd, started independently of local.d.
description="Bananarchy USB diagnostic sshd"

command="/usr/sbin/sshd"
command_args="-f /etc/ssh/sshd_config_debug"
pidfile="/run/sshd-debug.pid"

depend() {
  need localmount
  after sshd udev-settle
}

start_pre() {
  [ -x /usr/sbin/sshd ] || return 1
  [ -f /etc/ssh/ssh_host_ed25519_key ] || /usr/sbin/ssh-keygen -A >/dev/null 2>&1 || true
}

start() {
  if [ -f /etc/bananarchy-no-debug-sshd ]; then
    ebegin "Skipping USB-only diagnostic sshd"
    eend 0
    return 0
  fi
  ebegin "Starting USB-only diagnostic sshd"
  "$command" $command_args
  eend $?
}
