#!/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|status) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg ;; esac pre_config() { 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 [ -d "/tmp/flash/.ssh" ] || mkdir /tmp/flash/.ssh [ -e "/mod/root/.ssh" ] || ln -s /tmp/flash/.ssh /mod/root/.ssh } start() { if [ "$DROPBEAR_PWDAUTH" = "yes" ]; then if cat /etc/shadow | grep -q '^root:[*!]:'; then echo "Error[$DAEMON]: no root password set - run 'passwd root'" 1>&2 exit 1 fi else DROPBEAR_OPTIONS="-s $DROPBEAR_OPTIONS" fi echo -n 'Starting ssh server...' if [ -s /var/run/$DAEMON.pid ]; then echo 'already running.' exit 0 fi set -o noglob $DAEMON -p "$DROPBEAR_PORT" $DROPBEAR_OPTIONS exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n 'Stopping ssh server...' if [ -e /var/run/$DAEMON.pid ]; then kill "$(cat /var/run/$DAEMON.pid)" > /dev/null 2>&1 exitval=$? fi if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) pre_config modreg cgi 'dropbear' 'Dropbear' deffile='/mod/etc/default.dropbear/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_ENABLED" != "yes" ]; then if [ "$DROPBEAR_ENABLED" != "inetd" ]; then echo "$DAEMON is disabled" 1>&2 else echo "$DAEMON is started via inetd" 1>&2 fi exit 1; fi start ;; unload) stop modunreg file 'authorized_keys' modunreg cgi 'dropbear' ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ "$DROPBEAR_ENABLED" == "inetd" ]; then echo 'inetd' else if [ -s "/var/run/$DAEMON.pid" ]; then echo 'running' else echo 'stopped' fi fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0