forked from Freetz/freetz
/
rc.dropbear
executable file
·86 lines (74 loc) · 1.67 KB
/
rc.dropbear
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
DAEMON=dropbear
DAEMON_LONG_NAME="dropbear SSH server"
. /etc/init.d/modlibrc
[ -r /etc/options.cfg ] && . /etc/options.cfg
pre_config() {
mkdir -p /tmp/flash/dropbear
local alg do_save=false
for alg in rsa dss ecdsa ed25519; do
local key_file=/tmp/flash/dropbear/${alg}_host_key
if [ ! -e "${key_file}" ]; then
do_save=true
rm -f "${key_file}"
echo "Creating $(echo ${alg} | tr [a-z] [A-Z]) host key"
dropbearkey -t ${alg} -f "${key_file}"
fi
done
$do_save && /usr/bin/modsave flash
if [ ! -d "/mod/etc/ssh" ]; then
mkdir -p /mod/etc/ssh
for alg in rsa dss ecdsa ed25519; do
ln -sf /tmp/flash/dropbear/${alg}_host_key /mod/etc/ssh/${alg}_host_key
done
fi
if [ "$FREETZ_PACKAGE_AUTHORIZED_KEYS" != "y" ]; then
[ -e "/mod/root/.ssh" ] || ln -s /tmp/flash/dropbear /mod/root/.ssh
fi
}
start() {
if [ "$DROPBEAR_PWDAUTH" = "yes" ]; then
if cat /etc/shadow | grep -q '^root:[*!]:'; then
echo "Error[$DAEMON]: no root password set - run 'passwd root'" 1>&2
exit 1
fi
else
DROPBEAR_OPTIONS="-s $DROPBEAR_OPTIONS"
fi
[ "$DROPBEAR_ROOTONLY" = "yes" ] && DROPBEAR_OPTIONS="-0 $DROPBEAR_OPTIONS"
set -o noglob
modlib_startdaemon $DAEMON -p "$DROPBEAR_PORT" $DROPBEAR_OPTIONS
}
stop() {
killall dropbear 2>/dev/null
}
case $1 in
""|load)
pre_config
modreg cgi 'dropbear' 'Dropbear'
modreg daemon $DAEMON
modlib_start $DROPBEAR_ENABLED
;;
unload)
modunreg daemon $DAEMON
modunreg cgi 'dropbear'
modlib_stop
;;
start)
modlib_start
;;
stop)
modlib_stop
;;
restart)
modlib_restart
;;
status)
modlib_status
;;
*)
echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2
exit 1
;;
esac
exit 0