servis 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. #
  3. # /etc/init.d/dropbear: start/stop dropbear ssh daemon
  4. #
  5. SSD=/sbin/start-stop-daemon
  6. PROG=/usr/sbin/dropbear
  7. PID=/var/run/dropbear.pid
  8. CONV=/usr/bin/dropbearconvert
  9. KEYG=/usr/bin/dropbearkey
  10. RSA=/etc/dropbear/dropbear_rsa_host_key
  11. DSS=/etc/dropbear/dropbear_dss_host_key
  12. ECDSA=/etc/dropbear/dropbear_ecdsa_host_key
  13. create_keys() {
  14. if [ ! -f $RSA ]; then
  15. if [ -f /etc/ssh/ssh_host_rsa_key ]; then
  16. $CONV openssh dropbear /etc/ssh/ssh_host_rsa_key $RSA
  17. else
  18. $KEYG -t rsa -s 4096 -f $RSA
  19. fi
  20. fi
  21. if [ ! -f $DSS ]; then
  22. if [ -f /etc/ssh/ssh_host_dsa_key ]; then
  23. $CONV openssh dropbear /etc/ssh/ssh_host_dsa_key $DSS
  24. else
  25. $KEYG -t dss -f $DSS
  26. fi
  27. fi
  28. if [ ! -f $ECDSA ]; then
  29. if [ -f /etc/ssh/ssh_host_ecdsa_key ]; then
  30. $CONV openssh dropbear /etc/ssh/ssh_host_ecdsa_key $ECDSA
  31. else
  32. $KEYG -t ecdsa -s 521 -f $ECDSA
  33. fi
  34. fi
  35. }
  36. case $1 in
  37. start)
  38. create_keys
  39. $SSD --start --pidfile $PID --exec $PROG
  40. ;;
  41. stop)
  42. $SSD --stop --retry 10 --pidfile $PID
  43. ;;
  44. restart)
  45. $0 stop
  46. $0 start
  47. ;;
  48. status)
  49. $SSD --status --pidfile $PID
  50. case $? in
  51. 0) echo "$PROG is running with pid $(cat $PID)" ;;
  52. 1) echo "$PROG is not running but the pid file $PID exists" ;;
  53. 3) echo "$PROG is not running" ;;
  54. 4) echo "Unable to determine the program status" ;;
  55. esac
  56. ;;
  57. *)
  58. echo "usage: $0 [start|stop|restart|status]"
  59. ;;
  60. esac
  61. # End of file