#!/bin/sh
  # Add mod_perl to modules list
  if [ -f /usr/libexec/httpd/addons-list ] ; then
    if ! grep -q '^perl$' /usr/libexec/httpd/addons-list ; then
      echo perl >> /usr/libexec/httpd/addons-list
    fi
  else
    echo perl > /usr/libexec/httpd/addons-list
  fi
  if [ -f /home/httpd/html/manual/mod/index.html ] ; then
    # Add mod_perl documenatition link in index.html before mod_proxy link
    if grep -q '<A HREF="mod_proxy.html">mod_proxy</A>' /home/httpd/html/manual/mod/index.html ; then
      if ! grep -q '<!-- mod_perl documentation link -->' /home/httpd/html/manual/mod/index.html ; then
        sed "s|^\\(.*<A HREF=\"mod_proxy.html\">mod_proxy</A>.*\\)\$|<!-- mod_perl documentation link -->\\
<DT><A HREF=\"mod_perl.html\">mod_perl</A>\\
<DD>Apache/Perl integration\\
<\!-- mod_perl documentation link end -->\\
\1|" < /home/httpd/html/manual/mod/index.html > /home/httpd/html/manual/mod/index.html- 
        mv -f /home/httpd/html/manual/mod/index.html- /home/httpd/html/manual/mod/index.html
      fi
    fi
  fi
  if [ -f /home/httpd/html/index.html ] ; then
    if grep -q "<\!-- 'Powered by' icons for addons will be put here -->" /home/httpd/html/index.html ; then
      if ! grep -q '<!-- mod_perl site link -->' /home/httpd/html/index.html ; then
        sed "s|^<\!-- 'Powered by' icons for addons will be put here -->\$|<\!-- 'Powered by' icons for addons will be put here -->\\
<\!-- mod_perl site link -->\\
  <P> You are free to use the image below on an\\
  mod_perl-powered web server.  Thanks for using mod_perl! </P>\\
  <P ALIGN=\"CENTER\"> <a href=\"http://perl.apache.org/\">\\
  <IMG SRC=\"mod_perl.gif\" WIDTH=90 HEIGHT=30 BORDER=0 ALT=\"[ Powered by mod_perl ]\"></a>\\
  </P>\\
<\!-- mod_perl site link end -->|" < /home/httpd/html/index.html > /home/httpd/html/index.html- 
        mv -f /home/httpd/html/index.html- /home/httpd/html/index.html
      fi 
    fi  
  fi

  if [ -f /etc/httpd/conf/srm.conf ] ; then
  # Add mod_perl handling
    if ! grep -q '^\# mod_perl support$' /etc/httpd/conf/srm.conf ; then
      cat >>/etc/httpd/conf/srm.conf <<End
# mod_perl support
<IfModule mod_perl.c>
<Files ~ "\.PL$">
SetHandler perl-script
PerlHandler Apache::Registry
Options ExecCGI
</Files>
</IfModule>
# End of mod_perl support
End
    fi

    # Now change DirectoryIndex -- include index.PL there
    if ! grep -q '^ *DirectoryIndex.*index\.PL' /etc/httpd/conf/srm.conf ; then
      sed 's/\(^ *DirectoryIndex\)\(.*$\)/\1\2 index.PL/' < /etc/httpd/conf/srm.conf > /etc/httpd/conf/srm.conf-
      mv -f /etc/httpd/conf/srm.conf- /etc/httpd/conf/srm.conf
    fi
  fi

  if [ -f /etc/httpd/conf/httpd.conf ] ; then
    # Add LoadModule string
    if ! grep -q '.*LoadModule *perl_module' /etc/httpd/conf/httpd.conf ; then
      sed "s|^\#Addon's LoadModule's will go here\$|#Addon's LoadModule's will go here\\
LoadModule perl_module        libexec/httpd/mod_perl.so|" < /etc/httpd/conf/httpd.conf > /etc/httpd/conf/httpd.conf- 
      mv -f /etc/httpd/conf/httpd.conf- /etc/httpd/conf/httpd.conf
    fi

    # Add AddModule string
    if ! grep -q '.*AddModule *mod_perl\.c' /etc/httpd/conf/httpd.conf ; then
      sed "s|^\#Addon's AddModule's will go here\$|#Addon's AddModule's will go here\\
AddModule mod_perl.c|" < /etc/httpd/conf/httpd.conf > /etc/httpd/conf/httpd.conf- 
      mv -f /etc/httpd/conf/httpd.conf- /etc/httpd/conf/httpd.conf
    fi
  fi
