summaryrefslogtreecommitdiff
path: root/ldap
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-12-14 17:21:23 +0100
committerJonas Smedegaard <dr@jones.dk>2008-12-14 17:21:23 +0100
commit2edca013de8ec1a6e32cff62fafe28383c291d6e (patch)
treefc03fb9af555c694e7c741fecef43355c6776d5c /ldap
parenta90ae0e8460bfb43da87a6d296823a50a3e3f604 (diff)
Add getopt option parsing to mkldapdb.
Diffstat (limited to 'ldap')
-rwxr-xr-xldap/mkldapdb99
1 files changed, 92 insertions, 7 deletions
diff --git a/ldap/mkldapdb b/ldap/mkldapdb
index 229abc9..8ae9f24 100755
--- a/ldap/mkldapdb
+++ b/ldap/mkldapdb
@@ -4,23 +4,108 @@ set -e
umask 066
-# Resolve some defaults from other system config
-basedn="`grep '^BASE\b' /etc/ldap/ldap.conf | sed -e 's/^BASE[[:space:]]\+//' -e 's/,[[:space:]]\+/,/g'`"
-dnsdomain="`dnsdomainname`"
-orgname=""
-if [ -r /etc/local-ORG/orgname ]; then
- orgname="$(head -n 1 /etc/local-ORG/orgname)"
-fi
+PRG=$(basename "$0")
+
+TEMP=$(getopt -s sh -o b:e:d:fh -l basedn:,enable:,disable:,force,help -n "$PRG" -- "$@")
+if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+eval set -- "$TEMP"
+
+getbasedn() {
+ grep '^BASE\b' /etc/ldap/ldap.conf | sed -e 's/^BASE[[:space:]]\+//' -e 's/,[[:space:]]\+/,/g'
+}
+getdnsdomain() {
+ dnsdomainname
+}
+getorgname() {
+ if [ -r /etc/local-ORG/orgname ]; then
+ head -n 1 /etc/local-ORG/orgname
+ fi
+}
# config defaults as of slapd 2.4.10-3
backend="hdb"
+# extension default states (enabled/disabled)
+cipux=1
+horde=
+
+# strings above, and either functions above or strings right below,
+# can be overrided locally through this config file
+if [ -f /etc/local/mkldapdb.cfg ]; then
+ . /etc/local/mkldapdb.cfg
+fi
+
+basedn="${basedn:-$(getbasedn)}"
+dnsdomain="${dnsdomain:-$(getdnsdomain)}"
+orgname="${orgname:-$(getorgname)}"
+
+showhelp() {
+ cat <<EOF
+Usage: $PRG [opts...] [PHASE [PHASE...]]
+Setup LDAP database from skeleton files
+
+Options:
+ -b, --basedn LDAP Base DN (Distinguished Name) to use
+ (default: ${basedn})
+ -e, --enable Include this optional extension
+ -d, --disable Exclude this optional extension
+ -t, --tempdir Skip prep phase and use content of provided dir
+ -c, --config Include config phase
+ -i, --init Include init phase
+ -f, --force Update without asking for confirmation
+ -h, --help Show this help text
+
+The following extensions are available:
+ cipux CipUX admin framework ${cipux:+(enabled by default)}
+ horde HORDE web-app framework ${horde:+(enabled by default)}
+
+The following phases are possible:
+ prep Assemble slapd.conf and LDIF files with DIT parts
+ config Add/update LDAP server configuration file
+ init Purge any existing ldap data and initialize new core DIT
+ main Add general DIT for use with POSIX accounts
+ mainpw Apply/Change main admin password
+ opt Add optional DIT extensions
+ optpw Apply/Change passwords for accounts of optional extensions
+
+When no phases are supplied, all but config and init are applied
+
+Examples:
+ $PRG
+ $PRG --basedn dc=example,dc=org --enable horde prep
+EOF
+}
+
exit1() {
echo >&2 "Error: $1"
echo >&2 "Exiting..."
exit 1
}
+while true ; do
+ case "$1" in
+ -b|--basedn) basedn="$2"; shift 2;;
+ -e|--enable-extension)
+ case "$2" in
+ cipux|horde) eval "$2=1";;
+ *) exit1 "Unknown extension \"$2\""
+ esac
+ shift 2
+ ;;
+ -d|--disable-extension)
+ case "$2" in
+ cipux|horde) eval "$2=";;
+ *) exit1 "Unknown extension \"$2\""
+ esac
+ shift 2
+ ;;
+ -f|--force) force="1"; shift;;
+ -h|--help) showhelp; exit 0;;
+ --) shift; break;;
+ *) exit1 "Internal error!";;
+ esac
+done
+
# Ensure all required values are properly resolved
for var in basedn dnsdomain orgname backend; do
if [ -z "`eval echo '$'$var`" ]; then