#!/bin/sh

# all done with the installer, a few things to do.
#

# Add /usr/local/bin to the path
echo $PATH | grep -q -s '/usr/local/bin'
if [ $? == 1 ]; then
    echo "" >> ~/.profile
    echo "" >> ~/.profile
    echo "##" >> ~/.profile
    echo "# this will add /usr/local/bin to your \"PATH\"" >> ~/.profile
    echo "# the PATH is where OS X looks for commands you enter," >> ~/.profile
    echo "# searching each item on the list in turn." >> ~/.profile
    echo "#" >> ~/.profile
    echo "# added by the man2html installer package" >> ~/.profile
    echo "#" >> ~/.profile
    echo "echo \$PATH | grep -q -s '/usr/local/bin'" >> ~/.profile
    echo "if [ \$? == 1 ] ; then" >> ~/.profile
    echo "    PATH=\$PATH:/usr/local/bin" >> ~/.profile
    echo "    export PATH" >> ~/.profile
    echo "fi" >> ~/.profile
    echo "#" >> ~/.profile
    echo "# if /usr/local/bin is already in your PATH," >> ~/.profile
    echo "# this section does exactly nothing." >> ~/.profile
    echo "##" >> ~/.profile
    echo "" >> ~/.profile
fi

# okay, maybe it's paranoia, but I'm gonna make sure these scripts are executable
# Apache needs *every* directory in the cgi's path to be searchable, or else
# cgi scripts just fail.

sudo chown root:wheel /usr/local/bin/man2html /Library/WebServer/CGI-Executables /Library/WebServer/CGI-Executables/man.cgi /usr/local/man/man1/man2html.1

sudo chown root:admin /Library/WebServer

sudo chmod 755 /usr/local/bin /usr/local/bin/man2html /Library/WebServer /Library/WebServer/CGI-Executables /Library/WebServer/CGI-Executables/man.cgi /usr/local/man/man1/man2html.1

echo "man2html initialised.."

open http://localhost/cgi-bin/man.cgi