xf.li | 8611891 | 2025-03-19 20:07:27 -0700 | [diff] [blame^] | 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 | |
| 14 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 15 | DAEMON=/usr/sbin/dropbear |
| 16 | NAME=dropbear |
| 17 | DESC="Dropbear SSH server" |
| 18 | PIDFILE=/var/run/dropbear.pid |
| 19 | |
| 20 | # These values may be replaced by those from /etc/default/dropbear |
| 21 | DROPBEAR_RSAKEY_DIR="/etc_rw/dropbear" |
| 22 | DROPBEAR_PORT=22 |
| 23 | DROPBEAR_EXTRA_ARGS= |
| 24 | DROPBEAR_RSAKEY_ARGS= |
| 25 | NO_START=0 |
| 26 | |
| 27 | set -e |
| 28 | |
| 29 | test ! -r /etc/default/dropbear || . /etc/default/dropbear |
| 30 | test "$NO_START" = "0" || exit 0 |
| 31 | test -x "$DAEMON" || exit 0 |
| 32 | test ! -h /var/service/dropbear || exit 0 |
| 33 | |
| 34 | test -z "$DROPBEAR_BANNER" || \ |
| 35 | DROPBEAR_EXTRA_ARGS="$DROPBEAR_EXTRA_ARGS -b $DROPBEAR_BANNER" |
| 36 | test -n "$DROPBEAR_RSAKEY" || \ |
| 37 | DROPBEAR_RSAKEY="${DROPBEAR_RSAKEY_DIR}/dropbear_rsa_host_key" |
| 38 | |
| 39 | gen_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 | |
| 49 | start() { |
| 50 | gen_keys |
| 51 | start-stop-daemon -S -p $PIDFILE \ |
| 52 | -x "$DAEMON" -- -r $DROPBEAR_RSAKEY \ |
| 53 | -p "$DROPBEAR_PORT" $DROPBEAR_EXTRA_ARGS |
| 54 | } |
| 55 | |
| 56 | stop() { |
| 57 | start-stop-daemon -K -x "$DAEMON" -p $PIDFILE |
| 58 | } |
| 59 | |
| 60 | restart() { |
| 61 | stop |
| 62 | sleep 1 |
| 63 | start |
| 64 | } |
| 65 | |
| 66 | case "$1" in |
| 67 | start|stop|restart) |
| 68 | "$1" |
| 69 | ;; |
| 70 | force-reload) |
| 71 | restart |
| 72 | ;; |
| 73 | *) |
| 74 | echo "Usage: $0 {start|stop|restart|force-reload}" |
| 75 | exit 1 |
| 76 | esac |
| 77 | |
| 78 | exit $? |
| 79 | |