#!/bin/sh
authorized_key=
python_version=2
rootpass=foobar
while [ $# -gt 0 ]; do
    case "$1" in
    --py3)
        python_version=3
        ;;
    --authorized-key)
        authorized_key="$2"
        shift
        ;;
    esac
    shift
done
# install minimum requirements to run ansible
dnf install -y openssh-server python${python_version}-dnf
# configure SSH
ssh-keygen -q -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key
echo "root:$rootpass" | chpasswd
if [ -n "$authorized_key" ]; then
    mkdir -p /root/.ssh
    echo "$authorized_key" >> /root/.ssh/authorized_keys
    chmod 644 /root/.ssh/authorized_keys
fi
# start SSHD in background
/usr/sbin/sshd
echo SSHD READY
# wait forever
tail -f /dev/null
