#!/bin/sh
# This script synchronizes the UID and GID ownership information on OES
# servers for the two X-Tier users and one X-Tier group in eDirectory.
#
# It must be run on OES servers with non-standard X-Tier IDs prior to 
# installing OES 2 SP1 in the tree.
#
# Not all OES servers are affected. For more information, see "If Your Tree Has 
# Ever Contained an OES 1 Linux erver with LUM and NSS Installed" in the 
# OES Linux Installation Guide.
#
# Customize the settings below for each affected server.
#
# After customizing, run this script against your affected OES servers before 
# installing OES2 SP1 into the tree.  
#
# NOTE: The nam* and find commands in this script can also be run at the
# terminal prompt on each server, if you prefer that approach.
#
#set -x     #(uncomment to see commands for debugging)
id_check() {

        if [ `id -u` -ne 0 ]
        then
                echo "You must be root to run this script!"
                exit 65
        fi
}
id_check
echo ""
#
# settings      
#
# Replace the angle bracketed (<>) portion of the following line with 
# your server name (hostname).
# For example, server=my_server
#
server=<server_name>  
#
#
# Replace the portion of the following line that is in quotes, with the 
# eDirectory context of the X-Tier LUM objects: novlxtier, novlxregd, and novlxsrvd.
# Be sure to remove the angle brackets and retain the quotes. 
# For example, lum_context="ou=servers,o=company". 
#
lum_context="<context>"  
#
#
# Replace the portion of the following line that is in quotes, with the
# full admin name and context of your tree Admin.
# Be sure to remove the angle brackets and retain the quotes. 
# For example, admin_fdn="cn=admin,o=company"
#
admin_fdn="<admin_fdn>"
#
# NOTE: When the script runs, you are prompted for the admin password.
#
#
# Replace the following, including the angle brackets (<>), with the UID that the system
# assigned to the novlxregd user.
# For example, novlxregd_uid=101
#
novlxregd_uid=<novlxsrvd_uid>
#
#
# Replace the following, including the angle brackets (<>), with the UID that the system
# assigned to the novlxsrvd user. 
# For example, novlxsrvd_uid=103
#
novlxsrvd_uid=<novlxsrvd_uid>
#
#
# Replace the following, including the angle brackets (<>), with the GID that the system
# assigned to the novlxtier group. 
# For example, novlxtier_gid=101
#
novlxtier_gid=<novlxtier_gid>
#
#
# settings end

echo "The script contains the following settings:"
echo ""
echo "Server name (hostname) is set to $server"
echo "LUM objects context is set to $lum_context"
echo "Admin FDN is set to $admin_fdn"
echo ""
echo -n "Continue? [y\n] "
read ANSWER


main() {

# The following three lines only need to be run once in each context. However, it won't 
# cause problems to run them on each server. 

namgroupmod -a $admin_fdn -W $server -g 81 -o cn=novlxtier,$lum_context



namusermod -a $admin_fdn -G cn=novlxtier,$lum_context  -u 81 -o cn=novlxregd,$lum_context



namusermod -a $admin_fdn -G cn=novlxtier,$lum_context -u 82 -o cn=novlxsrvd,$lum_context


namconfig cache_refresh

# The two find commands below must be customized for and run on each affected server.

echo "Please wait...this may take up to 30-60 minutes to complete."
sleep 2
find / -follow -printf "%p\n" 2>/dev/null | xargs chown --from $novlxregd_uid:$novlxtier_gid 81:81
find / -follow -printf "%p\n" 2>/dev/null | xargs chown --from $novlxsrvd_uid:$novlxtier_gid 82:81

echo "Script has completed"
exit
}


if [ $ANSWER = "y" ];
then
main
else
echo "Please edit the settings section of this script."
fi

exit
