Diga/sx magic script
ScalixDB Schema Name Script
In the ScalixDB (Postgresql database), each user is assigned their own 'schema' (which is postgresql parlance for a database of their own). In order to guarantee uniqueness and comply with postgresql naming syntax, the name of these schema (schemata??) are generated by computing the MD5 hash of the user's directory entry GUID. Unfortunately this makes it impossible to identify the schema for a particular user by inspection. The script below performs the necessary directory lookup and MD5 hash. It also checks for the schema in the local postgresql database. Note that depending on which machine the script is run on, the user's schema may not be found in that database, or indeed the lookup may fail because there isn't a database on the local machine. In that case, take the schema name the script prints and use it against the appropriate database.
omshowpguser
#!/bin/sh if [ -z "$1" ]; then echo "Usage: $0 <filter>" echo "Example: $0 S=Smith" exit 2 fi FILTER="$1" LC_ALL=C export LC_ALL # Pass "" to prevent implicit passing of $* . /opt/scalix-postgres/bin/common-helpers.sh "" /etc/init.d/scalix-postgres status | grep 'is running' >/dev/null 2>/dev/null if [ $? = "0" ]; then POSTGRES_RUNNING=1 else POSTGRES_RUNNING=0 fi if [ $POSTGRES_RUNNING -ne 1 ]; then /etc/init.d/scalix-postgres start fi IDS=`omsearch -e $FILTER -m GLOBAL-UNIQUE-ID` if [ $? -ne 0 ]; then exit 1 fi # The following won't work #GUID=`echo "$IDS" | cut -d'=' -f2- | tr -d '[:space:]'` # Better is: GUID_TEMP=`echo "$IDS" | cut -d'=' -f2- | tr -d '[:space:]'` GUID=`echo "$GUID_TEMP" | sed 's/\\\//g'` HASHED=`python -c "import md5; print md5.new('${GUID}').hexdigest()"` SCHEMA="sx_${HASHED}" echo "$IDS" echo "User DB Schema ID: $SCHEMA" su - -c "$PGENGINE/psql -h $PSQL_DIR -p $PSQL_PORT -c '\dn' scalix" postgres | grep "$SCHEMA" >/dev/null 2>/dev/null res=$? found="No" if [ $res == 0 ]; then found="Yes" fi echo "User Schema Exists in DB on this machine: $found"