# This patch removes all need to run vpopmail's make as root...
# this is needed for package building as a non-root user.
# 
#  - removes explicit root test
#  - removes compile testing for vpopmail uid/gid
#  - expects vpopmail.{uid,gid,dir} files to be present already
#  - removes creation of vpopmaildir and vpopmaildir/etc
#  - add a default vpopmail.mysql file to the dist rather than
#    writing one in the Makefile
#  - remove -o/-g from install commands used in make install
#  - note: line 230 expects libvpopmail.a to be specified in terms of
#    $(libdir), NOT $(prefix)/lib -- apply that patch first
# 
# Japheth Cleaver
# <cleaver@rohan.sdsu.edu>
# 

# A common value for vpopmail's uid is 89...
# 
# You will need to create the vpopmail.{uid,gid,dir} files manually
# and re-run automake and autoconf prior to continuing!
# 

--- configure.in.no-root-needed	2004-07-21 12:48:38.000000000 -0700
+++ configure.in	2004-07-21 13:13:16.000000000 -0700
@@ -374,73 +368,10 @@
 
 AC_MSG_RESULT(yes)
 
-AC_MSG_CHECKING(whether password file entry for the vpopmail user exists)
-AC_TRY_RUN( [
-  #include <stdio.h>
-  #include <pwd.h>
-  #include <stdlib.h>
-
-  int main() {
-    struct passwd *pw;
-    char tmpbuf[100];
-    FILE *f;
-
-        unlink("vpopmail.dir");
-        unlink("vpopmail.uid");
-        unlink("vpopmail.gid");
-
-        if ( (f=fopen("vpopusername","r+"))==NULL) {
-                printf("No vpopmail user found.\n");
-                printf("Please add the vchkpw group and\n");
-                printf("vpopmail user. Then run configure again\n");
-                return(-1);
-        }
-
-        fgets(tmpbuf,100,f);
-        fclose(f);
-        tmpbuf[strlen(tmpbuf)-1] = 0;
-
-        if (( pw=getpwnam(tmpbuf)) != 0 ) {
-                f=fopen("vpopmail.dir","a+");
-                fprintf(f,"%s\n", pw->pw_dir);
-                fclose(f);
-
-                f=fopen("vpopmail.uid", "a+");
-                fprintf(f,"%d\n", pw->pw_uid);
-                fclose(f);
-
-                f=fopen("vpopmail.gid", "a+");
-                fprintf(f,"%d\n", pw->pw_gid);
-                fclose(f);
-        } else {
-                printf("No vpopmail user found.\n");
-                printf("Please add the vchkpw group and\n");
-                printf("vpopmail user. Then run configure again\n");
-                return(-1);
-        }
-        return(0);
-  }
-  ],
-    AC_MSG_RESULT(yes),
-    AC_MSG_RESULT(no)
-    AC_MSG_ERROR(Could not compile and run even a trivial ANSI C program - check CC.),
-    AC_MSG_ERROR(Could not compile and run even a trivial ANSI C program - check CC.)
-)
+### SKIPPING TEST FOR ACTUAL VPOPMAIL/VCHKPW USER ###
 
-if test ! -f vpopmail.uid
-then
-        AC_MSG_ERROR(No vpopmail user.)
-fi
 
-if test ! -f vpopmail.gid
-then
-        AC_MSG_ERROR(No vpopmail group.)
-fi
 
-if test ! -f vpopmail.dir
-then
-        AC_MSG_ERROR(No vpopmail home directory)
-fi
 
 vpopmaildir=`cat vpopmail.dir`
 AC_SUBST(vpopmaildir)
@@ -458,22 +389,7 @@
 
 #----------------------------------------------------------------------
 
-if test ! -d $vpopmaildir/etc
-then
-  if test ! -d $vpopmaildir
-  then
-    AC_MSG_WARN( creating $vpopmaildir )
-    mkdir -p $vpopmaildir
-    chown $vpopmailuid $vpopmaildir
-    chgrp $vpopmailgid $vpopmaildir
-    chmod 755 $vpopmaildir
-  fi
-  AC_MSG_WARN( making a vpopmail etc directory )
-  mkdir $vpopmaildir/etc
-  chown $vpopmailuid "$vpopmaildir"/etc
-  chgrp $vpopmailgid "$vpopmaildir"/etc
-  chmod 755 "$vpopmaildir"/etc
-fi
+### SKIPPING VPOPMAILDIR CREATION ###
 
 #----------------------------------------------------------------------
 
@@ -541,20 +457,12 @@
         [
             if test "$tcpserver_file" = ""
             then
-                AC_MSG_WARN([Unable to find your tcpserver relay file.])
-                AC_MSG_WARN([Creating tcp.smtp in "$vpopmaildir"/etc/tcp.smtp.])
-
-                echo "127.:allow,RELAYCLIENT=\"\"" > "$vpopmaildir"/etc/tcp.smtp
-                tcpserver_file="$vpopmaildir"/etc/tcp.smtp
+		AC_MSG_RESULT(no)
+                AC_MSG_ERROR([Unable to find your tcpserver relay file, specify --enable-tcpserver-path=/full/path/to/tcp.smtp])
             fi
         ]
     )
 
-    if test ! -f "$tcpserver_file"
-    then
-        AC_MSG_ERROR([Unable to find your tcp.smtp file, specify --enable-tcpserver-path=/full/path/to/tcp.smtp])
-    fi
-
     AC_MSG_RESULT(yes)
     AC_DEFINE_UNQUOTED(TCP_FILE,"$tcpserver_file","")
 
--- vpopmail.mysql.no-root-needed	2003-09-15 06:40:47.000000000 -0700
+++ vpopmail.mysql	2004-07-21 17:21:35.000000000 -0700
@@ -0,0 +1,17 @@
+# MYSQL CONNECTION SETTINGS FOR VPOPMAIL
+#
+# Line 1 defines the connection to use for database reads,
+# Line 2 defines the connection to use for database updates/writes.
+#
+# If you omit line 2, then the same settings will be
+# used for both read and write.
+#
+# settings for each line:
+# host|port|user|password|database
+#
+localhost|0|root|secret|vpopmail
+#
+# Note:
+#   The value of host may be either a hostname or an IP address.
+#   If host is 'localhost', then sockets (Unix) or named pipes (Windows)
+#   will be used instead of TCP/IP to connect to the server.
--- Makefile.am.no-root-needed	2006-04-28 19:13:42.000000000 -0700
+++ Makefile.am	2006-04-28 21:14:25.000000000 -0700
@@ -13,7 +13,7 @@
 
 CONFIG_CLEAN_FILES=vauth.c
 
-INSTALL_PROGRAM= ${INSTALL} -o @vpopuser@ -m 711 -g @vpopgroup@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_PROGRAM= ${INSTALL} -m 711 $(AM_INSTALL_PROGRAM_FLAGS)
 INSTALL_STRIP_PROGRAM=${INSTALL_PROGRAM} -s
 
 MYSQLCONF=$(DESTDIR)$(sysconfdir)/vpopmail.mysql
@@ -109,13 +109,13 @@
 install-exec-am:
 	for d in bin doc etc include lib ; do \
 	  if test ! -d $(DESTDIR)@vpopmaildir@/$$d; then \
-	    $(INSTALL) -d -g @vpopgroup@ -m 0755 -o @vpopuser@ \
+	    $(INSTALL) -d -m 0755 \
 	      $(DESTDIR)@vpopmaildir@/$$d ; \
 	  fi ; \
 	done
 
 install-data-local:
-	$(INSTALL) -d -g @vpopgroup@ -m 0700 -o @vpopuser@ \
+	$(INSTALL) -d -m 0700 \
 	  $(DESTDIR)@vpopmaildir@/@domains_dir@
 
 	echo "-I$(includedir) -I@vpopmaildir@/include" > \
@@ -124,51 +124,33 @@
 	 $(DESTDIR)@vpopmaildir@/etc/lib_deps
 
 	if test ! -r $(VLIMITS); then \
-	  $(INSTALL) -o @vpopuser@ -m 0644 -g @vpopgroup@ \
+	  $(INSTALL) -m 0644 \
 	    vlimits.default $(VLIMITS); \
 	fi
 	if test "@USE_MYSQL@" = "1"; then \
 	  if test ! -r $(MYSQLCONF); then \
-	    echo "# MYSQL CONNECTION SETTINGS FOR VPOPMAIL" >> $(MYSQLCONF); \
-	    echo "#" >> $(MYSQLCONF); \
-	    echo "# Line 1 defines the connection to use for database reads," >> $(MYSQLCONF); \
-	    echo "# Line 2 defines the connection to use for database updates/writes." >> $(MYSQLCONF); \
-	    echo "#" >> $(MYSQLCONF); \
-	    echo "# If you omit line 2, then the same settings will be" >> $(MYSQLCONF); \
-	    echo "# used for both read and write." >> $(MYSQLCONF); \
-	    echo "#" >> $(MYSQLCONF); \
-	    echo "# settings for each line:" >> $(MYSQLCONF); \
-	    echo "# host|port|user|password|database" >> $(MYSQLCONF); \
-	    echo "#" >> $(MYSQLCONF); \
-	    echo "localhost|0|root|secret|vpopmail" >> $(MYSQLCONF); \
-	    echo "#" >> $(MYSQLCONF); \
-	    echo "# Note:" >> $(MYSQLCONF); \
-	    echo "#   The value of host may be either a hostname or an IP address." >> $(MYSQLCONF); \
-	    echo "#   If host is 'localhost', then sockets (Unix) or named pipes (Windows)" >> $(MYSQLCONF); \
-	    echo "#   will be used instead of TCP/IP to connect to the server."   >> $(MYSQLCONF); \
+	    $(INSTALL) -m 0640 \
+	      vpopmail.mysql $(MYSQLCONF); \
 	  fi ; \
-	  chown @vpopuser@  $(MYSQLCONF) ; \
-	  chgrp @vpopgroup@ $(MYSQLCONF) ; \
-	  chmod 0640        $(MYSQLCONF) ; \
 	fi
 
-	$(INSTALL) -o root -m 0644 \
+	$(INSTALL) -m 0644 \
 	  libvpopmail.a $(DESTDIR)$(libdir)/libvpopmail.a
 
-	$(INSTALL) -o root -m 0444 \
+	$(INSTALL) -m 0444 \
 	  config.h $(DESTDIR)$(includedir)/vpopmail_config.h
 
 	for include in vpopmail.h config.h vauth.h vlimits.h ; do \
-	    $(INSTALL) -o root -m 0444 $$include \
+	    $(INSTALL) -m 0444 $$include \
 		$(DESTDIR)$(includedir) ; \
 	done
 
 	$(INSTALL) -d $(DESTDIR)@vpopmaildir@/doc/man_html
 	$(INSTALL) -d $(DESTDIR)@vpopmaildir@/doc/doc_html
-	$(INSTALL) -o @vpopuser@ -m 0444 -g @vpopgroup@ \
+	$(INSTALL) -m 0444 \
 	  doc/man_html/*.* $(DESTDIR)@vpopmaildir@/doc/man_html/
 
-	$(INSTALL) -o @vpopuser@ -m 0444 -g @vpopgroup@ \
+	$(INSTALL) -m 0444 \
 	  doc/doc_html/*.* $(DESTDIR)@vpopmaildir@/doc/doc_html/
 
 fix-priv:
