dropbear.init 1.2 KB

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