blob: 83662058a36add59c9bf1bb517888350490159d1 [file] [log] [blame]
xf.li86118912025-03-19 20:07:27 -07001#!/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_rw/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
49start() {
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
56stop() {
57 start-stop-daemon -K -x "$DAEMON" -p $PIDFILE
58}
59
60restart() {
61 stop
62 sleep 1
63 start
64}
65
66case "$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
76esac
77
78exit $?
79