1
0

dropbear.init 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. #PKG dropbear
  3. #INIT 50
  4. . /etc/rc.conf
  5. case $1 in
  6. autostop) ;;
  7. autostart)
  8. test x"${dropbear:-NO}" = x"NO" && exit 0
  9. test x"$dropbear" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
  10. exec sh $0 start
  11. ;;
  12. start)
  13. if test ! -f /etc/dropbear/dropbear_rsa_host_key; then
  14. mkdir -p /etc/dropbear
  15. if test ! -x /usr/bin/dropbearkey; then
  16. echo "dropbear not starting: SSH private key missing"
  17. exit 0
  18. fi
  19. echo "dropbear: generating SSH private key (RSA)"
  20. /usr/bin/dropbearkey -f /etc/dropbear/dropbear_rsa_host_key \
  21. -t rsa ; rv=$?
  22. echo "dropbear: key generation exited with code $rv"
  23. test $rv = 0 || exit 1
  24. test -f /etc/dropbear/dropbear_rsa_host_key || exit 1
  25. fi
  26. if test ! -f /etc/dropbear/dropbear_dss_host_key; then
  27. # take it easy here, since above already catched the worst cases
  28. if test -x /usr/bin/dropbearkey; then
  29. echo "dropbear: generating SSH private key (DSS)"
  30. /usr/bin/dropbearkey -f /etc/dropbear/dropbear_dss_host_key -t dss
  31. echo "dropbear: key generation exited with code $?"
  32. fi
  33. fi
  34. if test ! -f /etc/dropbear/dropbear_ecdsa_host_key; then
  35. # take it easy here, since above already catched the worst cases
  36. if test -x /usr/bin/dropbearkey; then
  37. echo "dropbear: generating SSH private key (ECDSA)"
  38. /usr/bin/dropbearkey -f /etc/dropbear/dropbear_ecdsa_host_key -t ecdsa
  39. echo "dropbear: key generation exited with code $?"
  40. fi
  41. fi
  42. /usr/sbin/dropbear $dropbear_flags
  43. ;;
  44. stop)
  45. kill $(pgrep -f /usr/sbin/dropbear)
  46. ;;
  47. restart)
  48. sh $0 stop
  49. sh $0 start
  50. ;;
  51. *)
  52. echo "Usage: $0 {start | stop | restart}"
  53. exit 1
  54. ;;
  55. esac
  56. exit $?