Hi,

Mark Duling wrote:
Hello,

Would it be possible to add DESTDIR support in a future release of nfsen? I don't know perl or I'd contribute the mods myself. It is standard with
Makefiles, and even though nfsen doesn't use a Makefile to install itself
it would make packaging it for some package managers much easier.  That
way the install routine can be "installed" to DESTDIR but relocated to
somewhere else by the package manager infrastructure without confusing the
installed program.  This is accomplished by setting all configuration
locations to $PREFIX/path (or $BASEDIR in the case of nfsen) while
installing and copying files to $DESTROOT/$PREFIX.  I'd like to package it
for use with MacPorts and it will require some ugly hacks without DESTDIR
support.  I think openbsd packages require this also, at least when using
certain options.
I have implemented DESTDIR feature. In my patch this variable it is called INSTALLPREFIX.

--
Erik Wenzel
diff -urNad nfsen~/installer-items/RRDconvertv1.pm nfsen/installer-items/RRDconvertv1.pm
--- nfsen~/installer-items/RRDconvertv1.pm	2008-03-07 14:46:23.000000000 +0000
+++ nfsen/installer-items/RRDconvertv1.pm	2008-03-07 14:48:04.000000000 +0000
@@ -161,17 +161,20 @@
 	my $profilename = shift;
 
 	my $index = 0;
+	my ($login,$pass,$uid,$gid) = ("", "", "", "");
+	if ( !defined $ENV{'INSTALLPREFIX'} ) {
+	    ($login,$pass,$uid,$gid) = getpwnam($NfConf::WWWUSER);
+	    if ( !defined $login ) {
+		    die "NFSEN user '$NfConf::WWWUSER' not found on this system\n";
+	    }
 
-    my ($login,$pass,$uid,$gid) = getpwnam($NfConf::WWWUSER);
-    if ( !defined $login ) {
-            die "NFSEN user '$NfConf::WWWUSER' not found on this system\n";
-    }
-
-    if ( defined $NfConf::WWWGROUP ) {
-        $gid  = getgrnam($NfConf::WWWGROUP) || 
-            die "NFSEN group '$NfConf::WWWGROUP' not found on this system\n";
-    }
-
+	    if ( defined $NfConf::WWWGROUP ) {
+		$gid  = getgrnam($NfConf::WWWGROUP) || 
+		    die "NFSEN group '$NfConf::WWWGROUP' not found on this system\n";
+	    }
+	} else {
+		($login,$pass,$uid,$gid) = ( "root", "", "0", "0");
+	}
 	my %profileinfo = NfProfile::ReadProfile($profilename);
 	if ( $profileinfo{'status'} eq 'empty' ) {
 		print "Error Reading profile '$profilename'. Abort conversion\n";
@@ -189,7 +192,9 @@
 			return 0;
 		}
 		NfSenRRD::SetupRRD("$NfConf::PROFILESTATDIR/$profilename", $source, $start_time - 300, 1);
-		chown $uid, $gid, "$NfConf::PROFILESTATDIR/$profilename/$source.rrd";
+		if ( !defined($ENV{'INSTALLPREFIX'}) ) {
+			chown $uid, $gid, "$NfConf::PROFILESTATDIR/$profilename/$source.rrd";
+		}
 	}
 
 	$| = 1;
diff -urNad nfsen~/libexec/NfConf.pm nfsen/libexec/NfConf.pm
--- nfsen~/libexec/NfConf.pm	2008-03-07 14:46:23.000000000 +0000
+++ nfsen/libexec/NfConf.pm	2008-03-07 14:46:25.000000000 +0000
@@ -176,21 +176,26 @@
 		$PICDIR = $BACKEND_PLUGINDIR;
 	}
 
-	my ($login,$pass,$uid,$gid) = getpwnam($USER);
-	if ( !defined $login ) {
-		$Log::ERROR =  "NFSEN user '$USER' not found on this system ";
-		return undef;
-	}
-
-	$UID = $uid;
-	if ( defined $WWWGROUP ) {
-		$gid  = getgrnam($WWWGROUP);
-		if ( !defined $gid ) {
-			$Log::ERROR =  "NFSEN group '$WWWGROUP' not found on this system ";
+	if ( !defined($ENV{'INSTPREFIX'}) ) {
+		my ($login,$pass,$uid,$gid) = getpwnam($USER);
+		if ( !defined $login ) {
+			$Log::ERROR =  "NFSEN user '$USER' not found on this system ";
 			return undef;
 		}
+
+		$UID = $uid;
+		if ( defined $WWWGROUP ) {
+			$gid  = getgrnam($WWWGROUP);
+			if ( !defined $gid ) {
+				$Log::ERROR =  "NFSEN group '$WWWGROUP' not found on this system ";
+				return undef;
+			}
+		}
+		$GID = $gid;
+	} else {
+		$UID = 0;
+		$GID = 0;
 	}
-	$GID = $gid;
 
 	$ZIPcollected = $ZIPcollected == 0 ? '' : '-z';
 	$ZIPprofiles  = $ZIPprofiles == 0 ? '' : '-z';
diff -urNad nfsen~/libexec/NfSen.pm nfsen/libexec/NfSen.pm
--- nfsen~/libexec/NfSen.pm	2008-03-07 14:46:23.000000000 +0000
+++ nfsen/libexec/NfSen.pm	2008-03-07 14:46:25.000000000 +0000
@@ -252,9 +252,12 @@
 sub root_process {
 
 	my $run_as   = $<;
-	my ($login,$pass,$root_id,$gid) = getpwnam('root');
-
-	return $run_as == $root_id;
+	if ( !defined($ENV{'INSTALLPREFIX'}) ) {
+		my ($login,$pass,$root_id,$gid) = getpwnam('root');
+		return $run_as == $root_id;
+	} else {
+		return $run_as == 0;
+	}
 
 } # End of root_process
 
diff -urNad nfsen~/install.pl nfsen/install.pl
--- nfsen~/install.pl	2008-03-05 11:03:07.000000000 +0000
+++ nfsen/install.pl	2008-03-05 11:03:09.000000000 +0000
@@ -283,8 +283,8 @@
 sub PatchAllScripts {
 
 	my %GlobList = ( 
-		"bin/*"		=> 	"$NfConf::BINDIR",
-		"libexec/*"	=>	"$NfConf::LIBEXECDIR"
+		"bin/*"		=> 	"$NfConf::INSTPREFIX$NfConf::BINDIR",
+		"libexec/*"	=>	"$NfConf::INSTPREFIX$NfConf::LIBEXECDIR"
 	);
 
 	foreach my $glob_list ( keys %GlobList ) {
@@ -316,8 +316,8 @@
 			foreach my $profile ( @AllProfiles ) {
 				foreach my $type (  'flows', 'packets', 'traffic' ) {
 					foreach my $periode (  'day', 'week', 'month',  'year' ) {
-						my $oldfile = "$NfConf::PROFILESTATDIR/$profilegroup/$profile/${type}-${periode}.gif";
-						my $newfile = "$NfConf::PROFILESTATDIR/$profilegroup/$profile/${type}-${periode}.png";
+						my $oldfile = "$NfConf::INSTPREFIX$NfConf::PROFILESTATDIR/$profilegroup/$profile/${type}-${periode}.gif";
+						my $newfile = "$NfConf::INSTPREFIX$NfConf::PROFILESTATDIR/$profilegroup/$profile/${type}-${periode}.png";
 						if ( -f $oldfile ) {
 							rename $oldfile, $newfile;
 						}
@@ -334,15 +334,15 @@
 	my ( $nfsen_uid, $www_gid ) = @_;
 
 	print "Setup php and html files.\n";
-	mkdir "$NfConf::HTMLDIR" unless -d "$NfConf::HTMLDIR";
-	die "Could not create HTMl directory '$NfConf::HTMLDIR': $!\n"  unless -d $NfConf::HTMLDIR;
+	mkdir "$NfConf::INSTPREFIX$NfConf::HTMLDIR" unless -d "$NfConf::INSTPREFIX$NfConf::HTMLDIR";
+	die "Could not create HTMl directory '$NfConf::INSTPREFIX$NfConf::HTMLDIR': $!\n"  unless -d "$NfConf::INSTPREFIX$NfConf::HTMLDIR";
 
 	$CopyRecursive::CopyLink = 1;
 	$CopyRecursive::MODE 	 = 0644;
 	$CopyRecursive::UID 	 = 0;
 	$CopyRecursive::GID 	 = $www_gid;
-	CopyRecursive::dircopy("html", "$NfConf::HTMLDIR");
-	open CONF, ">$NfConf::HTMLDIR/conf.php" || die "Can't open conf.php for writing: $!\n";
+	CopyRecursive::dircopy("html", "$NfConf::INSTPREFIX$NfConf::HTMLDIR");
+	open CONF, ">$NfConf::INSTPREFIX$NfConf::HTMLDIR/conf.php" || die "Can't open conf.php for writing: $!\n";
 	print CONF "<?\n";
 	print CONF "/* This file was automatically created by the NfSen install.pl script */\n\n";
 	print CONF "\$COMMSOCKET = \"$NfConf::COMMSOCKET\";\n";
@@ -362,15 +362,15 @@
 	umask 0002;
 	print "\nSetup diretories:\n";
 	my @dirs = (
-		"$NfConf::VARDIR",
-		"$NfConf::PIDDIR",
-		"$NfConf::VARDIR/tmp",
-		"$NfConf::VARDIR/filters",
-		"$NfConf::VARDIR/fmt",
-		"$NfConf::PROFILESTATDIR",
-		"$NfConf::PROFILESTATDIR/live",
-		"$NfConf::PROFILEDATADIR",
-		"$NfConf::PROFILEDATADIR/live",
+		"$NfConf::INSTPREFIX$NfConf::VARDIR",
+		"$NfConf::INSTPREFIX$NfConf::PIDDIR",
+		"$NfConf::INSTPREFIX$NfConf::VARDIR/tmp",
+		"$NfConf::INSTPREFIX$NfConf::VARDIR/filters",
+		"$NfConf::INSTPREFIX$NfConf::VARDIR/fmt",
+		"$NfConf::INSTPREFIX$NfConf::PROFILESTATDIR",
+		"$NfConf::INSTPREFIX$NfConf::PROFILESTATDIR/live",
+		"$NfConf::INSTPREFIX$NfConf::PROFILEDATADIR",
+		"$NfConf::INSTPREFIX$NfConf::PROFILEDATADIR/live",
 	);
 
 	print "\nUse UID/GID $nfsen_uid $www_gid\n";
@@ -586,13 +586,13 @@
 	$CopyRecursive::GID 	 = $www_gid;
 	$CopyRecursive::MODE 	 = 0755;
 	unlink "$NfConf::BINDIR/nfsen.rc";
-	CopyRecursive::dircopy("bin", "$NfConf::BINDIR");
-	CopyRecursive::dircopy("libexec", "$NfConf::LIBEXECDIR");
+	CopyRecursive::dircopy("bin", "$NfConf::INSTPREFIX$NfConf::BINDIR");
+	CopyRecursive::dircopy("libexec", "$NfConf::INSTPREFIX$NfConf::LIBEXECDIR");
 	$CopyRecursive::MODE 	 = 0644;
-	CopyRecursive::dircopy("etc", "$NfConf::CONFDIR");
-	CopyRecursive::dircopy("plugins/backend",  "$NfConf::BACKEND_PLUGINDIR");
-	CopyRecursive::dircopy("plugins/frontend", "$NfConf::FRONTEND_PLUGINDIR");
-	CopyRecursive::dircopy("doc", "$NfConf::DOCDIR");
+	CopyRecursive::dircopy("etc", "$NfConf::INSTPREFIX$NfConf::CONFDIR");
+	CopyRecursive::dircopy("plugins/backend",  "$NfConf::INSTPREFIX$NfConf::BACKEND_PLUGINDIR");
+	CopyRecursive::dircopy("plugins/frontend", "$NfConf::INSTPREFIX$NfConf::FRONTEND_PLUGINDIR");
+	CopyRecursive::dircopy("doc", "$NfConf::INSTPREFIX$NfConf::DOCDIR");
 
 	if ( $ConfigFile eq "$NfConf::CONFDIR/nfsen.conf" ) {
 		print "Keep config file '$ConfigFile'\n";
@@ -703,7 +703,7 @@
 # Get Perl
 # Put this into a NfCOnf Variablee, so we can use the standard Patch Procedure
 $NfConf::PERL = GetPerl();
-
+$NfConf::INSTPREFIX = $ENV{'INSTPREFIX'};
 
 my ($nfsen_uid, $www_gid ) = VerifyConfig();
 my $nfsen_run = 0;
@@ -785,7 +785,7 @@
 $$$hints{'version'} 		= $nfsen_version;
 $$$hints{'installed'} 		= time();
 NfSen::StoreHints();
-chown $nfsen_uid, $www_gid, "$NfConf::PROFILESTATDIR/hints" || die "Can't chown hints db: $!\n";
+chown $nfsen_uid, $www_gid, "$NfConf::INSTPREFIX$NfConf::PROFILESTATDIR/hints" || die "Can't chown hints db: $!\n";
 print "Setup done.\n\n";
 
 if ( $nfsen_run ) {
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Nfsen-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nfsen-discuss

Reply via email to