|
|
@@ -4,23 +4,45 @@ libpath_add()
|
|
|
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()
|
|
|
+# pass in a string that ends in dirsrv-name or slapd-name
|
|
|
+# and convert it to just "name"
|
|
|
+# the string could be a path name or not
|
|
|
+# if the string did not match @package_name@-name or slapd-name it
|
|
|
+# will be returned as is
|
|
|
+# want to be able to handle weird cases like /slapd-@package_name@-foo
|
|
|
+# that should normalize to the strange @package_name@-foo e.g.
|
|
|
+# someone named the instance "@package_name@-foo"
|
|
|
+normalize_server_id()
|
|
|
{
|
|
|
- dir=$1
|
|
|
- servid=$2
|
|
|
- first="yes"
|
|
|
- inst_count=0
|
|
|
- instances="<none>"
|
|
|
- rc=0
|
|
|
+ echo "$1" | sed '
|
|
|
+# save the current line
|
|
|
+h
|
|
|
+# delete leading path components if any (i.e. basename)
|
|
|
+s/^.*\///;ta
|
|
|
+:a
|
|
|
+# begins with @package_name@- ; remove it and exit
|
|
|
+s/^@package_name@-//;tx
|
|
|
+# begins with slapd- ; remove it and exit
|
|
|
+s/^slapd-//;tx
|
|
|
+# no match - return original string
|
|
|
+g
|
|
|
+:x
|
|
|
+'
|
|
|
+}
|
|
|
|
|
|
+# look for all initconfig files in the given directory
|
|
|
+# the initconfig files are the files used in the startup scripts
|
|
|
+# to start each instance
|
|
|
+# e.g. /etc/sysconfig/dirsrv-INST
|
|
|
+# these scripts contain the pointer CONFIG_DIR to where the instance
|
|
|
+# configuration files are to be found
|
|
|
+# if the given directory is empty, look in @initconfigdir@
|
|
|
+# if not running as root, look for non-system instances in
|
|
|
+# $HOME/.dirsrv
|
|
|
+# ignore the dirsrv-admin admin server config file
|
|
|
+get_initconfig_files()
|
|
|
+{
|
|
|
+ dir=${1:-@initconfigdir@}
|
|
|
# convert
|
|
|
# uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),.....
|
|
|
# to
|
|
|
@@ -29,61 +51,96 @@ get_server_id()
|
|
|
userid=`id | awk -F'[=(]+' '{print $2}'`
|
|
|
if [ "$userid" -ne 0 ] ; then
|
|
|
# magic - see start-dirsrv, DSCreate.pm::get_initconfigdir, etc.
|
|
|
- dir=$HOME/.@package_name@
|
|
|
+ extradir=$HOME/.@package_name@
|
|
|
+ if [ -d $extradir ] ; then
|
|
|
+ extra="$extradir/@package_name@-*"
|
|
|
+ fi
|
|
|
fi
|
|
|
+ # setting the env var forces the use of it and nothing else
|
|
|
if [ -n "$INITCONFIGDIR" ] ; then
|
|
|
dir=$INITCONFIGDIR
|
|
|
+ extra=
|
|
|
fi
|
|
|
-
|
|
|
- # look first in user provided INITCONFIGDIR, then in the system/build location,
|
|
|
- # then in the users home dir - cases
|
|
|
- # 1. system install but running as non-root user
|
|
|
- # in this case, we want to use the instance from $dir - it will
|
|
|
- # fallback to $homedir in that case, and if that is a problem, the user will
|
|
|
- # just have to temporarily move $homedir/dirsrv-sysinstancename out of the way
|
|
|
- # while working on the system instance
|
|
|
- # 2. prefix/non-system install
|
|
|
- # in this case, we want to use $homedir - if for some reason there is a system
|
|
|
- # instance in $dir with the same name, the user can use INITCONFIGDIR to
|
|
|
- # override that and force the use of the one from $homedir
|
|
|
- for i in `ls $dir/@package_name@-* 2>/dev/null`
|
|
|
- do
|
|
|
- if [ $i != "$dir/@package_name@-admin" ]
|
|
|
- then
|
|
|
- inst_count=`expr $inst_count + 1`
|
|
|
- id=$(expr "$i" : ".*@package_name@-\([^)]*\).*")
|
|
|
- if [ $first == "yes" ]
|
|
|
- then
|
|
|
- instances=$id
|
|
|
- first="no"
|
|
|
- else
|
|
|
- instances=$instances", $id"
|
|
|
- fi
|
|
|
- name=$id
|
|
|
+ retfiles=
|
|
|
+ found=1
|
|
|
+ for file in $dir/@package_name@-* $extra ; do
|
|
|
+ if [ ! -r "$file" ] ; then continue ; fi
|
|
|
+ case "$file" in */@package_name@-admin) continue ;; esac
|
|
|
+ if [ -z "$retfiles" ] ; then
|
|
|
+ retfiles=$file
|
|
|
+ else
|
|
|
+ retfiles="$retfiles $file"
|
|
|
fi
|
|
|
+ found=0
|
|
|
done
|
|
|
+ echo $retfiles
|
|
|
+ return $found # 0 return means success - at least one found
|
|
|
+}
|
|
|
+
|
|
|
+#
|
|
|
+# get_init_file()
|
|
|
+#
|
|
|
+# The init file is the instance specific file under
|
|
|
+# the @initconfig@ directory e.g.
|
|
|
+# /etc/sysconfig/dirsrv-instance
|
|
|
+# The presence and readability of this file means this is a
|
|
|
+# valid instance of directory server (except @package_name@-admin)
|
|
|
+# The CONFIG_DIR directive in this file tells us where to
|
|
|
+# look for the main server config
|
|
|
+# First grab all the @package_name@ init files
|
|
|
+# Then check if a server id was provided, if not, return the
|
|
|
+# one found if there is only one
|
|
|
+# If a servid was provided, make sure there is an init file
|
|
|
+# for that instance
|
|
|
+# Return the @initconfigdir@/@package_name@-$servid file name
|
|
|
+#
|
|
|
+get_init_file()
|
|
|
+{
|
|
|
+ dir=$1
|
|
|
+ servid=$2
|
|
|
+ first="yes"
|
|
|
+ inst_count=0
|
|
|
+ instances="<none>"
|
|
|
+ rc=0
|
|
|
|
|
|
- if [ -z $servid ]
|
|
|
+ # normalize servid, if given
|
|
|
+ if [ -n "$servid" ]
|
|
|
then
|
|
|
- # server id not provided, check if there is only one instance
|
|
|
- if [ $inst_count -eq 1 ]
|
|
|
+ servid=`normalize_server_id $servid`
|
|
|
+ fi
|
|
|
+
|
|
|
+ for i in `get_initconfig_files $dir`
|
|
|
+ do
|
|
|
+ inst_count=`expr $inst_count + 1`
|
|
|
+ id=`normalize_server_id $i`
|
|
|
+ if [ -n "$servid" -a "$id" = "$servid" ]
|
|
|
then
|
|
|
- servid=$name
|
|
|
- else
|
|
|
- # multiple instances, can not set server id. Return list of instances
|
|
|
- servid=$instances
|
|
|
- rc=1;
|
|
|
+ # found it
|
|
|
+ echo $i
|
|
|
+ exit 0
|
|
|
fi
|
|
|
- elif [ $servid == slapd-* ]
|
|
|
- then
|
|
|
- servid=`echo "$servid" | sed -e 's/slapd-//'`
|
|
|
- elif [ $servid == @package_name@-* ]
|
|
|
- then
|
|
|
- servid=`echo "$servid" | sed -e 's/@package_name@-//'`
|
|
|
+ if [ $first == "yes" ]
|
|
|
+ then
|
|
|
+ instances=$id
|
|
|
+ first="no"
|
|
|
+ else
|
|
|
+ instances=$instances", $id"
|
|
|
+ fi
|
|
|
+ name=$i
|
|
|
+ done
|
|
|
+
|
|
|
+ if [ -n $servid ] ; then
|
|
|
+ # if we got here, we did not find a match
|
|
|
+ echo $instances
|
|
|
+ exit 1
|
|
|
fi
|
|
|
- if ! [ -a "$dir/@package_name@-$servid" ]
|
|
|
+
|
|
|
+ # server id not provided, check if there is only one instance
|
|
|
+ if [ $inst_count -eq 1 ]
|
|
|
then
|
|
|
- # invalid instance name, return the "valid" instance names
|
|
|
+ servid=$name
|
|
|
+ else
|
|
|
+ # multiple instances, can not set server id. Return list of instances
|
|
|
servid=$instances
|
|
|
rc=1
|
|
|
fi
|
|
|
@@ -97,9 +154,9 @@ get_server_id()
|
|
|
#
|
|
|
process_dse ()
|
|
|
{
|
|
|
- servid=$1
|
|
|
+ configdir=$1
|
|
|
pid=$2
|
|
|
- file="@instconfigdir@/slapd-$servid/dse.ldif"
|
|
|
+ file="$configdir/dse.ldif"
|
|
|
shopt -s nocasematch
|
|
|
OLD_IFC=$IFC
|
|
|
IFS=""
|