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

45 lines
943 B
Bash
Executable File

#!/bin/sh
#
# Load SSH host key from SD card.
#
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
# Try to copy SSH host key from SD card.
mkdir -p /mnt/tmp_sdcard
mount -t vfat -o fmask=0177 -r /dev/mmcblk0p1 /mnt/tmp_sdcard
if ! cp -p /mnt/tmp_sdcard/dropbear_ed25519_host_key /etc/dropbear ; then
echo "WARNING: Failed to load SSH host key from SD card" >&2
umount /mnt/tmp_sdcard
rmdir /mnt/tmp_sdcard
exit 1
fi
umount /mnt/tmp_sdcard
rmdir /mnt/tmp_sdcard
chmod 0600 /etc/dropbear/dropbear_ed25519_host_key
}
case "$1" in
start)
start
;;
stop|restart|reload)
;;
*)
echo "Usage: $0 start"
exit 1
esac