From 249a689b1c8c26efa0288fb4d3cf007a58b03e2c Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Thu, 21 Feb 2013 10:28:23 -0500
Subject: [PATCH] Ticket 528 - RFE - get rid of instance specific scripts (part 2)

Bug Description:  There was a lot of rundant code in the scripts, and
                  hardcoded paths.

Fix Description:  Create new functions in DSUtil.pm(for perl scripts), and
                  create a new shared lib file for the shell scripts.  Redundant
                  code was turned into functions and placed in these files.  Also
                  replaced hardcoded paths with the proper macro values.

https://fedorahosted.org/389/ticket/528

Reviewed by: ?
---
 Makefile.am                                        |    3 +-
 Makefile.in                                        |    3 +-
 ldap/admin/src/scripts/DSSharedLib.in              |   68 +++++++++++
 ldap/admin/src/scripts/DSUtil.pm.in                |   90 +++++++++++++--
 ldap/admin/src/scripts/bak2db.in                   |   88 ++++-----------
 ldap/admin/src/scripts/bak2db.pl.in                |   66 +----------
 ldap/admin/src/scripts/cleanallruv.pl.in           |   65 +----------
 ldap/admin/src/scripts/db2bak.in                   |   93 ++++------------
 ldap/admin/src/scripts/db2bak.pl.in                |   69 +----------
 ldap/admin/src/scripts/db2index.in                 |   96 ++++------------
 ldap/admin/src/scripts/db2index.pl.in              |   67 +----------
 ldap/admin/src/scripts/db2ldif.in                  |  121 +++++---------------
 ldap/admin/src/scripts/db2ldif.pl.in               |   68 +----------
 ldap/admin/src/scripts/dbverify.in                 |  104 ++++-------------
 ldap/admin/src/scripts/dn2rdn.in                   |   88 ++++-----------
 ldap/admin/src/scripts/fixup-linkedattrs.pl.in     |   68 +----------
 ldap/admin/src/scripts/fixup-memberof.pl.in        |   67 +----------
 ldap/admin/src/scripts/ldif2db.in                  |   82 +++-----------
 ldap/admin/src/scripts/ldif2db.pl.in               |   67 +----------
 ldap/admin/src/scripts/ldif2ldap.in                |   87 +++-----------
 ldap/admin/src/scripts/monitor.in                  |   83 +++-----------
 ldap/admin/src/scripts/ns-accountstatus.pl.in      |   67 +----------
 ldap/admin/src/scripts/ns-activate.pl.in           |   66 +----------
 ldap/admin/src/scripts/ns-inactivate.pl.in         |   67 +----------
 ldap/admin/src/scripts/ns-newpwpolicy.pl.in        |   44 +-------
 ldap/admin/src/scripts/restart-slapd.in            |   72 +++---------
 ldap/admin/src/scripts/restoreconfig.in            |   94 ++++------------
 ldap/admin/src/scripts/saveconfig.in               |   91 ++++------------
 ldap/admin/src/scripts/schema-reload.pl.in         |   67 +----------
 ldap/admin/src/scripts/start-slapd.in              |   66 +++--------
 ldap/admin/src/scripts/stop-slapd.in               |   65 +++--------
 ldap/admin/src/scripts/suffix2instance.in          |   88 +++-----------
 ldap/admin/src/scripts/syntax-validate.pl.in       |   67 +----------
 ldap/admin/src/scripts/upgradedb.in                |   77 ++-----------
 ldap/admin/src/scripts/upgradednformat.in          |   98 ++++-------------
 ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in |   66 +----------
 ldap/admin/src/scripts/verify-db.pl.in             |   39 +------
 ldap/admin/src/scripts/vlvindex.in                 |   92 ++++------------
 38 files changed, 596 insertions(+), 2173 deletions(-)
 create mode 100644 ldap/admin/src/scripts/DSSharedLib.in

diff --git a/Makefile.am b/Makefile.am
index 06a4692..9f52f0b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -117,7 +117,7 @@ CLEANFILES =  dberrstrs.h ns-slapd.properties \
 	ldap/ldif/template-ldapi-autobind.ldif ldap/ldif/template-ldapi-default.ldif \
 	ldap/ldif/template-ldapi.ldif ldap/ldif/template-locality.ldif ldap/ldif/template-org.ldif \
 	ldap/ldif/template-orgunit.ldif ldap/ldif/template-pampta.ldif ldap/ldif/template-sasl.ldif \
-	ldap/ldif/template-state.ldif ldap/ldif/template-suffix-db.ldif \
+	ldap/ldif/template-state.ldif ldap/ldif/template-suffix-db.ldif ldap/admin/src/scripts/DSSharedLib \
 	ldap/admin/src/scripts/bak2db ldap/admin/src/scripts/db2bak ldap/admin/src/scripts/upgradedb \
 	ldap/admin/src/scripts/db2index ldap/admin/src/scripts/db2ldif \
 	ldap/admin/src/scripts/dn2rdn ldap/admin/src/scripts/ldif2db \
@@ -370,6 +370,7 @@ sbin_SCRIPTS = ldap/admin/src/scripts/setup-ds.pl \
 	ldap/admin/src/scripts/verify-db.pl \
 	ldap/admin/src/scripts/dbverify \
 	ldap/admin/src/scripts/upgradedb \
+	ldap/admin/src/scripts/DSSharedLib \
     wrappers/ldap-agent
 
 bin_SCRIPTS = ldap/servers/slapd/tools/rsearch/scripts/dbgen.pl \
diff --git a/Makefile.in b/Makefile.in
index 3cce460..ba85e57 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1407,7 +1407,7 @@ CLEANFILES = dberrstrs.h ns-slapd.properties \
 	ldap/ldif/template-ldapi-autobind.ldif ldap/ldif/template-ldapi-default.ldif \
 	ldap/ldif/template-ldapi.ldif ldap/ldif/template-locality.ldif ldap/ldif/template-org.ldif \
 	ldap/ldif/template-orgunit.ldif ldap/ldif/template-pampta.ldif ldap/ldif/template-sasl.ldif \
-	ldap/ldif/template-state.ldif ldap/ldif/template-suffix-db.ldif \
+	ldap/ldif/template-state.ldif ldap/ldif/template-suffix-db.ldif ldap/admin/src/scripts/DSSharedLib \
 	ldap/admin/src/scripts/bak2db ldap/admin/src/scripts/db2bak ldap/admin/src/scripts/upgradedb \
 	ldap/admin/src/scripts/db2index ldap/admin/src/scripts/db2ldif \
 	ldap/admin/src/scripts/dn2rdn ldap/admin/src/scripts/ldif2db \
@@ -1598,6 +1598,7 @@ sbin_SCRIPTS = ldap/admin/src/scripts/setup-ds.pl \
 	ldap/admin/src/scripts/verify-db.pl \
 	ldap/admin/src/scripts/dbverify \
 	ldap/admin/src/scripts/upgradedb \
+	ldap/admin/src/scripts/DSSharedLib \
     wrappers/ldap-agent
 
 bin_SCRIPTS = ldap/servers/slapd/tools/rsearch/scripts/dbgen.pl \
diff --git a/ldap/admin/src/scripts/DSSharedLib.in b/ldap/admin/src/scripts/DSSharedLib.in
new file mode 100644
index 0000000..7b1b35d
--- /dev/null
+++ b/ldap/admin/src/scripts/DSSharedLib.in
@@ -0,0 +1,68 @@
+libpath_add()
+{
+    [ -z "$1" ] && return
+    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
+}
+
+#
+#  get_server_id()
+#
+#  First grab all the server instances
+#  Then check if a server id was provided, if not, set
+#  the server id if there is only one instance. 
+#  If a servid was provided, make sure its a valid instance name.
+#
+get_server_id()
+{
+    dir=$1
+    servid=$2
+    first="yes"
+    inst_count=0
+    rc=0
+    
+    for i in `ls $dir/dirsrv-* 2>/dev/null`
+    do
+        if [ $i != '$dir/dirsrv-admin' ]
+        then
+            inst_count=`expr $inst_count + 1`
+            id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
+            if  [ $first == "yes" ]
+            then
+                instances=$id
+                first="no"
+            else
+                instances=$instances", $id"
+            fi
+            name=$id
+        fi
+    done
+    
+    if [ -z $servid ]
+    then
+        # server id not provided, check if there is only one instance
+        if [ $inst_count -eq 1 ]
+        then
+            servid=$name
+        else 
+            # multiple instances, can not set server id.  Return list of instances
+            servid=$instances
+            rc=1
+        fi
+    elif [ $servid == slapd-* ]
+    then
+        servid=`echo "$servid" | sed -e 's/slapd-//'`
+    elif [ $servid == dirsrv-* ]
+    then
+        servid=`echo "$servid" | sed -e 's/dirsrv-//'`
+    fi
+    
+    if ! [ -a $dir/dirsrv-$servid ]
+    then
+        # invalid instance name, return the "valid" instance names
+        servid=$instances
+        rc=1
+    fi
+
+    echo $servid
+    exit $rc
+}
diff --git a/ldap/admin/src/scripts/DSUtil.pm.in b/ldap/admin/src/scripts/DSUtil.pm.in
index b6b9b86..8f368c2 100644
--- a/ldap/admin/src/scripts/DSUtil.pm.in
+++ b/ldap/admin/src/scripts/DSUtil.pm.in
@@ -1212,20 +1212,13 @@ sub get_prefix {
 # Grab the host, port, and rootDN from the config file of the server instance
 # if the values are missing
 sub get_missing_info {
-    my $prefix = shift;
+    my $dir = shift;
     my $servID = shift;
-    my $instances = shift;
     my $host = shift;
     my $port = shift; 
     my $rootdn = shift;
     
-    unless ( -e "$prefix/etc/dirsrv/slapd-$servID/dse.ldif" ){
-        print (STDERR "Invalid server identifer: $servID\n");
-        print (STDERR "Available instances: $instances\n");
-        exit (1);
-    }
-    
-    open (DSE, "<$prefix/etc/dirsrv/slapd-$servID/dse.ldif") || die "Failed to open config file $prefix/etc/dirsrv/slapd-$servID/dse.ldif $!\n";
+    open (DSE, "<$dir/slapd-$servID/dse.ldif") || die "Failed to open config file $dir/slapd-$servID/dse.ldif $!\n";
         while(<DSE>){
         if ($host eq "" && $_ =~ /^nsslapd-localhost: (.*)/){
                 $host = $1;
@@ -1241,6 +1234,85 @@ sub get_missing_info {
     return $host, $port, $rootdn;
 }
 
+sub get_server_id {
+    my $servid = shift;
+    my $dir = shift;
+    my $first = "yes";
+    my $instance_count = 0;
+    my $instances = "";
+    my $name = "";
+    my $file;
+    
+    opendir(DIR, "$dir");
+    my @files = readdir(DIR);
+    foreach $file (@files){
+        if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
+            $instance_count++;
+            if($file =~ /dirsrv-(.*)/){
+                if($first eq "yes"){
+                    $instances=$1;
+                    $first = "no";
+                } else {
+                    $instances=$instances . ", $1";
+                }
+                $name = $1;
+            }
+        }
+    }
+    if($servid eq ""){
+        if ($instance_count == 1){
+            $servid = $name;
+        } else {
+            print "You must supply a valid server instance identifier.  Use -Z to specify instance name\n";
+            print "Available instances: $instances\n";
+            exit (1);
+        }
+    } elsif ($servid =~ /^dirsrv-/){
+        # strip off "dirsrv-"
+        $servid =~ s/^dirsrv-//;
+    } elsif ($servid =~ /^slapd-/){
+        # strip off "slapd-"
+        $servid =~ s/^slapd-//;
+    }
+    
+    unless ( -e "$dir/dirsrv-$servid" ){
+        print (STDERR "instance dir: $dir/dirsrv-$servid\n");
+        print (STDERR "Invalid server identifer: $servid\n");
+        print (STDERR "Available instances: $instances\n");
+        exit (1);
+    }
+    
+    return $servid;
+}
+
+sub get_password_from_file {
+    my $passwd = shift;
+    my $passwdfile = shift;
+    
+    if ($passwdfile ne ""){
+        # Open file and get the password
+        unless (open (RPASS, $passwdfile)) {
+            die "Error, cannot open password file $passwdfile\n";
+        }
+        $passwd = <RPASS>;
+        chomp($passwd);
+        close(RPASS);
+    } elsif ($passwd eq "-"){
+        # Read the password from terminal
+        print "Bind Password: ";
+        # Disable console echo
+        system("@sttyexec@ -echo") if -t STDIN;
+        # read the answer
+        $passwd = <STDIN>;
+        # Enable console echo
+        system("@sttyexec@ echo") if -t STDIN;
+        print "\n";
+        chop($passwd); # trim trailing newline
+    }
+    
+    return $passwd;
+}
+
 1;
 
 # emacs settings
diff --git a/ldap/admin/src/scripts/bak2db.in b/ldap/admin/src/scripts/bak2db.in
index 0fe5240..56e038f 100755
--- a/ldap/admin/src/scripts/bak2db.in
+++ b/ldap/admin/src/scripts/bak2db.in
@@ -1,23 +1,8 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
 libpath_add "@pcre_libdir@"
@@ -26,25 +11,28 @@ export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
+usage()
+{
+    echo "Usage: bak2db archivedir [-Z serverID] [-n backendname] [-q] | [-h]"
+}
+
 if [ $# -lt 1 ] || [ $# -gt 7 ]
 then
-    echo "Usage: bak2db archivedir [-Z serverID] [-n backendname] [-q] | [-h]"
+    usage
     exit 1
 elif [ "$1" == "-*" ]
 then
-    echo "Usage: bak2db archivedir [-Z serverID] [-n backendname] [-q] | [-h]"
+    usage
     exit 1
 else
     archivedir=$1
     shift
 fi
-
-first="yes"
-args=""      
+    
 while getopts "hn:Z:qd:vi:a:SD:" flag
 do
     case $flag in
-        h) echo "Usage: bak2db archivedir [-Z serverID] [-n backendname] [-q] | [-h]"
+        h) usage
            exit 0;;
         Z) servid=$OPTARG;; 
         n) args=$args" -n $OPTARG";;
@@ -55,57 +43,22 @@ do
         i) args=$args" -i $OPTARG";;
         a) archivedir=$OPTARG;;
         S) args=$args" -S";;
-        ?) echo "Usage: bak2db archivedir [-Z serverID] [-n backendname] [-q] | [-h]"
+        ?) usage
            exit 1;;
     esac
 done
 
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done
-
-if [ -z $servid ]
-then
-    # server id not provided, check if there is only one instance
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: bak2db archivedir [-Z serverID] [-n backendname] [-q] | [-h]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ 1 = `expr $archivedir : "\/"` ]
 then
     archivedir=$archivedir
@@ -114,5 +67,4 @@ else
     archivedir=`pwd`/$archivedir
 fi
 
-cd $server_sbin
-./ns-slapd archive2db -D $configdir -a $archivedir $args
+@sbindir@/ns-slapd archive2db -D $configdir -a $archivedir $args
diff --git a/ldap/admin/src/scripts/bak2db.pl.in b/ldap/admin/src/scripts/bak2db.pl.in
index 0352ed1..a6cb72d 100644
--- a/ldap/admin/src/scripts/bak2db.pl.in
+++ b/ldap/admin/src/scripts/bak2db.pl.in
@@ -67,7 +67,6 @@ $passwdfile = "";
 $host = "";
 $port = "";
 $i = 0;
-$prefix = DSUtil::get_prefix();
 
 while ($i <= $#ARGV) {
 	if ("$ARGV[$i]" eq "-a") {	# backup directory
@@ -99,62 +98,10 @@ if ($archivedir eq ""){
     exit(1);
 }
 
-$first = "yes";
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
-if ($passwdfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $passwdfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$passwd = <RPASS>;
-	chomp($passwd);
-	close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
 if ( $rootdn eq "" || $passwd eq "") { &usage; exit(1); }
 ($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
 $mn++; $yr += 1900;
@@ -168,7 +115,7 @@ if (!$isabs) {
     $archivedir = File::Spec->rel2abs( $archivedir );
 }
 $dn = "dn: cn=$taskname, cn=restore, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn = "cn: $taskname\n";
 if ($instance ne "") {
 	$nsinstance = "nsInstance: ${instance}\n";
@@ -178,12 +125,11 @@ $nsdbtype = "nsDatabaseType: $dbtype\n";
 $entry = "${dn}${misc}${cn}${nsinstance}${nsarchivedir}${nsdbtype}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h $info[0] -p $info[1] -D $info[2] -w \"$passwd\" -a" );
diff --git a/ldap/admin/src/scripts/cleanallruv.pl.in b/ldap/admin/src/scripts/cleanallruv.pl.in
index 7cdfb2d..267305d 100644
--- a/ldap/admin/src/scripts/cleanallruv.pl.in
+++ b/ldap/admin/src/scripts/cleanallruv.pl.in
@@ -64,15 +64,12 @@ $abort = "";
 $verbose = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
@@ -131,61 +128,9 @@ while ($i <= $#ARGV)
     $i++;
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-    print "Bind Password: ";
-    # Disable console echo
-    system("@sttyexec@ -echo") if -t STDIN;
-    # read the answer
-    $passwd = <STDIN>;
-    # Enable console echo
-    system("@sttyexec@ echo") if -t STDIN;
-    print "\n";
-    chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" || $basedn eq "" || $rid eq "") 
 { 
diff --git a/ldap/admin/src/scripts/db2bak.in b/ldap/admin/src/scripts/db2bak.in
index 8e53722..b4dd456 100755
--- a/ldap/admin/src/scripts/db2bak.in
+++ b/ldap/admin/src/scripts/db2bak.in
@@ -1,41 +1,27 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
+libpath_add "@libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
+usage()
+{
+    echo "Usage: db2bak [archivedir] [-Z serverID] [-q] [-h]"
+}
+
 if [ $# -gt 4 ]
 then
-    echo "Usage: db2bak [archivedir] [-Z serverID] [-q] [-h]"
+    usage
     exit 1
 fi
 
-first="yes"
-bak_dir=""
-args=""
-cd $server_sbin
 if [ "$#" -gt 0 ]
 then
   if ["$1" != "-*" ] 
@@ -47,7 +33,7 @@ then
   while getopts "hqd:Z:vi:a:SD" flag
   do
     case $flag in
-        h) echo "Usage: db2bak [archivedir] [-Z serverID] [-q] [-h]"
+        h) usage
            exit 0;;
         q) args=$args" -g";;
         v) args=$args" -v";;
@@ -57,62 +43,27 @@ then
         a) $bakdir=$OPTARG;;
         d) args=$args" -d $OPTARG";;
         Z) servid=$OPTARG;;
-        ?) echo "Usage: db2bak [archivedir] [-Z serverID] [-q] [-h]"
+        ?) usage
            exit 1;;
     esac
   done
 fi
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: db2bak [archivedir] [-Z serverID] [-q] [-h]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ -z $bak_dir ]
 then
-    bak_dir=$prefix/var/lib/dirsrv/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H_%M_%S`
+    bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H_%M_%S`
 fi
 
 echo "Back up directory: $bak_dir"
-./ns-slapd db2archive -D $configdir -a $bak_dir $args
+@sbindir@/ns-slapd db2archive -D $configdir -a $bak_dir $args
diff --git a/ldap/admin/src/scripts/db2bak.pl.in b/ldap/admin/src/scripts/db2bak.pl.in
index f45a834..d406a2c 100644
--- a/ldap/admin/src/scripts/db2bak.pl.in
+++ b/ldap/admin/src/scripts/db2bak.pl.in
@@ -64,8 +64,6 @@ $passwdfile = "";
 $i = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
 while ($i <= $#ARGV) {
 	if ("$ARGV[$i]" eq "-a") {	# backup directory
@@ -90,63 +88,11 @@ while ($i <= $#ARGV) {
 	$i++;
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$mybakdir = "@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak";
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
-$mybakdir = "$prefix/var/lib/dirsrv/slapd-$servid/bak";
-
-if ($passwdfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $passwdfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$passwd = <RPASS>;
-	chomp($passwd);
-	close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
 if ( $info[2] eq "" || $passwd eq "") { &usage; exit(1); }
 ($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
 $mn++; $yr += 1900;
@@ -155,19 +101,18 @@ if ($archivedir eq "") {
 	$archivedir = "${mybakdir}/$servid-${yr}_${mn}_${dy}_${h}_${m}_${s}";
 }
 $dn = "dn: cn=$taskname, cn=backup, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn = "cn: $taskname\n";
 $nsarchivedir = "nsArchiveDir: $archivedir\n";
 $nsdbtype = "nsDatabaseType: $dbtype\n";
 $entry = "${dn}${misc}${cn}${nsarchivedir}${nsdbtype}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 print("Back up directory: $archivedir host: $info[0] port: $info[1] binddn: $info[2]\n");
diff --git a/ldap/admin/src/scripts/db2index.in b/ldap/admin/src/scripts/db2index.in
index f735cfc..501f637 100755
--- a/ldap/admin/src/scripts/db2index.in
+++ b/ldap/admin/src/scripts/db2index.in
@@ -1,37 +1,25 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
+libpath_add "@libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
-first="yes"
-args=""
+usage ()
+{
+    echo "Usage: db2index [-Z serverID] [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]"
+}
+
 while getopts "hZ:n:s:t:T:vd:a:SD:x:" flag
 do
     case $flag in
-        h) echo "Usage: db2index [-Z serverID] [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]"
+        h) usage
            exit 0;;
         Z) servid=$OPTARG;; 
         n) args=$args" -n $OPTARG"
@@ -46,72 +34,36 @@ do
         v) args=$args=" -v";;
         S) args=$args=" -S";;
         D) args=$args" -D $OPTARG";;
-        ?) echo "Usage: db2index [-Z serverID] [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]"
+        ?) usage
            exit 1;;
     esac
 done
 
 if [ -z $benameopt ] && [ -z $includeSuffix ]
 then
-    echo "Usage: db2index [-Z serverID] [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]"
+    usage
     exit 1;
 fi
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: db2index [-Z serverID] [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ $# -eq 0 ]
 then
-	bak_dir=$prefix/var/lib/dirsrv/slapd-$servid/bak/reindex_`date +%Y_%m_%d_%H_%M_%S`
-	./ns-slapd upgradedb -D $configdir -a "$bak_dir"
+	bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/reindex_`date +%Y_%m_%d_%H_%M_%S`
+	@sbindir@/ns-slapd upgradedb -D $configdir -a "$bak_dir"
 elif [ $# -lt 2 ]
 then
-	echo "Usage: db2index [-Z instance-name] [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]"
+	usage
 	exit 1
 else
-	./ns-slapd db2index -D $configdir $args
+	@sbindir@/ns-slapd db2index -D $configdir $args
 fi
diff --git a/ldap/admin/src/scripts/db2index.pl.in b/ldap/admin/src/scripts/db2index.pl.in
index a9acce5..956e975 100644
--- a/ldap/admin/src/scripts/db2index.pl.in
+++ b/ldap/admin/src/scripts/db2index.pl.in
@@ -73,14 +73,12 @@ $vlvattribute_arg = "";
 $verbose = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
@@ -109,62 +107,11 @@ $attribute_arg = $opt_t;
 $vlvattribute_arg = $opt_T;
 $verbose = $opt_v;
 $servid = $opt_Z;
+$passwdfile = $opt_j;
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-    print "Bind Password: ";
-    # Disable console echo
-    system("@sttyexec@ -echo") if -t STDIN;
-    # read the answer
-    $passwd = <STDIN>;
-    # Enable console echo
-    system("@sttyexec@ echo") if -t STDIN;
-    print "\n";
-    chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" ) 
 { 
@@ -242,7 +189,7 @@ else
 # Build the task entry to add
 
 $dn = "dn: cn=$taskname, cn=index, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn =  "cn: $taskname\n";
 $nsinstance = "nsInstance: ${instance}\n";
 
diff --git a/ldap/admin/src/scripts/db2ldif.in b/ldap/admin/src/scripts/db2ldif.in
index 8df3e51..f17e7a8 100755
--- a/ldap/admin/src/scripts/db2ldif.in
+++ b/ldap/admin/src/scripts/db2ldif.in
@@ -1,31 +1,24 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
+libpath_add "@libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
+usage()
+{
+    echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}*"
+    echo "               [{-x excludesuffix}*] [-a outputfile]"
+    echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1] [-q]"
+    echo "Note: either \"-n backend_instance\" or \"-s includesuffix\" is required."
+}
+
 make_ldiffile()
 {
     be=""
@@ -64,33 +57,24 @@ make_ldiffile()
     done
 
     if [ "$be" = "" ]; then
-        echo $prefix/var/lib/dirsrv/slapd-$servid/ldif/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
+        echo @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
     else
-        echo $prefix/var/lib/dirsrv/slapd-$servid/ldif/$servid-${be}-`date +%Y_%m_%d_%H%M%S`.ldif
+        echo @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif/$servid-${be}-`date +%Y_%m_%d_%H%M%S`.ldif
     fi
     return 0
 }
 
-cd $server_sbin
 if [ "$#" -lt 2 ];
 then
-    echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}*"
-    echo "               [{-x excludesuffix}*] [-a outputfile]"
-    echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1] [-q]"
-    echo "Note: either \"-n backend_instance\" or \"-s includesuffix\" is required."
+    usage
     exit 1
 fi
-         
-first="yes"
-args=""      
+    
 while getopts "hZ:n:s:x:a:NrCuUmM1qvd:D:ESt:o" flag
 do
     case $flag in
-        h) echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}*"
-            echo "               [{-x excludesuffix}*] [-a outputfile]"
-            echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1] [-q]"
-            echo "Note: either \"-n backend_instance\" or \"-s includesuffix\" is required."
-            exit 0;;
+        h) usage
+           exit 0;;
         Z) servid=$OPTARG;; 
         n) benameopt="-n $OPTARG"
            required_param="yes";;
@@ -113,78 +97,35 @@ do
         M) args=$args" -M";;
         1) args=$args" -1";;
         q) args=$args" -q";;        
-        ?) echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}*"
-            echo "               [{-x excludesuffix}*] [-a outputfile]"
-            echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1] [-q]"
-            echo "Note: either \"-n backend_instance\" or \"-s includesuffix\" is required."
-            exit 1;;
+        ?) usage
+           exit 1;;
     esac
 done
 
 if [ "$required_param" != "yes" ]
 then
-    echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}*"
-    echo "               [{-x excludesuffix}*] [-a outputfile]"
-    echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1] [-q]"
-    echo "Note: either \"-n backend_instance\" or \"-s includesuffix\" is required."
+    usage
     exit 1
 fi
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}*"
-        echo "               [{-x excludesuffix}*] [-a outputfile]"
-        echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1] [-q]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
+configdir="@instconfigdir@/slapd-$servid"
+
 ldif_file=`make_ldiffile $@`
 rn=$?
 
 echo "Exported ldif file: $ldif_file"
 if [ $rn -eq 1 ]
 then
-./ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix $outputFile $args
+    @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix $outputFile $args
 else
-./ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix -a $ldif_file $args
+    @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix -a $ldif_file $args
 fi
diff --git a/ldap/admin/src/scripts/db2ldif.pl.in b/ldap/admin/src/scripts/db2ldif.pl.in
index 5b7e75c..14054d9 100644
--- a/ldap/admin/src/scripts/db2ldif.pl.in
+++ b/ldap/admin/src/scripts/db2ldif.pl.in
@@ -94,7 +94,6 @@ sub usage {
 	""
 );
 
-$prefix = DSUtil::get_prefix();
 $maxidx = 50;
 $nowrap = 0;
 $nobase64 = 0;
@@ -117,7 +116,6 @@ $excli = 0;
 $decrypt_on_export = 0;
 $host = "";
 $port = "";
-$first = "yes";
 
 while ($i <= $#ARGV) {
 	if ( "$ARGV[$i]" eq "-n" ) {	# instances
@@ -181,68 +179,17 @@ while ($i <= $#ARGV) {
 	$i++;
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-$ldifdir = "$prefix/var/lib/dirsrv/slapd-$servid/ldif";
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$ldifdir = "@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif";
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
-if ($passwdfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $passwdfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$passwd = <RPASS>;
-	chomp($passwd);
-	close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
 if (($instances[0] eq "" && $included[0] eq "") || $info[2] eq "" || $passwd eq "") { &usage; exit(1); }
 ($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
 $mn++; $yr += 1900;
 $taskname = "export_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 $dn = "dn: cn=$taskname, cn=export, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn =  "cn: $taskname\n";
 $i = 0;
 $be = "";
@@ -305,12 +252,11 @@ $nsldiffile = "nsFilename: ${ldiffile}\n";
 $entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsreplica}${nsnobase64}${nsnowrap}${nsnoversion}${nsnouniqueid}${nsuseid2entry}${nsonefile}${nsexportdecrypt}${nsprintkey}${nsldiffile}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 print("Exporting to ldif file: ${ldiffile}\n");
diff --git a/ldap/admin/src/scripts/dbverify.in b/ldap/admin/src/scripts/dbverify.in
index fb16086..169e591 100755
--- a/ldap/admin/src/scripts/dbverify.in
+++ b/ldap/admin/src/scripts/dbverify.in
@@ -1,42 +1,30 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-PATH=$PATH:/bin
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
+libpath_add "@libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
+PATH=$PATH:/bin
+
+usage()
+{
+    echo "Usage: dbverify [-Z serverID] [-n backend_instance] [-V]"
+    echo "Note : if \"-n backend_instance\" is not passed, verify all DBs."
+    echo "  -Z : Server instance identifier"
+    echo "  -V : verbose"
+}
 
-first="yes"
-args=""
 while getopts "Z:n:hVfd:n:D:" flag
 do
     case $flag in
-        h)  echo "Usage: dbverify [-Z serverID] [-n backend_instance] [-V]"
-            echo "Note : if \"-n backend_instance\" is not passed, verify all DBs."
-            echo "  -Z : Server instance identifier"
-            echo "  -V : verbose"
-            exit 0;;
+        h) usage
+           exit 0;;
         Z) servid=$OPTARG;;
         n) args=$args" -n $OPTARG";;
         d) args=$args" -d $OPTARG";;
@@ -44,65 +32,23 @@ do
         v) args=$args" -v";;
         f) args=$args" -f";;
         D) args=$args" -D $OPTARG";;
-        ?) echo "Usage: dbverify [-Z serverID] [-n backend_instance] [-V]"
-           echo "Note : if \"-n backend_instance\" is not passed, verify all DBs."
-           echo "  -Z : Server instance identifier"
-           echo "  -V : verbose"
+        ?) usage
            exit 1;;
     esac
 done
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: dbverify [-Z serverID] [-n backend_instance] [-V]"
-        echo "Note : if \"-n backend_instance\" is not passed, verify all DBs."
-        echo "  -Z : Server instance identifier"
-        echo "  -V : verbose"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
-./ns-slapd dbverify -D $configdir $args
+configdir="@instconfigdir@/slapd-$servid"
+
+@sbindir@/ns-slapd dbverify -D $configdir $args
 if [ $? -eq 0 ]; then
     echo "DB verify: Passed"
     exit 0
diff --git a/ldap/admin/src/scripts/dn2rdn.in b/ldap/admin/src/scripts/dn2rdn.in
index bf078ef..9e1a102 100755
--- a/ldap/admin/src/scripts/dn2rdn.in
+++ b/ldap/admin/src/scripts/dn2rdn.in
@@ -1,36 +1,24 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
+libpath_add "@libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
       
-first="yes"
-arg=""         
+usage ()
+{
+    echo "Usage: db2rdn [-Z serverID]"
+}
+    
 while getopts "Z:d:ha:vfr:D:" flag
 do
     case $flag in
-        h) echo "Usage: db2rdn [-Z serverID]"
+        h) usage
            exit 0;;
         Z) servid=$OPTARG;;
         d) arg=$arg" -d $OPTARG";;
@@ -39,57 +27,21 @@ do
         f) arg=$arg" -f";;
         r) arg=$arg" -r";;
         D) arg=$arg" -D $OPTARG";;
-        ?) echo "Usage: db2rdn [-Z serverID]"
+        ?) usage
            exit 1;;
     esac
 done
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done
-
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: db2rdn [-Z serverID]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
-bak_dir=$prefix/var/lib/dirsrv/slapd-$servid/bak/reindex_`date +%Y_%m_%d_%H_%M_%S`
-./ns-slapd upgradedb -D $configdir -r -a "$bak_dir" $arg
+configdir="@instconfigdir@/slapd-$servid"
+
+bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/reindex_`date +%Y_%m_%d_%H_%M_%S`
+@sbindir@/ns-slapd upgradedb -D $configdir -r -a "$bak_dir" $arg
diff --git a/ldap/admin/src/scripts/fixup-linkedattrs.pl.in b/ldap/admin/src/scripts/fixup-linkedattrs.pl.in
index 187e588..1499736 100644
--- a/ldap/admin/src/scripts/fixup-linkedattrs.pl.in
+++ b/ldap/admin/src/scripts/fixup-linkedattrs.pl.in
@@ -62,15 +62,12 @@ $linkdn_arg = "";
 $verbose = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
@@ -118,62 +115,9 @@ while ($i <= $#ARGV)
     }
     $i++;
 }
-
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" ) 
 { 
@@ -194,7 +138,7 @@ $taskname = "linked_attrs_fixup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 
 # Build the task entry to add
 $dn = "dn: cn=$taskname, cn=fixup linked attributes, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn =  "cn: $taskname\n";
 if ($linkdn_arg ne "")
 {
diff --git a/ldap/admin/src/scripts/fixup-memberof.pl.in b/ldap/admin/src/scripts/fixup-memberof.pl.in
index 923d2ad..8afa243 100644
--- a/ldap/admin/src/scripts/fixup-memberof.pl.in
+++ b/ldap/admin/src/scripts/fixup-memberof.pl.in
@@ -67,15 +67,12 @@ $filter = "";
 $verbose = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
@@ -129,61 +126,9 @@ while ($i <= $#ARGV)
     $i++;
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }            
-    }
-}
-
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" || $basedn_arg eq "" ) 
 { 
@@ -204,7 +149,7 @@ $taskname = "memberOf_fixup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 
 # Build the task entry to add
 $dn = "dn: cn=$taskname, cn=memberOf task, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn =  "cn: $taskname\n";
 $basedn = "basedn: $basedn_arg\n";
 
diff --git a/ldap/admin/src/scripts/ldif2db.in b/ldap/admin/src/scripts/ldif2db.in
index fdf9230..d62ed66 100755
--- a/ldap/admin/src/scripts/ldif2db.in
+++ b/ldap/admin/src/scripts/ldif2db.in
@@ -1,26 +1,11 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
+libpath_add "@libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
@@ -51,8 +36,6 @@ handleopts()
     return 0
 }
 
-first="yes"
-args=""
 while getopts "Z:vd:i:g:G:n:s:x:NOCc:St:D:Eq" flag
 do
     case $flag in
@@ -81,53 +64,17 @@ do
     esac
 done
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        usage
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ $# -lt 5 ]
 then
     usage
@@ -136,9 +83,10 @@ fi
 
 handleopts $@
 quiet=$?
-
 if [ $quiet -eq 0 ]; then
     echo importing data ...
 fi
-./ns-slapd ldif2db -D $configdir $args 2>&1
+
+@sbindir@/ns-slapd ldif2db -D $configdir $args 2>&1
+
 exit $?
diff --git a/ldap/admin/src/scripts/ldif2db.pl.in b/ldap/admin/src/scripts/ldif2db.pl.in
index 379a264..5aff2bb 100644
--- a/ldap/admin/src/scripts/ldif2db.pl.in
+++ b/ldap/admin/src/scripts/ldif2db.pl.in
@@ -108,8 +108,6 @@ $excli = 0;
 $encrypt_on_import = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
 while ($i <= $#ARGV) {
 	if ( "$ARGV[$i]" eq "-i" ) {	# ldiffiles
@@ -169,68 +167,16 @@ while ($i <= $#ARGV) {
 	}
 	$i++;
 }
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print (STDERR "You must supply a server instance identifier.  Use -Z to specify instance name\n");
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $passwdfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$passwd = <RPASS>;
-	chomp($passwd);
-	close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
 if (($instance eq "" && $included[0] eq "") || $ldiffiles[0] eq "" || $info[2] eq "" || $passwd eq "") { &usage; exit(1); }
 ($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
 $mn++; $yr += 1900;
 $taskname = "import_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 $dn = "dn: cn=$taskname, cn=import, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn =  "cn: $taskname\n";
 if ($instance ne "") {
 	$nsinstance = "nsInstance: ${instance}\n";
@@ -264,12 +210,11 @@ if ($uniqidname ne "") { $nsuniqidname = "nsUniqueIdGeneratorNamespace: ${uniqid
 $entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsldiffiles}${nsnoattrindexes}${nsimportencrypt}${nsmergechunksiz}${nsgenuniqid}${nsuniqidname}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h $info[0] -p $info[1] -D \"$info[2]\" -w \"$passwd\" -a" );
diff --git a/ldap/admin/src/scripts/ldif2ldap.in b/ldap/admin/src/scripts/ldif2ldap.in
index abfb5f4..069470c 100755
--- a/ldap/admin/src/scripts/ldif2ldap.in
+++ b/ldap/admin/src/scripts/ldif2ldap.in
@@ -1,37 +1,22 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
+source ./DSSharedLib
 
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
-
-libpath_add "$prefix@ldapsdk_libdir@"
 libpath_add "@ldapsdk_libdir@"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
-libpath_add "$server_dir"
+libpath_add "@libdir@/dirsrv/"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
+PATH=$PATH:@ldaptool_bindir@:@ldaptool_bindir@
 
-PATH=$PATH:$prefix@ldaptool_bindir@:@ldaptool_bindir@
+usage ()
+{
+    echo "Usage: ldif2ldap [-Z serverID] -D <bind dn> -w <password> -f <file>"
+}
 
-first="yes"
-args=""
 while getopts "Z:D:w:f:h" flag
 do
     case $flag in
@@ -42,65 +27,29 @@ do
            passwd=$OPTARG;;
         f) args=$args" -f $OPTARG"
            input_file=$OPTARG;;
-        h) echo "Usage: ldif2ldap [-Z serverID] -D <bind dn> -w <password> -f <file>"
+        h) usage
            exit 0;;
-        ?) echo "Usage: ldif2ldap [-Z serverID] -D <bind dn> -w <password> -f <file>"
+        ?) usage
            exit 1;;
     esac
 done
 
 if [ "$binddn" == "" ] || [ "$passwd" == "" ] || [ "$input_file" == "" ]
 then 
-    echo "Usage: ldif2ldap -D <bind dn> -w <password> -f <file>"
+    usage
     exit 1
 fi
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: ldif2ldap [-Z serverID] -D <bind dn> -w <password> -f <file>"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-if ! [ -a "$prefix/etc/dirsrv/slapd-$servid/dse.ldif" ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-port=$(grep 'nsslapd-port' $prefix/etc/dirsrv/slapd-$servid/dse.ldif | awk '{print $2}' )
-host=$(grep 'nsslapd-localhost' $prefix/etc/dirsrv/slapd-$servid/dse.ldif | awk '{print $2}' )
+port=$(grep 'nsslapd-port' @instconfigdir@/slapd-$servid/dse.ldif | awk '{print $2}' )
+host=$(grep 'nsslapd-localhost' @instconfigdir@/slapd-$servid/dse.ldif | awk '{print $2}' )
 
 ldapmodify @ldaptool_opts@ -a -p $port -h $host $args
diff --git a/ldap/admin/src/scripts/monitor.in b/ldap/admin/src/scripts/monitor.in
index 6438331..fc3723b 100755
--- a/ldap/admin/src/scripts/monitor.in
+++ b/ldap/admin/src/scripts/monitor.in
@@ -1,94 +1,45 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@ldapsdk_libdir@"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@ldapsdk_libdir@"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
+PATH=$PATH:@ldaptool_bindir@:@ldaptool_bindir@
 
-PATH=$PATH:$prefix@ldaptool_bindir@:@ldaptool_bindir@
+usage ()
+{
+    echo "Usage: monitor [ -Z serverID ] [ -b basedn ]"
+}
 
 while getopts "Z:b:h" flag
 do
     case $flag in
         Z) servid=$OPTARG;;
         b) MDN=$OPTARG;;
-        h) echo "Usage: monitor [ -Z serverID ] [ -b basedn ]"
+        h) usage
            exit 0;;
-        ?) echo "Usage: monitor [ -Z serverID ] [ -b basedn ]"
+        ?) usage
            exit 1;;
     esac
 done
 
-first="yes"
-
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: monitor [ -Z serverID ] [ -b basedn ]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-if ! [ -a "$prefix/etc/dirsrv/slapd-$servid/dse.ldif" ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-port=$(grep 'nsslapd-port' $prefix/etc/dirsrv/slapd-$servid/dse.ldif | awk '{print $2}' )
-host=$(grep 'nsslapd-localhost' $prefix/etc/dirsrv/slapd-$servid/dse.ldif | awk '{print $2}' )
+port=$(grep 'nsslapd-port' @instconfigdir@/slapd-$servid/dse.ldif | awk '{print $2}' )
+host=$(grep 'nsslapd-localhost' @instconfigdir@/slapd-$servid/dse.ldif | awk '{print $2}' )
 
 if [ -z $MDN ]
 then
diff --git a/ldap/admin/src/scripts/ns-accountstatus.pl.in b/ldap/admin/src/scripts/ns-accountstatus.pl.in
index eac9473..ee56914 100644
--- a/ldap/admin/src/scripts/ns-accountstatus.pl.in
+++ b/ldap/admin/src/scripts/ns-accountstatus.pl.in
@@ -42,8 +42,6 @@
 use lib qw(@perlpath@);
 use DSUtil;
 
-$prefix = DSUtil::get_prefix();
-
 ###############################
 # SUB-ROUTINES
 ###############################
@@ -391,9 +389,9 @@ else
 }
 
 debug("Running ** $cmd ** $operation\n");
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
+DSUtil::libpath_add("@nss_libdir@");
+DSUtil::libpath_add("/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
 
@@ -411,7 +409,6 @@ $pwfile = "";
 $entry = "";
 $single = 0;
 $role = 0;
-$first = "yes";
 
 # Process the command line arguments
 while( $arg = shift)
@@ -457,61 +454,9 @@ while( $arg = shift)
 	}
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($pwfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $pwfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$rootpw = <RPASS>;
-	chomp($rootpw);
-	close(RPASS);
-} elsif ($rootpw eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$rootpw = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($rootpw); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$rootpw = DSUtil::get_password_from_file($rootpw, $pwfile);
 
 if( $rootpw eq "" || $entry eq "")
 {
diff --git a/ldap/admin/src/scripts/ns-activate.pl.in b/ldap/admin/src/scripts/ns-activate.pl.in
index 3660aa4..f7254e0 100644
--- a/ldap/admin/src/scripts/ns-activate.pl.in
+++ b/ldap/admin/src/scripts/ns-activate.pl.in
@@ -359,7 +359,6 @@ sub checkScope
 ###############################
 
 # Generated variable
-$prefix = DSUtil::get_prefix();
 
 # Determine which command we are running
 if ( $0 =~ /ns-inactivate(.pl)?$/ )
@@ -395,10 +394,10 @@ else
 
 debug("Running ** $cmd ** $operation\n");
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
+DSUtil::libpath_add("@nss_libdir@");
+DSUtil::libpath_add("/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
 
@@ -414,7 +413,6 @@ $host = "";
 $rootpw = "";
 $pwfile = "";
 $entry = "";
-$first = "yes";
 $single = 0;
 $role = 0;
 
@@ -462,61 +460,9 @@ while( $arg = shift)
 	}
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($pwfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $pwfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$rootpw = <RPASS>;
-	chomp($rootpw);
-	close(RPASS);
-} elsif ($rootpw eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$rootpw = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($rootpw); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$rootpw = DSUtil::get_password_from_file($rootpw, $pwfile);
 
 if( $rootpw eq "" || $entry eq "")
 {
diff --git a/ldap/admin/src/scripts/ns-inactivate.pl.in b/ldap/admin/src/scripts/ns-inactivate.pl.in
index 9aa17e1..cf82eea 100644
--- a/ldap/admin/src/scripts/ns-inactivate.pl.in
+++ b/ldap/admin/src/scripts/ns-inactivate.pl.in
@@ -359,7 +359,6 @@ sub checkScope
 ###############################
 
 # Generated variable
-$prefix = DSUtil::get_prefix();
 
 # Determine which command we are running
 if ( $0 =~ /ns-inactivate(.pl)?$/ )
@@ -395,10 +394,10 @@ else
 
 debug("Running ** $cmd ** $operation\n");
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
+DSUtil::libpath_add("@nss_libdir@");
+DSUtil::libpath_add("/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
 
@@ -414,7 +413,6 @@ $pwfile = "";
 $host = "";
 $port = "";
 $entry = "";
-$first = "yes";
 $single = 0;
 $role = 0;
 
@@ -461,62 +459,9 @@ while( $arg = shift)
 		exit(1);
 	}
 }
-
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($pwfile ne ""){
-# Open file and get the password
-	unless (open (RPASS, $pwfile)) {
-		die "Error, cannot open password file $passwdfile\n";
-	}
-	$rootpw = <RPASS>;
-	chomp($rootpw);
-	close(RPASS);
-} elsif ($rootpw eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$rootpw = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($rootpw); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$rootpw = DSUtil::get_password_from_file($rootpw, $pwfile);
 
 if( $rootpw eq "" || $entry eq "")
 {
diff --git a/ldap/admin/src/scripts/ns-newpwpolicy.pl.in b/ldap/admin/src/scripts/ns-newpwpolicy.pl.in
index 4486ad1..d785147 100755
--- a/ldap/admin/src/scripts/ns-newpwpolicy.pl.in
+++ b/ldap/admin/src/scripts/ns-newpwpolicy.pl.in
@@ -45,13 +45,12 @@ use DSUtil;
 # enable the use of our bundled perldap with our bundled ldapsdk libraries
 # all of this nonsense can be omitted if the mozldapsdk and perldap are
 # installed in the operating system locations (e.g. /usr/lib /usr/lib/perl5)
-$prefix = DSUtil::get_prefix();
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
+
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 # Add new password policy specific entries
@@ -102,41 +101,8 @@ sub usage {
 {
 	usage() if (!getopts('vD:w:j:p:h:U:S:Z:'));
 
-	$first = "yes";
-
-    opendir(DIR, "$prefix/etc/sysconfig");
-    @files = readdir(DIR);
-    foreach $file (@files){
-        if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-            $instance_count++;
-            if($file =~ /dirsrv-(.*)/){
-                if($first eq "yes"){
-                    $instances=$1;
-                    $first = "no";
-                } else {
-                    $instances=$instances . ", $1";
-                }
-                $name = $1;
-            }
-        }    
-    }
-        
-    if($opt_Z eq ""){
-        if ($instance_count == 1){
-            $opt_Z = $name;
-        } else {
-            print (STDERR "You must supply a server instance identifier.  Use -Z to specify instance name\n");
-            print "Available instances: $instances\n";
-            exit (1);
-        }
-    } elsif ($opt_Z =~ /^dirsrv-/){
-        # strip off "dirsrv-"
-        $opt_Z =~ s/^dirsrv-//;
-    } elsif ($opt_Z =~ /^slapd-/){
-        # strip off "slapd-"
-        $opt_Z =~ s/^slapd-//;
-    }
-    @info = DSUtil::get_missing_info($prefix, $opt_Z, $instances, $opt_h, $opt_p, $opt_D);
+    $opt_Z = DSUtil::get_server_id($opt_Z, "@initconfigdir@");
+    @info = DSUtil::get_missing_info("@instconfigdir@", $opt_Z, $opt_h, $opt_p, $opt_D);
     
 	if ($opt_j ne ""){
 		die "Error, cannot open password file $opt_j\n" unless (open (RPASS, $opt_j));
diff --git a/ldap/admin/src/scripts/restart-slapd.in b/ldap/admin/src/scripts/restart-slapd.in
index 800c512..8712082 100644
--- a/ldap/admin/src/scripts/restart-slapd.in
+++ b/ldap/admin/src/scripts/restart-slapd.in
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+source ./DSSharedLib
+
 # Script that restarts the ns-slapd server.
 # Exit status can be:
 #       0: Server restarted successfully
@@ -7,8 +9,11 @@
 #       2: Server started successfully (was not running)
 #       3: Server could not be stopped
 
-first="yes"
-args=""
+usage ()
+{
+    echo "Usage: restart-slapd [-Z serverID]"
+}
+
 while getopts "Z:SvVhi:d:w:" flag
 do
     case $flag in
@@ -19,70 +24,23 @@ do
         i) args=$args" -i $OPTARG";;
         w) args=$args" -w $OPTARG";;
         S) args=$args" -S";; 
-        h) echo "Usage: restart-slapd [-Z serverID]"
+        h) usage
            exit 0;;
-        ?) echo "Usage: restart-slapd [-Z serverID]"
+        ?) usage
            exit 1;;
     esac
 done
 
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-fi
-
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: restart-slapd [-Z serverID]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-
-
-if ! [ -a "$prefix/etc/dirsrv/slapd-$servid/dse.ldif" ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-@sbindir@/restart-dirsrv -d $prefix/etc/sysconfig $servid $args
+@sbindir@/restart-dirsrv -d @initconfigdir@ $servid $args
 if [ $? == 0 ]
 then
     echo Sucessfully restarted instance $servid
diff --git a/ldap/admin/src/scripts/restoreconfig.in b/ldap/admin/src/scripts/restoreconfig.in
index 1f5ea8e..c8f68bd 100755
--- a/ldap/admin/src/scripts/restoreconfig.in
+++ b/ldap/admin/src/scripts/restoreconfig.in
@@ -1,101 +1,47 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
-libpath_add "@libdir@"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@nss_libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
+usage ()
+{
+    echo "Usage: restoreconfig [-Z serverID]"
+    echo "   -Z      - Server instance identifier"
+}
+
 while getopts "Z:h" flag
 do
     case $flag in
         Z) servid=$OPTARG;;
-        h) echo "Usage: restoreconfig [-Z serverID]"
-           echo "   -Z      - Server instance identifier"
+        h) usage
            exit 0;;
-        ?) echo "Usage: restoreconfig [-Z serverID]"
-           echo "   -Z      - Server instance identifier"
+        ?) usage
            exit 1;;
-           
     esac
 done
 
-first="yes"
-
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: restoreconfig [-Z serverID]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
-conf_ldif=`ls -1t $prefix/var/lib/dirsrv/slapd-$servid/bak/$servid-*.ldif 2>/dev/null | head -1 `
+conf_ldif=`ls -1t @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-*.ldif 2>/dev/null | head -1 `
 if [ -z "$conf_ldif" ]
 then
-    echo No configuration to restore in $prefix/var/lib/dirsrv/slapd-$servid/bak/ ; exit 1
+    echo No configuration to restore in @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/ ; exit 1
 fi
 echo Restoring $conf_ldif...
-./ns-slapd ldif2db -D $configdir -i $conf_ldif -n NetscapeRoot 2>&1
+@sbindir@/ns-slapd ldif2db -D $configdir -i $conf_ldif -n NetscapeRoot 2>&1
 exit $?
diff --git a/ldap/admin/src/scripts/saveconfig.in b/ldap/admin/src/scripts/saveconfig.in
index 62aa160..f388a82 100755
--- a/ldap/admin/src/scripts/saveconfig.in
+++ b/ldap/admin/src/scripts/saveconfig.in
@@ -1,98 +1,47 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
+usage ()
+{
+    echo "Usage: saveconfig [-Z serverID]"
+    echo "   -Z      - Server instance identifier"
+}
+
 while getopts "Z:h" flag
 do
     case $flag in
         Z) servid=$OPTARG;;
-        h) echo "Usage: saveconfig [-Z serverID]"
-           echo "   -Z      - Server instance identifier"
+        h) usage
            exit 0;;
-        ?) echo "Usage: saveconfig [-Z serverID]"
-           echo "   -Z      - Server instance identifier"
+        ?) usage
            exit 1;;
     esac
 done
 
-first="yes"
-
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: saveconfig [-Z serverID]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
+configdir="@instconfigdir@/slapd-$servid"
+
 echo saving configuration...
-conf_ldif=$prefix/var/lib/dirsrv/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
-./ns-slapd db2ldif -N -D $configdir -s "o=NetscapeRoot" -a $conf_ldif -n NetscapeRoot 2>&1
+conf_ldif=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/$servid-`date +%Y_%m_%d_%H%M%S`.ldif
+@sbindir@/ns-slapd db2ldif -N -D $configdir -s "o=NetscapeRoot" -a $conf_ldif -n NetscapeRoot 2>&1
 if [ "$?" -ge 1 ] 
 then
     echo Error occurred while saving configuration
diff --git a/ldap/admin/src/scripts/schema-reload.pl.in b/ldap/admin/src/scripts/schema-reload.pl.in
index 8d235a6..3e8cc08 100644
--- a/ldap/admin/src/scripts/schema-reload.pl.in
+++ b/ldap/admin/src/scripts/schema-reload.pl.in
@@ -61,16 +61,13 @@ $schemadir = "";
 $verbose = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $i = 0;
 while ($i <= $#ARGV) 
@@ -116,63 +113,9 @@ while ($i <= $#ARGV)
     }
     $i++;
 }
-
-
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" )
 { 
diff --git a/ldap/admin/src/scripts/start-slapd.in b/ldap/admin/src/scripts/start-slapd.in
index 6f1f6a5..d31ffcf 100755
--- a/ldap/admin/src/scripts/start-slapd.in
+++ b/ldap/admin/src/scripts/start-slapd.in
@@ -1,12 +1,18 @@
 #!/bin/sh
 
+source ./DSSharedLib
+
 # Script that starts the ns-slapd server.
 # Exit status can be:
 #       0: Server started successfully
 #       1: Server could not be started
 #       2: Server already running
 
-args=""
+usage ()
+{
+    echo "Usage: start-slapd [-Z serverID]"
+}
+
 while getopts "Z:SvVhi:d:w:" flag
 do
     case $flag in
@@ -17,66 +23,28 @@ do
         i) args=$args" -i $OPTARG";;
         w) args=$args" -w $OPTARG";;
         S) args=$args" -S";;
-        h) echo "Usage: start-slapd [-Z serverID]"
+        h) usage
            exit 0;;
-        ?) echo "Usage: start-slapd [-Z serverID]"
+        ?) usage
            exit 1;;
     esac
 done
 
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
+    exit 1
 fi
 
-first="yes"
-if [ -z $servid ]
-then
-    # server id not provided, check if there is only one instance
-    inst_count=0
-    for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-    do
-        if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-        then
-            inst_count=`expr $inst_count + 1`
-            id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-            if  [ $first == "yes" ]
-            then
-                instances=$id
-                first="no"
-            else
-                instances=$instances", $id"
-            fi
-            name=$id
-        fi
-    done 
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: start-slapd [-Z serverID]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-
-@sbindir@/start-dirsrv -d $prefix/etc/sysconfig $servid $args
+@sbindir@/start-dirsrv -d @initconfigdir@ $servid $args
 if [ $? == 0 ]
 then
     echo Sucessfully started instance $servid
 else
     echo Failed to start instance $servid
 fi
+
 exit $?
diff --git a/ldap/admin/src/scripts/stop-slapd.in b/ldap/admin/src/scripts/stop-slapd.in
index 7661b17..c8b9f42 100755
--- a/ldap/admin/src/scripts/stop-slapd.in
+++ b/ldap/admin/src/scripts/stop-slapd.in
@@ -1,11 +1,18 @@
 #!/bin/sh
 
+source ./DSSharedLib
+
 # Script that stops the ns-slapd server.
 # Exit status can be:
 #       0: Server stopped successfully
 #       1: Server could not be stopped
 #       2: Server was not running
 
+usage ()
+{
+    echo "Usage: stop-slapd [-Z serverID]"
+}
+
 while getopts "Z:SvVhi:d:w:" flag
 do
     case $flag in
@@ -16,63 +23,23 @@ do
         i) args=$args" -i $OPTARG";;
         w) args=$args" -w $OPTARG";;
         S) args=$args" -S";;
-        h) echo "Usage: stop-slapd [-Z serverID]"
+        h) usage
            exit 0;;
-        ?) echo "Usage: stop-slapd [-Z serverID]"
+        ?) usage
            exit 1;;
     esac
 done
 
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
+    exit 1
 fi
 
-first="yes"
-if [ -z $servid ]
-then
-    # server id not provided, check if there is only one instance
-    inst_count=0
-    for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-    do
-        if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-        then
-            inst_count=`expr $inst_count + 1`
-            id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-            if  [ $first == "yes" ]
-            then
-                instances=$id
-                first="no"
-            else
-                instances=$instances", $id"
-            fi
-            name=$id
-        fi
-    done 
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: stop-slapd [-Z serverID]"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-
-
-@sbindir@/stop-dirsrv -d $prefix/etc/sysconfig $servid $args
+@sbindir@/stop-dirsrv -d @initconfigdir@ $servid $args
 if [ $? == 0 ]
 then
     echo Sucessfully stopped instance $servid
diff --git a/ldap/admin/src/scripts/suffix2instance.in b/ldap/admin/src/scripts/suffix2instance.in
index 0c31fc6..86b8905 100755
--- a/ldap/admin/src/scripts/suffix2instance.in
+++ b/ldap/admin/src/scripts/suffix2instance.in
@@ -1,104 +1,54 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
-first="yes"
-args=""
+usage ()
+{
+    echo "Usage: suffix2index [-Z serverID] -s <suffix>"
+}
+
 while getopts "Z:s:h" flag
 do
     case $flag in
         Z) servid=$OPTARG;;
         s) args=$args" -s $OPTARG";;
-        h) echo "Usage: suffix2index [-Z serverID] -s <suffix>"
+        h) usage
            exit 0;;
-        ?) echo "Usage: suffix2index [-Z serverID] -s <suffix>"
+        ?) usage
            exit 1;;
     esac
 done
 
 if [ "$args" == "" ]
 then
-    echo "Usage: suffix2index [-Z serverID] -s <suffix>"
+    usage
     exit 1
 fi
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: suffix2index [-Z serverID] -s <suffix>"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ $# -lt 2 ]
 then
 	echo Usage: suffix2instance [-Z serverID] {-s includesuffix}*
 	exit 1
 fi
 
-./ns-slapd suffix2instance -D $configdir $args 2>&1
+@sbindir@/ns-slapd suffix2instance -D $configdir $args 2>&1
diff --git a/ldap/admin/src/scripts/syntax-validate.pl.in b/ldap/admin/src/scripts/syntax-validate.pl.in
index 2d6c98b..18bddba 100644
--- a/ldap/admin/src/scripts/syntax-validate.pl.in
+++ b/ldap/admin/src/scripts/syntax-validate.pl.in
@@ -64,17 +64,14 @@ $passwdfile = "";
 $basedn_arg = "";
 $filter_arg = "";
 $filter = "";
-$first = "yes";
 $verbose = 0;
-$prefix = DSUtil::get_prefix();
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $i = 0;
 while ($i <= $#ARGV) 
@@ -126,61 +123,9 @@ while ($i <= $#ARGV)
     $i++;
 }
 
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" || $basedn_arg eq "" ) 
 { 
@@ -201,7 +146,7 @@ $taskname = "syntax_validate_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 
 # Build the task entry to add
 $dn = "dn: cn=$taskname, cn=syntax validate, cn=tasks, cn=config\n";
-$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
+$misc = "objectclass: top\nobjectclass: extensibleObject\n";
 $cn =  "cn: $taskname\n";
 $basedn = "basedn: $basedn_arg\n";
 
diff --git a/ldap/admin/src/scripts/upgradedb.in b/ldap/admin/src/scripts/upgradedb.in
index e250cc9..0f90567 100755
--- a/ldap/admin/src/scripts/upgradedb.in
+++ b/ldap/admin/src/scripts/upgradedb.in
@@ -1,35 +1,16 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
+source ./DSSharedLib
 
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
-
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
-first="yes"
-args=""
 while getopts "Z:vfrd:" flag
 do
     case $flag in
@@ -43,58 +24,22 @@ do
     esac
 done
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done 
-    
-if [ -z $servid ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ "$#" -eq 1 ]
 then
 	bak_dir=$1
 else
-	bak_dir=$prefix/var/lib/dirsrv/slapd-$servid/bak/upgradedb_`date +%Y_%m_%d_%H_%M_%S`
+	bak_dir=@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/bak/upgradedb_`date +%Y_%m_%d_%H_%M_%S`
 fi
 
 echo upgrade index files ...
-./ns-slapd upgradedb -D $configdir -a $bak_dir $args
+@sbindir@/ns-slapd upgradedb -D $configdir -a $bak_dir $args
diff --git a/ldap/admin/src/scripts/upgradednformat.in b/ldap/admin/src/scripts/upgradednformat.in
index 6f6ded8..0e7304f 100755
--- a/ldap/admin/src/scripts/upgradednformat.in
+++ b/ldap/admin/src/scripts/upgradednformat.in
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+source ./DSSharedLib
+
 # upgradednformat -- upgrade DN format to the new style (RFC 4514)
 # Usgae: upgradednformat [-N] -n backend_instance -a db_instance_directory
 #        -N: dryrun
@@ -8,42 +10,20 @@
 #        -a db_instance_directory -- full path to the db instance dir
 #                                    e.g., /var/lib/dirsrv/slapd-ID/db/userRoot
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
-
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@/dirsrv/"
+libpath_add "@nss_libdir@"
 libpath_add "@libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
-cd $server_sbin
-
-dir=""
-be=""
-servid=""
-dryrun=0
-
-first="yes"
-args=""        
+usage ()
+{
+    echo "Usage: $0 [-N] [-Z serverID] -n backend_instance -a db_instance_directory"
+}
+ 
 while getopts "vhd:a:n:D:N" flag
 do
     case $flag in
@@ -55,67 +35,31 @@ do
            dir="set";;
         n) args=$args" -n $OPTARG"
            be="set";;
-        h) echo "Usage: $0 [-N] [-Z serverID] -n backend_instance -a db_instance_directory"
+        h) usage
            exit 0;;
         D) args=$args" -D $OPTARG";;
-        ?) echo "Usage: $0 [-N] [-Z serverID] -n backend_instance -a db_instance_directory"
+        ?) usage
            exit 1;;
     esac
 done
 
 if [ "$be" = "" ] || [ "$dir" = "" ]; then
-    echo "Usage: $0 [-N] [-Z serverID] -n backend_instance -a db_instance_directory"
+    usage
     exit 1
 fi
 
-
-    # server id not provided, check if there is only one instance
-    inst_count=0
-    for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-    do
-        if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-        then
-            inst_count=`expr $inst_count + 1`
-            id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-            if  [ $first == "yes" ]
-            then
-                instances=$id
-                first="no"
-            else
-                instances=$instances", $id"
-            fi
-            name=$id
-        fi
-    done 
-    
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: $0 [-N] [-Z serverID] -n backend_instance -a db_instance_directory"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
-then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-./ns-slapd upgradednformat -D $configdir $args
+configdir="@instconfigdir@/slapd-$servid"
 
+@sbindir@/ns-slapd upgradednformat -D $configdir $args
 rc=$?
+
 exit $rc
diff --git a/ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in b/ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in
index f03a53f..de4db8b 100644
--- a/ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in
+++ b/ldap/admin/src/scripts/usn-tombstone-cleanup.pl.in
@@ -66,15 +66,12 @@ $maxusn_arg = "";
 $verbose = 0;
 $host = "";
 $port = "";
-$first = "yes";
-$prefix = DSUtil::get_prefix();
 
-$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
+$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:@ldaptool_bindir@:/usr/bin";
 
-DSUtil::libpath_add("$prefix@nss_libdir@");
-DSUtil::libpath_add("$prefix/usr/lib");
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
+DSUtil::libpath_add("/usr/lib64");
 
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
@@ -133,62 +130,9 @@ while ($i <= $#ARGV)
     $i++;
 }
 
-
-opendir(DIR, "$prefix/etc/sysconfig");
-@files = readdir(DIR);
-foreach $file (@files){
-    if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-        $instance_count++;
-        if($file =~ /dirsrv-(.*)/){
-            if($first eq "yes"){
-                $instances=$1;
-                $first = "no";
-            } else {
-                $instances=$instances . ", $1";
-            }
-            $name = $1;
-        }
-    }
-}
-    
-if($servid eq ""){
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
-@info = DSUtil::get_missing_info($prefix, $servid, $instances, $host, $port, $rootdn);
-
-if ($passwdfile ne ""){
-# Open file and get the password
-    unless (open (RPASS, $passwdfile)) {
-        die "Error, cannot open password file $passwdfile\n";
-    }
-    $passwd = <RPASS>;
-    chomp($passwd);
-    close(RPASS);
-} elsif ($passwd eq "-"){
-# Read the password from terminal
-	print "Bind Password: ";
-	# Disable console echo
-	system("@sttyexec@ -echo") if -t STDIN;
-	# read the answer
-	$passwd = <STDIN>;
-	# Enable console echo
-	system("@sttyexec@ echo") if -t STDIN;
-	print "\n";
-	chop($passwd); # trim trailing newline
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
+@info = DSUtil::get_missing_info("@instconfigdir@", $servid, $host, $port, $rootdn);
+$passwd = DSUtil::get_password_from_file($passwd, $passwdfile);
 
 if ( $info[2] eq "" || $passwd eq "" )
 { 
diff --git a/ldap/admin/src/scripts/verify-db.pl.in b/ldap/admin/src/scripts/verify-db.pl.in
index bff8a2e..364136c 100644
--- a/ldap/admin/src/scripts/verify-db.pl.in
+++ b/ldap/admin/src/scripts/verify-db.pl.in
@@ -149,7 +149,6 @@ if ($isWin) {
 
 my $i = 0;
 $startpoint = "";
-$prefix = DSUtil::get_prefix();
 
 while ($i <= $#ARGV) {
   if ( "$ARGV[$i]" eq "-a" ) {  # path to search the db files
@@ -164,39 +163,7 @@ while ($i <= $#ARGV) {
   $i++;
 }
 
-$first = "yes";
-if($servid eq ""){
-    opendir(DIR, "$prefix/etc/sysconfig");
-    @files = readdir(DIR);
-    foreach $file (@files){
-        if($file =~ /^dirsrv-/ && $file ne "dirsrv-admin"){
-            $instance_count++;
-            if($file =~ /dirsrv-(.*)/){
-                if($first eq "yes"){
-                    $instances=$1;
-                    $first = "no";
-                } else {
-                    $instances=$instances . ", $1";
-                }
-                $name = $1;
-            }
-        }
-    }
-    if ($instance_count == 1){
-        $servid = $name;
-    } else {
-        &usage;
-        print "You must supply a server instance identifier.  Use -Z to specify instance name\n";
-        print "Available instances: $instances\n";
-        exit (1);
-    }
-} elsif ($servid =~ /^dirsrv-/){
-    # strip off "dirsrv-"
-    $servid =~ s/^dirsrv-//;
-} elsif ($servid =~ /^slapd-/){
-    # strip off "slapd-"
-    $servid =~ s/^slapd-//;
-}
+$servid = DSUtil::get_server_id($servid, "@initconfigdir@");
 
 print("*****************************************************************\n");
 print("verify-db: This tool should only be run if recovery start fails\n" .
@@ -206,12 +173,12 @@ print("verify-db: This tool should only be run if recovery start fails\n" .
 print("*****************************************************************\n");
 
 if ( "$startpoint" eq "" ) {
-  $startpoint = "$prefix/var/lib/dirsrv/slapd-$servid/db";
+  $startpoint = "@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/db";
 }
 # get dirs having DBVERSION
 my $dbdirs = getDbDir($startpoint);
 
-$ENV{'PATH'} = "@libdir@/dirsrv/slapd-$servid:$prefix@db_bindir@:$prefix/usr/bin:@db_bindir@:/usr/bin";
+$ENV{'PATH'} = "@libdir@/dirsrv/slapd-$servid:@db_bindir@:/usr/bin:@db_bindir@:/usr/bin";
 
 DSUtil::libpath_add("@db_libdir@");
 DSUtil::libpath_add("@libdir@");
diff --git a/ldap/admin/src/scripts/vlvindex.in b/ldap/admin/src/scripts/vlvindex.in
index 4f0c693..4854b00 100755
--- a/ldap/admin/src/scripts/vlvindex.in
+++ b/ldap/admin/src/scripts/vlvindex.in
@@ -1,35 +1,22 @@
 #!/bin/sh
 
-libpath_add() {
-    [ -z "$1" ] && return
-    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1
-}
-
-server_dir="@libdir@/dirsrv/"
-SCRIPT=$(readlink -f $0)
-SCRIPTPATH=$(dirname $SCRIPT)
-if [ $SCRIPTPATH == "/usr/sbin" ]
-then
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/usr\/sbin//'`
-    server_sbin="/usr/sbin"
-else
-    prefix=`echo "$SCRIPTPATH" | sed -e 's/\/sbin//'`
-    server_sbin=$prefix"/sbin"
-fi
+source ./DSSharedLib
 
-libpath_add "$server_dir"
-libpath_add "$prefix@nss_libdir@"
-libpath_add "$prefix@libdir@"
+libpath_add "@libdir@/dirsrv/"
 libpath_add "@libdir@"
 libpath_add "@nss_libdir@"
-libpath_add "$prefix@pcre_libdir@"
+libpath_add "@pcre_libdir@"
 
 export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
-first="yes"
-args=""
+usage ()
+{
+    echo "Usage: vlvindex [-Z serverID] -n backend_instance | {-s includesuffix}* -T attribute"
+    echo Note: either \"-n backend_instance\" or \"-s includesuffix\" are required.
+}
+
 while getopts "Z:vd:a:t:T:Sn:s:x:hD:" flag
 do
     case $flag in
@@ -44,67 +31,28 @@ do
         n) args=$args" -n $OPTARG";;
         x) args=$args" -x $OPTARG";;
         D) args=$args" -D $OPTARG";;
-        h) echo "Usage: vlvindex [-Z serverID] -n backend_instance | {-s includesuffix}* -T attribute"
-           echo Note: either \"-n backend_instance\" or \"-s includesuffix\" are required.
+        h) usage
            exit 0;;
-        ?) echo "Usage: vlvindex [-Z serverID] -n backend_instance | {-s includesuffix}* -T attribute"
-           echo Note: either \"-n backend_instance\" or \"-s includesuffix\" are required.
+        ?) usage
            exit 1;;
     esac
 done
 
-# server id not provided, check if there is only one instance
-inst_count=0
-for i in `ls $prefix/etc/sysconfig/dirsrv-* 2>/dev/null`
-do
-    if [ $i != '$prefix/etc/sysconfig/dirsrv-admin' ]
-    then
-        inst_count=`expr $inst_count + 1`
-        id=$(expr "$i" : ".*dirsrv-\([^)]*\).*")
-        if  [ $first == "yes" ]
-        then
-            instances=$id
-            first="no"
-        else
-            instances=$instances", $id"
-        fi
-        name=$id
-    fi
-done
-     
-if [ -z $servid ]
-then
-    if [ $inst_count -eq 1 ]
-    then
-        servid=$name
-    else 
-        # error
-        echo "Usage: vlvindex [-Z serverID] -n backend_instance | {-s includesuffix}* -T attribute"
-        echo "You must supply a server instance identifier.  Use -Z to specify instance name"
-        echo "Available instances: $instances"
-        exit 1
-    fi
-elif [ $servid == slapd-* ]
-then
-    servid=`echo "$servid" | sed -e 's/slapd-//'`
-elif [ $servid == dirsrv-* ]
+servid=$(get_server_id "@initconfigdir@" $servid)
+if [ $? == 1 ]
 then
-    servid=`echo "$servid" | sed -e 's/dirsrv-//'`
-fi
-configdir="$prefix/etc/dirsrv/slapd-$servid"
-if ! [ -a $configdir ]
-then
-    echo "Invalid server identifier: $servid"
-    echo "Available instances: $instances"
+    usage
+    echo "You must supply a valid server instance identifier.  Use -Z to specify instance name"
+    echo "Available instances: $servid"
     exit 1
 fi
 
-cd $server_sbin
+configdir="@instconfigdir@/slapd-$servid"
+
 if [ $# -lt 4 ]
 then
-	echo "Usage: vlvindex [-Z serverID] -n backend_instance | {-s includesuffix}* -T attribute"
-	echo Note: either \"-n backend_instance\" or \"-s includesuffix\" are required.
+	usage
 	exit 1
 fi
 
-./ns-slapd db2index -D $configdir $args
+@sbindir@/ns-slapd db2index -D $configdir $args
-- 
1.7.1

