sshd.init 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. #PKG openssh-server
  3. #INIT 50
  4. . /etc/rc.conf
  5. case $1 in
  6. autostop) ;;
  7. autostart)
  8. [[ $openssh = NO ]] && exit 0
  9. grep dropbear /etc/rc.conf >/dev/null 2>&1 || dropbear=NO
  10. if [[ $openssh = AUTO && $dropbear != NO ]]; then
  11. echo openssh not starting: set to AUTO and dropbear is enabled
  12. exit 0
  13. fi
  14. exec sh $0 start
  15. ;;
  16. start)
  17. if [[ ! -s /etc/ssh/ssh_host_rsa_key ]]; then
  18. mkdir -p /etc/ssh
  19. if [[ ! -x /usr/bin/ssh-keygen ]]; then
  20. bothlog openssh not starting: SSH private key missing
  21. exit 0
  22. fi
  23. echo "openssh: generating SSH private key (RSA)"
  24. /usr/bin/ssh-keygen -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key
  25. rv=$?
  26. echo openssh: key generation exited with code $rv
  27. [[ $rv = 0 && -s /etc/ssh/ssh_host_rsa_key ]] || exit 1
  28. fi
  29. mkdir -p /var/run/sshd
  30. mkdir -p /var/empty
  31. /usr/sbin/sshd
  32. ;;
  33. stop)
  34. if [ -e /var/run/sshd.pid ]; then
  35. kill $(cat /var/run/sshd.pid)
  36. fi
  37. ;;
  38. restart)
  39. sh $0 stop
  40. sh $0 start
  41. ;;
  42. *)
  43. echo "Usage: $0 {start | stop | restart}"
  44. exit 1
  45. ;;
  46. esac
  47. exit $?