#!/bin/sh

set -e
set -x

HOMEDIR="$AUTOPKGTEST_TMP/home"
adduser --home "$HOMEDIR" --disabled-password --gecos autopkgtest rsync
mkdir -m 700 "$HOMEDIR/.ssh"

ps fax | grep ssh || true
ls -l /etc/ssh/ || true

if ! systemctl is-active -q ssh; then
	systemctl start ssh || true
fi

sleep 5

journalctl | tail -n 100

ps fax | grep ssh
ls -l /etc/ssh/

ssh-keyscan -v localhost > "$HOMEDIR/.ssh/known_hosts" 2>/dev/null
ssh-keygen -q -N '' -f "$HOMEDIR/.ssh/id_rsa"
cp "$HOMEDIR/.ssh/id_rsa.pub" "$HOMEDIR/.ssh/authorized_keys"
chown -R rsync: "$HOMEDIR/.ssh/"

runuser -u rsync -- env REMOTE=rsync@localhost /bin/sh debian/tests/local-tests

