summaryrefslogtreecommitdiffstats
path: root/meta/packages/dropbear/dropbear/init
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/dropbear/dropbear/init')
-rwxr-xr-xmeta/packages/dropbear/dropbear/init98
1 files changed, 98 insertions, 0 deletions
diff --git a/meta/packages/dropbear/dropbear/init b/meta/packages/dropbear/dropbear/init
new file mode 100755
index 0000000000..d019bdb4ba
--- /dev/null
+++ b/meta/packages/dropbear/dropbear/init
@@ -0,0 +1,98 @@
1#!/bin/sh
2#
3# Do not configure this file. Edit /etc/default/dropbear instead!
4#
5
6PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
7DAEMON=/usr/sbin/dropbear
8NAME=dropbear
9DESC="Dropbear SSH server"
10
11DROPBEAR_PORT=22
12DROPBEAR_EXTRA_ARGS=
13NO_START=0
14
15set -e
16
17test ! -r /etc/default/dropbear || . /etc/default/dropbear
18test "$NO_START" = "0" || exit 0
19test -x "$DAEMON" || exit 0
20test ! -h /var/service/dropbear || exit 0
21
22readonly_rootfs=0
23for flag in `awk '{ if ($2 == "/") { split($4,FLAGS,",") } }; END { for (f in FLAGS) print FLAGS[f] }' </proc/mounts`; do
24 case $flag in
25 ro)
26 readonly_rootfs=1
27 ;;
28 esac
29done
30
31if [ $readonly_rootfs = "1" ]; then
32 mkdir -p /var/lib/dropbear
33 DROPBEAR_RSAKEY_DEFAULT="/var/lib/dropbear/dropbear_rsa_host_key"
34 DROPBEAR_DSSKEY_DEFAULT="/var/lib/dropbear/dropbear_dss_host_key"
35else
36 DROPBEAR_RSAKEY_DEFAULT="/etc/dropbear/dropbear_rsa_host_key"
37 DROPBEAR_DSSKEY_DEFAULT="/etc/dropbear/dropbear_dss_host_key"
38fi
39
40test -z "$DROPBEAR_BANNER" || \
41 DROPBEAR_EXTRA_ARGS="$DROPBEAR_EXTRA_ARGS -b $DROPBEAR_BANNER"
42test -n "$DROPBEAR_RSAKEY" || \
43 DROPBEAR_RSAKEY=$DROPBEAR_RSAKEY_DEFAULT
44test -n "$DROPBEAR_DSSKEY" || \
45 DROPBEAR_DSSKEY=$DROPBEAR_DSSKEY_DEFAULT
46test -n "$DROPBEAR_KEYTYPES" || \
47 DROPBEAR_KEYTYPES="rsa"
48
49gen_keys() {
50for t in $DROPBEAR_KEYTYPES; do
51 case $t in
52 rsa)
53 test -f $DROPBEAR_RSAKEY || dropbearkey -t rsa -f $DROPBEAR_RSAKEY
54 ;;
55 dsa)
56 test -f $DROPBEAR_DSSKEY || dropbearkey -t dss -f $DROPBEAR_DSSKEY
57 ;;
58 esac
59done
60}
61
62case "$1" in
63 start)
64 echo -n "Starting $DESC: "
65 gen_keys
66 KEY_ARGS=""
67 test -f $DROPBEAR_DSSKEY && KEY_ARGS="$KEY_ARGS -d $DROPBEAR_DSSKEY"
68 test -f $DROPBEAR_RSAKEY && KEY_ARGS="$KEY_ARGS -r $DROPBEAR_RSAKEY"
69 start-stop-daemon -S \
70 -x "$DAEMON" -- $KEY_ARGS \
71 -p "$DROPBEAR_PORT" $DROPBEAR_EXTRA_ARGS
72 echo "$NAME."
73 ;;
74 stop)
75 echo -n "Stopping $DESC: "
76 start-stop-daemon -K -x "$DAEMON"
77 echo "$NAME."
78 ;;
79 restart|force-reload)
80 echo -n "Restarting $DESC: "
81 start-stop-daemon -K -x "$DAEMON"
82 sleep 1
83 KEY_ARGS=""
84 test -f $DROPBEAR_DSSKEY && KEY_ARGS="$KEY_ARGS -d $DROPBEAR_DSSKEY"
85 test -f $DROPBEAR_RSAKEY && KEY_ARGS="$KEY_ARGS -r $DROPBEAR_RSAKEY"
86 start-stop-daemon -S \
87 -x "$DAEMON" -- $KEY_ARGS \
88 -p "$DROPBEAR_PORT" $DROPBEAR_EXTRA_ARGS
89 echo "$NAME."
90 ;;
91 *)
92 N=/etc/init.d/$NAME
93 echo "Usage: $N {start|stop|restart|force-reload}" >&2
94 exit 1
95 ;;
96esac
97
98exit 0