#!/bin/sh set -e test_vars(){ for v in $REQUIRED_VARS ; do V="\$$v" if [ -z "$(eval echo $V)" ] ; then exit 0 fi done return 0 } # main # test environment [ "$CAPNAME" ] || exit 0 action="$1" case $action in create) # TODO: may be we need to test LDAP_MASTER role? # in this case ... join and create must export the same data # lliurex-cap create mus be done before or after ldap+krb5 init ? REQUIRED_VARS="LDAP_REPLICATOR_CN CAP_NET_HOST_IP LDAP_ADMIN_FILE CAP_LDAP_CAPNAME LDAP_BASE_DN CAP_ZERO_CAPNAME LDAP_REPLICATOR_NAME LDAP_REPLICATOR_PASS" eval "$(llxcfg-showvars $REQUIRED_VARS)" [ "$CAP_LDAP_CAPNAME" ] || CAP_LDAP_CAPNAME="$CAP_ZERO_CAPNAME" # test vars test_vars [ "$CAP_LDAP_CAPNAME" = "$CAPNAME" -a -r "$LDAP_ADMIN_FILE" ] || exit 0 # export admin password file TMP_DIR="$(mktemp -d)" tar czf "$TMP_DIR/ldap-files.ldap" "$LDAP_ADMIN_FILE" # export LDAP VARIABLES echo "LDAP_MASTER_BASE_DN=\"$LDAP_BASE_DN\"" >> "$TMP_DIR/ldap.vars" echo "LDAP_MASTER_URI=\"ldap://$CAP_NET_HOST_IP\"" >> "$TMP_DIR/ldap.vars" echo "LDAP_REPLICATOR_CN=\"$LDAP_REPLICATOR_CN\"" >> "$TMP_DIR/ldap.vars" echo "LDAP_REPLICATOR_NAME=\"$LDAP_REPLICATOR_NAME\"" >> "$TMP_DIR/ldap.vars" # add files to configuration lliurex-cap add-config "$CAP_LDAP_CAPNAME" "$TMP_DIR/ldap-files.ldap" "$TMP_DIR/ldap.vars" rm -fr "$TMP_DIR" ;; join) llxcfg-systemvars add LDAP_REPLICATOR_RID=$CAP_HOST_ID ;; joinedserver) llxcfg-cpkg update ldap-server ;; *) exit 0 ;; esac exit 0