#!/bin/sh
# tinyssh run: provision host keys once, then serve ssh via tcpsvd.
# tinysshd-makekey is NOT idempotent (mkdir fails when the keydir exists,
# and rerunning would rotate keys), so the ed25519.pk guard below is
# load-bearing - never exec makekey unconditionally.
exec 2>&1
KEYDIR=/etc/tinyssh/sshkeydir
mkdir -p /etc/tinyssh
if [ ! -e "${KEYDIR}/ed25519.pk" ]; then
  /usr/sbin/tinysshd-makekey -q "${KEYDIR}" || exit 1
fi
exec /usr/bin/tcpsvd -vE 0 22 /usr/sbin/tinysshd -v "${KEYDIR}"
