]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/dropbear/dropbear/init
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / dropbear / dropbear / init
1 #!/bin/sh
2 #
3 # Do not configure this file. Edit /etc/default/dropbear instead!
4 #
5
6 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
7 DAEMON=/usr/sbin/dropbear
8 NAME=dropbear
9 DESC="Dropbear SSH server"
10
11 DROPBEAR_PORT=22
12 DROPBEAR_EXTRA_ARGS=
13 NO_START=0
14
15 set -e
16
17 test ! -r /etc/default/dropbear || . /etc/default/dropbear
18 test "$NO_START" = "0" || exit 0
19 test -x "$DAEMON" || exit 0
20 test ! -h /var/service/dropbear || exit 0
21
22 readonly_rootfs=0
23 for 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
29 done
30
31 if [ $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"
35 else
36   DROPBEAR_RSAKEY_DEFAULT="/etc/dropbear/dropbear_rsa_host_key"
37   DROPBEAR_DSSKEY_DEFAULT="/etc/dropbear/dropbear_dss_host_key"
38 fi
39
40 test -z "$DROPBEAR_BANNER" || \
41   DROPBEAR_EXTRA_ARGS="$DROPBEAR_EXTRA_ARGS -b $DROPBEAR_BANNER"
42 test -n "$DROPBEAR_RSAKEY" || \
43   DROPBEAR_RSAKEY=$DROPBEAR_RSAKEY_DEFAULT
44 test -n "$DROPBEAR_DSSKEY" || \
45   DROPBEAR_DSSKEY=$DROPBEAR_DSSKEY_DEFAULT
46 test -n "$DROPBEAR_KEYTYPES" || \
47   DROPBEAR_KEYTYPES="rsa"
48
49 gen_keys() {
50 for 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
59 done
60 }
61
62 case "$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         ;;
96 esac
97
98 exit 0