#! /bin/sh

#
# --- MUST escape all '$' AND all '`' (backticks) AND all '\' ---
#
# in other words: `\' must be used to quote the
#                 characters `\', `$', and ``'
#

cat > _INSTALL_NAME_.boot <<EOF
#!/bin/sh

if test "x_PREFIX_" = "xOPT"; then
   SBINDIR=/opt/_INSTALL_NAME_/bin
else
   SBINDIR=_PREFIX_/sbin
fi

if [ ! -f \${SBINDIR}/_INSTALL_NAME_ ]; then
        exit 0
fi


case "\$1" in
    start)
        echo "_INSTALL_NAME_ starting."
	/bin/rm -f /var/run/_INSTALL_NAME_.pid
        ;;
    stop)
        echo "_INSTALL_NAME_ stopping."
        ;;
    restart)
        echo "_INSTALL_NAME_ restarting."
        ;;
    reload)
        echo "_INSTALL_NAME_ reloading."
        ;;
    *)
        echo "Usage: \$0 {start|stop|restart|reload}"
        exit 1
        ;;
esac

\${SBINDIR}/_INSTALL_NAME_  \$1

status=\$?

if [ \$status != 0 ]; then
    echo \$status
    exit 1
fi

exit 0
EOF

  # exit 0   # FIXME

if test -d /etc/init.d; then
    cp _INSTALL_NAME_.boot /etc/init.d/_INSTALL_NAME_;
    chmod 0744 /etc/init.d/_INSTALL_NAME_;
    chown root:sys /etc/init.d/_INSTALL_NAME_;
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc2.d/S99_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc3.d/S99_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc4.d/S99_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc5.d/S99_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc2.d/K10_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc3.d/K10_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc4.d/K10_INSTALL_NAME_); 
    (cd /etc/init.d && ln _INSTALL_NAME_ /etc/rc5.d/K10_INSTALL_NAME_); 
else
    echo "Could not find an appropriate place for boot script ..."; 
    echo ".. tried /etc/init.d  (Solaris)"; 
  fi
fi

### Uncomment this to start the client.
### Note that you need to have everything ready on the server side
### when the client is starting, else it will abort.

# echo '/etc/init.d/_INSTALL_NAME_ start' | at now + 1hour 
