dropbear.init 1.5 KB

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