#!/bin/sh

WORK_FILES_DIR="/mnt/persistent-data"
# remount / rw
mount -o remount,rw /

# remove old keys
sed -i "/HostKey/d" /etc/ssh/sshd_config_readonly

# make new keys
echo "HostKey ${WORK_FILES_DIR}/.ssh/ssh_host_rsa_key" >> /etc/ssh/sshd_config_readonly
echo "HostKey ${WORK_FILES_DIR}/.ssh/ssh_host_ecdsa_key" >> /etc/ssh/sshd_config_readonly
echo "HostKey ${WORK_FILES_DIR}/.ssh/ssh_host_ed25519_key" >> /etc/ssh/sshd_config_readonly

# make directory
mkdir -p "$WORK_FILES_DIR"/.ssh

# remount / ro
mount -o remount,ro /
