Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # Donated code that was put under PD license. |
| 3 | # |
| 4 | # Stripped PRNGd out of it for the time being. |
| 5 | |
Tim Rice | 748fcf9 | 2002-11-13 15:50:04 -0800 | [diff] [blame] | 6 | umask 022 |
| 7 | |
Tim Rice | 5af9db9 | 2004-06-19 19:31:06 -0700 | [diff] [blame] | 8 | CAT=@CAT@ |
| 9 | KILL=@KILL@ |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 10 | |
Tim Rice | 5af9db9 | 2004-06-19 19:31:06 -0700 | [diff] [blame] | 11 | prefix=@prefix@ |
| 12 | sysconfdir=@sysconfdir@ |
| 13 | piddir=@piddir@ |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 14 | |
Ben Lindstrom | 7a97339 | 2001-10-12 21:52:39 +0000 | [diff] [blame] | 15 | SSHD=$prefix/sbin/sshd |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame] | 16 | PIDFILE=$piddir/sshd.pid |
Ben Lindstrom | 7a97339 | 2001-10-12 21:52:39 +0000 | [diff] [blame] | 17 | SSH_KEYGEN=$prefix/bin/ssh-keygen |
Tim Rice | 5af9db9 | 2004-06-19 19:31:06 -0700 | [diff] [blame] | 18 | HOST_KEY_RSA1=$sysconfdir/ssh_host_key |
| 19 | HOST_KEY_DSA=$sysconfdir/ssh_host_dsa_key |
| 20 | HOST_KEY_RSA=$sysconfdir/ssh_host_rsa_key |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 21 | |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 22 | |
| 23 | checkkeys() { |
| 24 | if [ ! -f $HOST_KEY_RSA1 ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 25 | ${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 26 | fi |
| 27 | if [ ! -f $HOST_KEY_DSA ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 28 | ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 29 | fi |
| 30 | if [ ! -f $HOST_KEY_RSA ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 31 | ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 32 | fi |
| 33 | } |
| 34 | |
| 35 | stop_service() { |
| 36 | if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 37 | PID=`${CAT} ${PIDFILE}` |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 38 | fi |
| 39 | if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 40 | ${KILL} ${PID} |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 41 | else |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 42 | echo "Unable to read PID file" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 43 | fi |
| 44 | } |
| 45 | |
| 46 | start_service() { |
| 47 | # XXX We really should check if the service is already going, but |
| 48 | # XXX we will opt out at this time. - Bal |
| 49 | |
| 50 | # Check to see if we have keys that need to be made |
| 51 | checkkeys |
| 52 | |
| 53 | # Start SSHD |
| 54 | echo "starting $SSHD... \c" ; $SSHD |
| 55 | |
| 56 | sshd_rc=$? |
| 57 | if [ $sshd_rc -ne 0 ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 58 | echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing." |
| 59 | exit $sshd_rc |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 60 | fi |
| 61 | echo done. |
| 62 | } |
| 63 | |
| 64 | case $1 in |
| 65 | |
| 66 | 'start') |
| 67 | start_service |
| 68 | ;; |
| 69 | |
| 70 | 'stop') |
| 71 | stop_service |
| 72 | ;; |
| 73 | |
| 74 | 'restart') |
| 75 | stop_service |
| 76 | start_service |
| 77 | ;; |
| 78 | |
| 79 | *) |
| 80 | echo "$0: usage: $0 {start|stop|restart}" |
| 81 | ;; |
| 82 | esac |