#!/bin/sh
#
# MacPorts generated daemondo support script
#

#
# Init
#
prefix=/opt/local

#
# Start
#
Start()
{
	if [ -x /opt/local/sbin/sshd ]; then
            if [ ! -f /opt/local/etc/ssh/ssh_host_rsa_key ]; then
                /opt/local/bin/ssh-keygen -t rsa -f \
                /opt/local/etc/ssh/ssh_host_rsa_key -N "" -C `hostname`
            fi
            if [ ! -f /opt/local/etc/ssh/ssh_host_ecdsa_key ]; then
                /opt/local/bin/ssh-keygen -t ecdsa -f \
                /opt/local/etc/ssh/ssh_host_ecdsa_key -N "" -C `hostname`
            fi
            if [ ! -f /opt/local/etc/ssh/ssh_host_ed25519_key ]; then
                /opt/local/bin/ssh-keygen -t ed25519 -f \
                /opt/local/etc/ssh/ssh_host_ed25519_key -N "" -C `hostname`
            fi
            /opt/local/sbin/sshd
        fi
}

#
# Stop
#
Stop()
{
	if [ -r /opt/local/var/run/sshd.pid ]; then
            kill `cat /opt/local/var/run/sshd.pid`
        fi
}

#
# Restart
#
Restart()
{
	Stop
	Start
}

#
# Run
#
Run()
{
case $1 in
  start  ) Start   ;;
  stop   ) Stop    ;;
  restart) Restart ;;
  *      ) echo "$0: unknown argument: $1";;
esac
}

#
# Run a phase based on the selector
#
Run $1

