#!/bin/sh

LG=$1
CG=$2
HM=$3

umask 022

rm -f /usr/lib/apache/suexecdir/${LG}
if [ ${CG} = "no" ] ;then
  ln -s ../noncgi.sh /usr/lib/apache/suexecdir/${LG}
  exit 0;
fi

cp /usr/lib/apache/suexec-user /usr/lib/apache/suexecdir/${LG}
chown ${LG} /usr/lib/apache/suexecdir/${LG}
chgrp ${LG} /usr/lib/apache/suexecdir/${LG}
chmod 6111 /usr/lib/apache/suexecdir/${LG}

FL=`echo $LG | sed '
	s/^./&KILLAFTER/
	s/KILLAFTER.*$//
	'`
if [ ! -f ${HM}/.apache-suid ] ;then
  AST='*'
  echo "run:/home/${FL}/${LG}/www/${AST}" > ${HM}/.apache-suid
  echo "run:/home/${FL}/${LG}/_vti_bin/${AST}" >> ${HM}/.apache-suid
  chown ${LG} ${HM}/.apache-suid
  chgrp ${LG} ${HM}/.apache-suid
  chmod 644 ${HM}/.apache-suid
fi

if [ ! -d ${HM}/www/cgi-bin ] ;then
  mkdir ${HM}/www 2>>/dev/null
  mkdir ${HM}/www/cgi-bin
  echo "SetHandler cgi-script" > ${HM}/www/cgi-bin/.htaccess
  CGIS="date debug debugh mailto nph-test.cgi test-cgi.tcl test.cgi"
  for i in ${CGIS} ;do
    cp /usr/lib/cgi-bin/${i} ${HM}/www/cgi-bin/${i}
    chmod 755 ${HM}/www/cgi-bin/${i}
  done
  chown -R ${LG} ${HM}/www/cgi-bin
  chgrp -R ${LG} ${HM}/www/cgi-bin
  chmod 755 ${HM}/www/cgi-bin
  chmod 644 ${HM}/www/cgi-bin/.htaccess
fi

exit 0
