#!/bin/sh

TARGET_DESC="Dropbear (SSH daemon)"
TARGET_BIN=/usr/sbin/dropbear

source /etc/utils/shell-utils.sh

echo "[IM][system init][+][${TARGET_DESC}] Starting..."

/sbin/ifup eth0

# wait for /dev/urandom before we start dropbear
while [ 1 ]; do
    if [ -c /dev/urandom ]; then
	#echo "[IM][system init][+][${TARGET_DESC}] urandom is ready"
	break;
    else
	#echo "[IM][system init][i][${TARGET_DESC}] urandom NOT found. waiting..."
	sleep 0.2
    fi
done

if [ -e /usr/sbin/dropbear ]; then
    if [ ! -e /etc/dropbear/dropbear_rsa_host_key ]; then
	echo "[IM][system init][+][${TARGET_DESC}] HOST KEY not found. Creating host key"
        mkdir -p /etc/dropbear
        dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
        dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
    fi

    $TARGET_BIN 
#-E 2>> /ram/db.txt 

    #echo "$?" >> /ram/db.txt

    if [ $? -eq 0 ]; then
	echo "[IM][system init][i][${TARGET_DESC}] Started OK"
    else 
	echo "[IM][system init][!][${TARGET_DESC}] FAILED to start!"
    fi
fi

${SPLASH} prg 50
${SPLASH} clear_log
${SPLASH} log "Init SSH server..."
