Files
PatchBay/sshd/patchbay-sshd
mueller_minki 8e83a98ef4 Initial Awawawa
2026-10-04 09:08:27 +02:00

37 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# Starts the dedicated PatchBay sshd in the foreground. Used by all init systems.
# Usage: patchbay-sshd [config] (default /etc/patchbay/patchbay.conf)
set -eu
CONF=${1:-/etc/patchbay/patchbay.conf}
LIBDIR=$(dirname "$(readlink -f "$0")")
PATCHBAYD=${PATCHBAYD:-patchbayd}
SSHD=${SSHD:-$(command -v sshd || echo /usr/sbin/sshd)}
get() {
"$PATCHBAYD" -c "$CONF" --print-config | sed -n "s/^$1=//p"
}
RUNDIR=$(get RunDir)
HOSTKEY=$(get SSHHostKey)
mkdir -p "$RUNDIR" /run/sshd
chmod 755 "$RUNDIR"
if [ ! -f "$HOSTKEY" ]; then
ssh-keygen -q -t ed25519 -N '' -C patchbay-target -f "$HOSTKEY"
fi
# authorized_keys must exist before sshd accepts connections.
"$PATCHBAYD" -c "$CONF" --write-keys
sed -e "s|@PORT@|$(get TargetPort)|" \
-e "s|@HUBPORT@|$(get HubPort)|" \
-e "s|@HOSTKEY@|$HOSTKEY|" \
-e "s|@AUTHKEYS@|$(get AuthorizedKeys)|" \
-e "s|@USER@|$(get SSHUser)|" \
-e "s|@RUNDIR@|$RUNDIR|" \
"$LIBDIR/sshd_config.in" > "$RUNDIR/sshd_config"
"$SSHD" -t -f "$RUNDIR/sshd_config"
exec "$SSHD" -D -e -f "$RUNDIR/sshd_config"