#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib DAEMON=dropbear case "$1" in ""|load|start|restart) if [ ! -r "/mod/etc/conf/$DAEMON-sshd.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON-sshd.cfg ;; esac start() { if [ ! -e "/tmp/flash/rsa_host_key" -o ! -e "/tmp/flash/dss_host_key" ]; then echo "Creating RSA and DSS host keys" rm -f /tmp/flash/rsa_host_key rm -f /tmp/flash/dss_host_key dropbearkey -t rsa -f /tmp/flash/rsa_host_key dropbearkey -t dss -f /tmp/flash/dss_host_key /usr/bin/modsave flash fi if [ ! -d "/mod/etc/ssh" ]; then mkdir -p /mod/etc/ssh ln -s /tmp/flash/rsa_host_key /mod/etc/ssh/rsa_host_key ln -s /tmp/flash/dss_host_key /mod/etc/ssh/dss_host_key fi [ -e "/mod/root/.ssh" ] || ln -s /tmp/flash/.ssh /mod/root/.ssh if [ "$DROPBEAR_SSHD_PWDAUTH" = "yes" ]; then if cat /var/tmp/shadow | grep '^root:\*:' > /dev/null; then echo "Error[$DAEMON]: no root password set - run 'modpasswd root'" 1>&2 exit 1 fi else DROPBEAR_SSHD_OPTIONS="-s $DROPBEAR_SSHD_OPTIONS" fi echo -n 'Starting ssh server...' set -o noglob $DAEMON -p "$DROPBEAR_SSHD_PORT" $DROPBEAR_SSHD_OPTIONS exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n 'Stopping ssh server...' killall $DAEMON > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) [ -d "/tmp/flash/.ssh" ] || mkdir /tmp/flash/.ssh modreg cgi 'dropbear-sshd' 'Dropbear' deffile='/mod/etc/default.dropbear-sshd/authorized_keys.def' [ -r "/tmp/flash/authorized_keys.def" ] && deffile='/tmp/flash/authorized_keys.def' modreg file 'authorized_keys' 'Authorized keys' 0 "$deffile" if [ "$DROPBEAR_SSHD_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi start ;; unload) stop modunreg file 'authorized_keys' modunreg cgi 'dropbear-sshd' ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ -z "$(pidof "$DAEMON")" ]; then echo 'stopped' else echo 'running' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0