summaryrefslogtreecommitdiff
path: root/package/dropbear/files/dropbear.init
blob: 9bf74098e6bbb451f77ecfbfccdfd3d38ec987c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
#PKG dropbear
#INIT 50
. /etc/rc.conf

case $1 in
autostop) ;;
autostart)
	test x"${dropbear:-NO}" = x"NO" && exit 0
	test x"$dropbear" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
	exec sh $0 start
	;;
start)
	if test ! -f /etc/dropbear/dropbear_rsa_host_key; then
		mkdir -p /etc/dropbear
		if test ! -x /usr/bin/dropbearkey; then
			echo "dropbear not starting: SSH private key missing"
			exit 0
		fi
		echo "dropbear: generating SSH private key (RSA)"
		/usr/bin/dropbearkey -f /etc/dropbear/dropbear_rsa_host_key \
		    -t rsa ; rv=$?
		echo "dropbear: key generation exited with code $rv"
		test $rv = 0 || exit 1
		test -f /etc/dropbear/dropbear_rsa_host_key || exit 1
	fi
	if test ! -f /etc/dropbear/dropbear_dss_host_key; then
		# take it easy here, since above already catched the worst cases
		if test -x /usr/bin/dropbearkey; then
			echo "dropbear: generating SSH private key (DSS)"
			/usr/bin/dropbearkey -f /etc/dropbear/dropbear_dss_host_key -t dss
			echo "dropbear: key generation exited with code $?"
		fi
	fi
	if test ! -f /etc/dropbear/dropbear_ecdsa_host_key; then
		# take it easy here, since above already catched the worst cases
		if test -x /usr/bin/dropbearkey; then
			echo "dropbear: generating SSH private key (ECDSA)"
			/usr/bin/dropbearkey -f /etc/dropbear/dropbear_ecdsa_host_key -t ecdsa
			echo "dropbear: key generation exited with code $?"
		fi
	fi
	/usr/sbin/dropbear $dropbear_flags
	;;
stop)
	kill $(pgrep -f /usr/sbin/dropbear)
	;;
restart)
	sh $0 stop
	sh $0 start
	;;
*)
	echo "Usage: $0 {start | stop | restart}"
	exit 1
	;;
esac
exit $?