redpitaya-puzzlefw/sw/buildroot_overlay/etc/init.d/S10prepare_dropbear.sh

42 lines
1001 B
Bash
Raw Normal View History

#!/bin/sh
#
# Load SSH host key from SD card.
#
2024-10-13 10:35:19 +02:00
. /opt/puzzlefw/lib/functions.sh
start() {
# If host key exists, do nothing.
[ -f /etc/dropbear/dropbear_ed25519_host_key ] && return
# If /etc/dropbear is a symlink, delete it.
[ -L /etc/dropbear ] && rm /etc/dropbear
# Create directory /etc/dropbear if it does not exist.
mkdir -p /etc/dropbear
2024-10-13 10:35:19 +02:00
# Try to copy SSH host key from configuration files.
if ! cp -p ${CONFIG_DIR}/dropbear_ed25519_host_key /etc/dropbear ; then
echo "WARNING: Failed to load SSH host key from SD card" >&2
2024-10-13 10:35:19 +02:00
echo "Generating new SSH host key." >&2
dropbearkey -t ed25519 -f ${CONFIG_DIR}/dropbear_ed25519_host_key.new
sync_config dropbear_ed25519_host_key
cp -p ${CONFIG_DIR}/dropbear_ed25519_host_key /etc/dropbear
fi
chmod 0600 /etc/dropbear/dropbear_ed25519_host_key
}
case "$1" in
start)
start
;;
stop|restart|reload)
;;
*)
echo "Usage: $0 start"
exit 1
esac