# Template file for 'tinyssh'
pkgname=tinyssh
version=20260906
revision=4
short_desc="Small SSH server"
maintainer="finwo <finwo@pm.me>"
license="CC0-1.0"
homepage="https://tinyssh.org"
distfiles="https://github.com/janmojzis/tinyssh/archive/refs/tags/20260906.tar.gz"
checksum=54c143281e3a7430e9db80847c3242bbd6bf859ceafb5a18562bc4ecbbb2806d
depends="busybox"

# Notes:
# - Daemon-only package: upstream ships no client. tinysshd is a multicall
#   binary (makekey/printkey/noneauthd are argv[0] modes); the template
#   installs real symlinks rather than the copies `make install` would lay.
# - Host keys are provisioned by the service run script itself
#   (idempotent tinysshd-makekey guarded on ed25519.pk), never packaged.
#   Auth is stock ~/.ssh/authorized_keys, ssh-ed25519 only.
# - No `make install`: full control over destinations via vinstall.

do_build() {
  cd "${WRKSRC}"
  make -j"$(nproc)"
  [ -x ./tinysshd ] || die "tinyssh: tinysshd binary missing after build"
}

do_install() {
  cd "${WRKSRC}"
  vinstall tinysshd 755 usr/sbin tinysshd
  # -f: DESTDIR persists across rebuilds, links may already exist
  ( cd "${DESTDIR}/usr/sbin" && ln -sfn tinysshd tinysshd-makekey ) || die "link makekey"
  ( cd "${DESTDIR}/usr/sbin" && ln -sfn tinysshd tinysshd-printkey ) || die "link printkey"
  ( cd "${DESTDIR}/usr/sbin" && ln -sfn tinysshd tinysshnoneauthd ) || die "link noneauthd"
  vinstall man/tinysshd.8 644 usr/share/man/man8 tinysshd.8
  vinstall man/tinysshd-makekey.8 644 usr/share/man/man8 tinysshd-makekey.8
  vinstall man/tinysshd-printkey.8 644 usr/share/man/man8 tinysshd-printkey.8
  vinstall man/tinysshnoneauthd.8 644 usr/share/man/man8 tinysshnoneauthd.8
  vinstall ${FILESDIR}/tinyssh-run 755 etc/sv/tinyssh run
  vinstall ${FILESDIR}/tinyssh-check 755 etc/sv/tinyssh check
  vinstall ${FILESDIR}/tinyssh-log-run 755 etc/sv/tinyssh/log run
  # owned (empty) so the keydir parent always exists; the run script also
  # mkdir -p's defensively for wiped-state recovery
  install -d "${DESTDIR}/etc/tinyssh"
  install -d "${DESTDIR}/var/log/tinyssh"
}
