summaryrefslogtreecommitdiff
path: root/package/openssh/files/sshd.init
blob: 5953abef2809840ff111d5594c50041ee546ad98 (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
#!/bin/sh
#PKG openssh-server
#INIT 50
. /etc/rc.conf

case $1 in
autostop) ;;
autostart)
	test x"${openssh:-NO}" = x"NO" && exit 0
	grep "^dropbear" /etc/rc.conf >/dev/null 2>&1 || dropbear=NO
	if [[ $openssh = AUTO && $dropbear != NO ]]; then
		echo openssh not starting: set to AUTO and dropbear is enabled
		exit 0
	fi
	exec sh $0 start
	;;
start)
	if [[ ! -s /etc/ssh/ssh_host_rsa_key ]]; then
		mkdir -p /etc/ssh
		if [[ ! -x /usr/bin/ssh-keygen ]]; then
			echo "openssh not starting: SSH private key missing"
			exit 0
		fi
		echo "openssh: generating SSH private key (RSA)"
		/usr/bin/ssh-keygen -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key
		rv=$?
		echo openssh: key generation exited with code $rv
		[[ $rv = 0 && -s /etc/ssh/ssh_host_rsa_key ]] || exit 1
	fi
	mkdir -p /var/run/sshd
	mkdir -p /var/empty
	touch /var/log/btmp && chmod 600 /var/log/btmp
	/usr/sbin/sshd
	;;
stop)
	if [ -e /var/run/sshd.pid ]; then
		kill $(cat /var/run/sshd.pid)
	fi
	;;
restart)
	sh $0 stop
	sh $0 start
	;;
*)
	echo "Usage: $0 {start | stop | restart}"
	exit 1
	;;
esac
exit $?