diff options
Diffstat (limited to 'other/ssharp/contrib/redhat/sshd.init')
| -rwxr-xr-x | other/ssharp/contrib/redhat/sshd.init | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/other/ssharp/contrib/redhat/sshd.init b/other/ssharp/contrib/redhat/sshd.init new file mode 100755 index 0000000..efedbfb --- /dev/null +++ b/other/ssharp/contrib/redhat/sshd.init | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # Init file for OpenSSH server daemon | ||
| 4 | # | ||
| 5 | # chkconfig: 2345 55 25 | ||
| 6 | # description: OpenSSH server daemon | ||
| 7 | # | ||
| 8 | # processname: sshd | ||
| 9 | # config: /etc/ssh/ssh_host_key | ||
| 10 | # config: /etc/ssh/ssh_host_key.pub | ||
| 11 | # config: /etc/ssh/ssh_random_seed | ||
| 12 | # config: /etc/ssh/sshd_config | ||
| 13 | # pidfile: /var/run/sshd.pid | ||
| 14 | |||
| 15 | # source function library | ||
| 16 | . /etc/rc.d/init.d/functions | ||
| 17 | |||
| 18 | [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd | ||
| 19 | |||
| 20 | RETVAL=0 | ||
| 21 | |||
| 22 | # Some functions to make the below more readable | ||
| 23 | KEYGEN=/usr/bin/ssh-keygen | ||
| 24 | RSA1_KEY=/etc/ssh/ssh_host_key | ||
| 25 | RSA_KEY=/etc/ssh/ssh_host_rsa_key | ||
| 26 | DSA_KEY=/etc/ssh/ssh_host_dsa_key | ||
| 27 | PID_FILE=/var/run/sshd.pid | ||
| 28 | my_success() { | ||
| 29 | local msg | ||
| 30 | if [ $# -gt 1 ]; then | ||
| 31 | msg="$2" | ||
| 32 | else | ||
| 33 | msg="done" | ||
| 34 | fi | ||
| 35 | case "`type -type success`" in | ||
| 36 | function) | ||
| 37 | success "$1" | ||
| 38 | ;; | ||
| 39 | *) | ||
| 40 | echo -n "${msg}" | ||
| 41 | ;; | ||
| 42 | esac | ||
| 43 | } | ||
| 44 | my_failure() { | ||
| 45 | local msg | ||
| 46 | if [ $# -gt 1 ]; then | ||
| 47 | msg="$2" | ||
| 48 | else | ||
| 49 | msg="FAILED" | ||
| 50 | fi | ||
| 51 | case "`type -type failure`" in | ||
| 52 | function) | ||
| 53 | failure "$1" | ||
| 54 | ;; | ||
| 55 | *) | ||
| 56 | echo -n "${msg}" | ||
| 57 | ;; | ||
| 58 | esac | ||
| 59 | } | ||
| 60 | do_rsa1_keygen() { | ||
| 61 | if ! test -f $RSA1_KEY ; then | ||
| 62 | echo -n "Generating SSH1 RSA host key: " | ||
| 63 | if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then | ||
| 64 | my_success "RSA1 key generation" | ||
| 65 | echo | ||
| 66 | else | ||
| 67 | my_failure "RSA1 key generation" | ||
| 68 | echo | ||
| 69 | exit 1 | ||
| 70 | fi | ||
| 71 | fi | ||
| 72 | } | ||
| 73 | do_rsa_keygen() { | ||
| 74 | if ! test -f $RSA_KEY ; then | ||
| 75 | echo -n "Generating SSH2 RSA host key: " | ||
| 76 | if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then | ||
| 77 | my_success "RSA key generation" | ||
| 78 | echo | ||
| 79 | else | ||
| 80 | my_failure "RSA key generation" | ||
| 81 | echo | ||
| 82 | exit 1 | ||
| 83 | fi | ||
| 84 | fi | ||
| 85 | } | ||
| 86 | do_dsa_keygen() { | ||
| 87 | if ! test -f $DSA_KEY ; then | ||
| 88 | echo -n "Generating SSH2 DSA host key: " | ||
| 89 | if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then | ||
| 90 | my_success "DSA key generation" | ||
| 91 | echo | ||
| 92 | else | ||
| 93 | my_failure "DSA key generation" | ||
| 94 | echo | ||
| 95 | exit 1 | ||
| 96 | fi | ||
| 97 | fi | ||
| 98 | } | ||
| 99 | |||
| 100 | case "$1" in | ||
| 101 | start) | ||
| 102 | # Create keys if necessary | ||
| 103 | do_rsa1_keygen; | ||
| 104 | do_rsa_keygen; | ||
| 105 | do_dsa_keygen; | ||
| 106 | |||
| 107 | echo -n "Starting sshd: " | ||
| 108 | if [ ! -f $PID_FILE ] ; then | ||
| 109 | sshd $OPTIONS | ||
| 110 | RETVAL=$? | ||
| 111 | if [ "$RETVAL" = "0" ] ; then | ||
| 112 | my_success "sshd startup" "sshd" | ||
| 113 | touch /var/lock/subsys/sshd | ||
| 114 | else | ||
| 115 | my_failure "sshd startup" "" | ||
| 116 | fi | ||
| 117 | fi | ||
| 118 | echo | ||
| 119 | ;; | ||
| 120 | stop) | ||
| 121 | echo -n "Shutting down sshd: " | ||
| 122 | if [ -f $PID_FILE ] ; then | ||
| 123 | killproc sshd | ||
| 124 | RETVAL=$? | ||
| 125 | [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd | ||
| 126 | fi | ||
| 127 | echo | ||
| 128 | ;; | ||
| 129 | restart) | ||
| 130 | $0 stop | ||
| 131 | $0 start | ||
| 132 | RETVAL=$? | ||
| 133 | ;; | ||
| 134 | condrestart) | ||
| 135 | if [ -f /var/lock/subsys/sshd ] ; then | ||
| 136 | $0 stop | ||
| 137 | $0 start | ||
| 138 | RETVAL=$? | ||
| 139 | fi | ||
| 140 | ;; | ||
| 141 | status) | ||
| 142 | status sshd | ||
| 143 | RETVAL=$? | ||
| 144 | ;; | ||
| 145 | *) | ||
| 146 | echo "Usage: sshd {start|stop|restart|status|condrestart}" | ||
| 147 | exit 1 | ||
| 148 | ;; | ||
| 149 | esac | ||
| 150 | |||
| 151 | exit $RETVAL | ||
