#!/bin/bash
# Script to set up symbolic links to html directories for RV
#
# Format: infoSetupLinks
#
# Usage:
#     infoSetupLinks
#
#
#
# Exit status = 0 if no errors occur; non-zero otherwise.
#
#
# Module History:
# 00 10/19/2006  M. Gregor     Initial release
# 01 01/31/2007  M. Gregor     576738 - Add support to display additional informatin for vary on/off devices
# 02 08/22/2007  M. Gregor     621873 - Hang everythign off console web space
# 02 04/12/2008  M. Gregor     657925 - RV isolates and symbolics - changes to point to correct eCLipz


echo "Setting up symbolic links for InfoCenter "
infoDir=/info
#echo "infoDir: " $infoDir
#Create /info/NLS/help/topic subdirs
cmd="mkdir -p  /opt/ccfw/www%1/help/topic"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd
cmd="chown -R root:users /opt/ccfw/www%1/help"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd
cmd="chmod -R 775 /opt/ccfw/www%1/help"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd
#Create symbolic links from /info/NLS/eclipse/plugins/
cmd1="find %1/eclipse/plugins -type d -mindepth 1 -maxdepth 1"
cmd2='BEGIN {
print "ARGC =", ARGC
for (j = 1; j < ARGC; j++) {
  n = split( ARGV[j], tval, "/")
  for (k = 1; k <= n; k++) {
    print "tval[" k "] = " tval[k]
    if (k == 6) {
      print "creating symbolic link: " ARGV[j] "/ /opt/ccfw/www/" tval[2] "/" tval[3] "/help/topic/" tval[6]
      system("ln -s " ARGV[j] "/ /opt/ccfw/www/" tval[2] "/" tval[3] "/help/topic/" tval[6])
    }
  }
}
}'
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd1 | xargs awk "$cmd2"
echo "Setting up symbolic links for links within content "
infoDir=/info
#Create /opt/ccfw/www/info/NLS/eclipz subdirs
cmd="mkdir -p  /opt/ccfw/www%1"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd
cmd="chown -R root:users /opt/ccfw/www%1"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd
cmd="chmod -R 775 /opt/ccfw/www%1"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd
cmd="ln -s %1/eclipz/ /opt/ccfw/www%1/eclipz"
find $infoDir -mindepth 1 -maxdepth 1 -type d | xargs -i%1 $cmd

#-02 start  we should remove this when we make images absolute in html.../res/com/ibm/hwmca/p/service/images/image.gif
echo "Creating link for images hung off web space..."
mkdir -vp /opt/ccfw/www/opt/ccfw
chown -vR root:ccfw /opt/ccfw/www/opt/ccfw/
chmod -vR 775 /opt/ccfw/www/opt/ccfw/
ln -s /opt/ccfw/www/res/com/ /opt/ccfw/www/opt/ccfw/com
#-02 end

exit 0
