#!/bin/sh

# a wee script to initialise man2html. Feel free to use any part.

# 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


# this will setup the file permissions. Use the heirarchy in the "local" folder
# or edit the values here to match your own locations.
#
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

# remember, apache needs the permissions correct on *all* the folders in the path *to* the cgi, not just the cgi folder itself.

echo "man2html initialised.."
echo ""

# opens the page in your favourite browser
open http://localhost/cgi-bin/man.cgi