Darren Tucker | fbea764 | 2006-01-30 00:22:39 +1100 | [diff] [blame] | 1 | #!@STARTUP_SCRIPT_SHELL@ |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 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 |
Tim Rice | 53e9974 | 2009-11-20 19:32:15 -0800 | [diff] [blame] | 17 | PidFile=`grep "^PidFile" ${sysconfdir}/sshd_config | tr "=" " " | awk '{print $2}'` |
| 18 | [ X$PidFile = X ] || PIDFILE=$PidFile |
Ben Lindstrom | 7a97339 | 2001-10-12 21:52:39 +0000 | [diff] [blame] | 19 | SSH_KEYGEN=$prefix/bin/ssh-keygen |
Tim Rice | 5af9db9 | 2004-06-19 19:31:06 -0700 | [diff] [blame] | 20 | HOST_KEY_RSA1=$sysconfdir/ssh_host_key |
| 21 | HOST_KEY_DSA=$sysconfdir/ssh_host_dsa_key |
| 22 | HOST_KEY_RSA=$sysconfdir/ssh_host_rsa_key |
Tim Rice | 9b87a5c | 2011-01-12 22:35:43 -0800 | [diff] [blame] | 23 | @COMMENT_OUT_ECC@HOST_KEY_ECDSA=$sysconfdir/ssh_host_ecdsa_key |
Tim Rice | 9c36698 | 2014-03-14 12:45:01 -0700 | [diff] [blame] | 24 | HOST_KEY_ED25519=$sysconfdir/ssh_host_ed25519_key |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 25 | |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 26 | |
| 27 | checkkeys() { |
| 28 | if [ ! -f $HOST_KEY_RSA1 ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 29 | ${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 30 | fi |
| 31 | if [ ! -f $HOST_KEY_DSA ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 32 | ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 33 | fi |
| 34 | if [ ! -f $HOST_KEY_RSA ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 35 | ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 36 | fi |
Tim Rice | 9b87a5c | 2011-01-12 22:35:43 -0800 | [diff] [blame] | 37 | @COMMENT_OUT_ECC@ if [ ! -f $HOST_KEY_ECDSA ]; then |
| 38 | @COMMENT_OUT_ECC@ ${SSH_KEYGEN} -t ecdsa -f ${HOST_KEY_ECDSA} -N "" |
| 39 | @COMMENT_OUT_ECC@ fi |
Tim Rice | 9c36698 | 2014-03-14 12:45:01 -0700 | [diff] [blame] | 40 | if [ ! -f $HOST_KEY_ED25519 ]; then |
| 41 | ${SSH_KEYGEN} -t ed25519 -f ${HOST_KEY_ED25519} -N "" |
| 42 | fi |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | stop_service() { |
| 46 | if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 47 | PID=`${CAT} ${PIDFILE}` |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 48 | fi |
| 49 | if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 50 | ${KILL} ${PID} |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 51 | else |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 52 | echo "Unable to read PID file" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 53 | fi |
| 54 | } |
| 55 | |
| 56 | start_service() { |
| 57 | # XXX We really should check if the service is already going, but |
| 58 | # XXX we will opt out at this time. - Bal |
| 59 | |
| 60 | # Check to see if we have keys that need to be made |
| 61 | checkkeys |
| 62 | |
| 63 | # Start SSHD |
| 64 | echo "starting $SSHD... \c" ; $SSHD |
| 65 | |
| 66 | sshd_rc=$? |
| 67 | if [ $sshd_rc -ne 0 ]; then |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 68 | echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing." |
| 69 | exit $sshd_rc |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 70 | fi |
| 71 | echo done. |
| 72 | } |
| 73 | |
| 74 | case $1 in |
| 75 | |
| 76 | 'start') |
| 77 | start_service |
| 78 | ;; |
| 79 | |
| 80 | 'stop') |
| 81 | stop_service |
| 82 | ;; |
| 83 | |
| 84 | 'restart') |
| 85 | stop_service |
| 86 | start_service |
| 87 | ;; |
| 88 | |
| 89 | *) |
| 90 | echo "$0: usage: $0 {start|stop|restart}" |
| 91 | ;; |
| 92 | esac |