--- install-sh	2008-07-18 21:38:22.000000000 -0400
+++ foo-sh	2008-07-18 21:37:56.000000000 -0400
@@ -99,22 +99,28 @@
 
 # ---------------------------------------------------------- line100 --- sh --
 <?php
-
+$prefix_args = find_prefix();
+if (isset($prefix_args['prefix'])) {
+	$PREFIX=$prefix_args['prefix'];
+	echo "Found install prefix of: ". $PREFIX."\n";
+} else {
+	$PREFIX = '';
+}
 # -- Default installation directories.
 $setup = array(
-	"BIN" => "/usr/sbin",
-	"LIB" => "/usr/lib/nanoweb",
-	"CONF" => "/etc/nanoweb",
-	"LOG" => "/var/log/nanoweb",
-	"WWWROOT" => "/var/www/localhost",
-	"DOC" => "/usr/share/doc/nanoweb",
+	"BIN" => $PREFIX."/usr/sbin",
+	"LIB" => $PREFIX."/usr/lib/nanoweb",
+	"CONF" => $PREFIX."/etc/nanoweb",
+	"LOG" => $PREFIX."/var/log/nanoweb",
+	"WWWROOT" => $PREFIX."/var/www/localhost",
+	"DOC" => $PREFIX."/usr/share/doc/nanoweb",
 	"NWGROUP" => "www-data",
 	"NWUSER" => "www-data",
 	"INETD" => "1",
 	"INIT" => "1",
-	"PHP" => "/usr/local/bin/php",
-	"MANDIR" => "/usr/share/man",
-	"SSLDIR" => "/etc/ssl/certs",
+	"PHP" => $PREFIX."/usr/bin/php",
+	"MANDIR" => $PREFIX."/usr/share/man",
+	"SSLDIR" => $PREFIX."/etc/ssl/certs",
 	"DONE" => ''
 );
 
@@ -360,8 +366,10 @@
 
 	global $setup;
 
-	if ($binary = getenv("PHP_BIN")) {
-		$setup["PHP"] = $binary;
+	if (!isset($setup["PHP"])) {
+		if ($binary = getenv("PHP_BIN")) {
+			$setup["PHP"] = $binary;
+		}
 	}
 
 	if ($uu = dirname(`which nanoweb.php`)) {
@@ -414,13 +422,32 @@
 		case "--verbose":
 		$ret["verbose"]=true;
 		break;
-	
+
 	}
 
 	return($ret);
 
 }
 
+function find_prefix() {
+	$ret=array();
+	
+	foreach($_SERVER["argv"] as $k => $arg) {
+
+		if ($arg ==  "-p") {
+			$ret["prefix"]=$_SERVER["argv"][$k+1];
+		}
+
+		if (strpos($arg, "--prefix") !== FALSE) {
+			list ($zero, $prefix) = explode('=', $arg);
+			$ret["prefix"]=$prefix;
+
+		}
+	}
+
+	return($ret);
+}
+
 
 function init_defines() {
 
@@ -531,6 +558,7 @@
 		install_files("conf/modules.conf", "$CONF/modules.conf");
 		install_files("conf/vhosts.conf", "$CONF/vhosts.conf");
 		
+		/*
 		if (file_exists("/etc/mime.types")) {
 		
 			make_symlink("/etc/mime.types", "$CONF/mime.types");
@@ -540,6 +568,8 @@
 			install_files("conf/mime.types", "$CONF/mime.types");
 
 		}
+		*/
+		install_files("conf/mime.types", "$CONF/mime.types");
 
 		#-- update config files with install-sh settings
 		patch_configs();
@@ -562,6 +592,7 @@
 
 
 function update_config_files_new_version() {
+	global $PREFIX;
    extract($GLOBALS["setup"]);
 
    $trans = array(
@@ -584,7 +615,7 @@
          'ServerTheme' => "ServerTheme = default \n",
          'DisableMimeMagic' => "DisableMimeMagic = 0 \n",
 	 /* 2.1.1 */
-         'LogDir' => "LogDir = /var/log/nanoweb/ \n",
+         'LogDir' => "LogDir = '.$PREFIX.'/var/log/nanoweb/ \n",
       ),
       "modules.conf" => array(
          /* 1.9.0 */
@@ -816,6 +847,7 @@
 
 function patch_configs() {
 
+	global $PREFIX;
 	extract($GLOBALS["setup"]);
 
 	echo bold("Adjusting configuration files with your settings\n");
@@ -829,6 +861,9 @@
 			$conf = preg_replace('# /usr/lib/nanoweb#m', " $LIB", $conf);
 			$conf = preg_replace('# /etc/nanoweb#m', " $CONF", $conf);
 			$conf = preg_replace('# /var/www/localhost#m', " $WWWROOT", $conf);
+			$conf = preg_replace('# /var/run/nanoweb\.pid#m', " ".$PREFIX."/var/run/nanoweb.pid", $conf);
+			$conf = preg_replace('# /var/log/nanoweb#m', " ".$PREFIX."/var/log/nanoweb", $conf);
+			$conf = preg_replace('# 80#m', " 8443", $conf);
 
 			$conf = preg_replace('#(\nGroup\s+=\s*)www-data#m', "$1" . $NWGROUP, $conf);
 			$conf = preg_replace('#(\nUser\s+=\s*)www-data#m', "$1" . $NWUSER, $conf);
@@ -856,6 +891,7 @@
 		if ($bin = @implode("", @file($BIN . $bf))) {
 
 			$bin = preg_replace('|^#!/usr/local/bin/php|', "#!" . $PHP, $bin);
+			$bin = preg_replace('|/etc/nanoweb|',  $CONF, $bin);
 			$bin = preg_replace('|/usr/sbin/nanoweb.php|', $BIN . "/nanoweb.php", $bin);
 
 			if ($f = @fopen($BIN . $bf, "w")) {

