1#!/bin/sh 2### BEGIN INIT INFO 3# Provides: sshd 4# Required-Start: $remote_fs $syslog $networking 5# Required-Stop: $remote_fs $syslog 6# Default-Start: 2 3 4 5 7# Default-Stop: 1 8# Short-Description: Dropbear Secure Shell server 9### END INIT INFO 10# 11# Do not configure this file. Edit /etc/default/dropbear instead! 12# 13 14PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 15DAEMON=/usr/sbin/dropbear 16NAME=dropbear 17DESC="Dropbear SSH server" 18PIDFILE=/var/run/dropbear.pid 19 20# These values may be replaced by those from /etc/default/dropbear 21DROPBEAR_RSAKEY_DIR="/etc/dropbear" 22DROPBEAR_PORT=22 23DROPBEAR_EXTRA_ARGS= 24DROPBEAR_RSAKEY_ARGS= 25NO_START=0 26 27set -e 28 29test ! -r /etc/default/dropbear || . /etc/default/dropbear 30test "$NO_START" = "0" || exit 0 31test -x "$DAEMON" || exit 0 32test ! -h /var/service/dropbear || exit 0 33 34test -z "$DROPBEAR_BANNER" || \ 35 DROPBEAR_EXTRA_ARGS="$DROPBEAR_EXTRA_ARGS -b $DROPBEAR_BANNER" 36test -n "$DROPBEAR_RSAKEY" || \ 37 DROPBEAR_RSAKEY="${DROPBEAR_RSAKEY_DIR}/dropbear_rsa_host_key" 38 39gen_keys() { 40 if [ -f "$DROPBEAR_RSAKEY" -a ! -s "$DROPBEAR_RSAKEY" ]; then 41 rm $DROPBEAR_RSAKEY || true 42 fi 43 if [ ! -f "$DROPBEAR_RSAKEY" ]; then 44 mkdir -p ${DROPBEAR_RSAKEY%/*} 45 dropbearkey -t rsa -f $DROPBEAR_RSAKEY $DROPBEAR_RSAKEY_ARGS 46 fi 47} 48 49case "$1" in 50 start) 51 echo -n "Starting $DESC: " 52 gen_keys 53 start-stop-daemon -S -p $PIDFILE \ 54 -x "$DAEMON" -- -r $DROPBEAR_RSAKEY \ 55 -p "$DROPBEAR_PORT" $DROPBEAR_EXTRA_ARGS 56 echo "$NAME." 57 ;; 58 stop) 59 echo -n "Stopping $DESC: " 60 start-stop-daemon -K -x "$DAEMON" -p $PIDFILE 61 echo "$NAME." 62 ;; 63 restart|force-reload) 64 echo -n "Restarting $DESC: " 65 start-stop-daemon -K -x "$DAEMON" -p $PIDFILE 66 sleep 1 67 start-stop-daemon -S -p $PIDFILE \ 68 -x "$DAEMON" -- -r $DROPBEAR_RSAKEY \ 69 -p "$DROPBEAR_PORT" $DROPBEAR_EXTRA_ARGS 70 echo "$NAME." 71 ;; 72 *) 73 N=/etc/init.d/$NAME 74 echo "Usage: $N {start|stop|restart|force-reload}" >&2 75 exit 1 76 ;; 77esac 78 79exit 0 80