#!/bin/sh
#####################################################################################
#
# This file is called after the files of the package are copied on to the disk
#
# Functionality:
# - Extract tar to SC directory
# - Create VARDIR
# - Create FW_BOOT_DIR
# - Creating registry
# - Add boot files (StarupItem)
# - Add Usuful links
#
######################################################################################


SP_VER=4
CP_VER=5.0
SRPACK=/tmp/SecureClientInstaller/desktop_B634006015_1.tgz
SRDIR=/opt/CPsrsc-50 ; export SRDIR
VARDIR=${SRDIR}/var ; export VARDIR
CPDIR=${SRDIR} ; export CPDIR
export DYLD_LIBRARY_PATH
DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH:-:}
DYLD_LIBRARY_PATH=${SRDIR}/bin:${DYLD_LIBRARY_PATH}
FWDIR=${SRDIR} ; export FWDIR
REG_FILE=${SRDIR}/tmp/create_reg
ST_ITEM=/Library/LaunchDaemons/
ST_ITEM_OLD=/System/Library/StartupItems
APPLIPATH=/Applications/Check\ Point\ VPN\-1\ SecureClient
_YN="n"

AWK=awk
CAT=/bin/cat
CD=cd
CHMOD=/bin/chmod
CHOWN=/usr/sbin/chown
CHGRP=/usr/bin/chgrp
CP=/bin/cp
ECHO=/bin/echo
LN=/bin/ln
MKDIR=/bin/mkdir
MV=/bin/mv
RM=/bin/rm
SED=sed
TAR=tar
GUNZIP=/usr/bin/gunzip
TOUCH=/usr/bin/touch
IAM=`/usr/bin/id -g`
MORE=/usr/bin/more

INST_DEBUG_LEVEL=`$ECHO $INST_DEBUG_LEVEL | $SED 's/[^0-9]*//'`
INST_DEBUG_LEVEL=${INST_DEBUG_LEVEL:-0}
INST_DEBUG_LEVEL=9

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO ' '
    $ECHO Welcome to Check Point SecureClient For Mac OS-X
    $ECHO ================================================
fi

umask 007

#=============================================================
# Check preconditions: root user, not already installed etc.

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO "Checking preconditions..."
fi

# check root user
if [ "$IAM" != "0" ]; then
	if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
		$ECHO "Must be root to install"
	fi
	exit 1
fi

# check kernel version

MAJOR=`uname -r | tr '.C[a-z]-' '   ' | awk '{print $1}'`
MINOR=`uname -r | tr '.C[a-z]-' '   ' | awk '{print $2}'`

if  [ "$MAJOR" < "9" ]; then
	if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
	    $ECHO ' '
	    $ECHO "Unsupported platform \(Kernel $MAJOR.$MINOR\)"
	    $ECHO "SecureClient is supported only on Mac OS-X 10.5 \(Leopard\)"
	    $ECHO "You may need to upgrade your kernel."
	fi
    exit 1
fi

# Check for previous installations
DIREXISTS=`ls -l $SRDIR | wc -l | awk '{print $1}'`
if [ "$DIREXISTS" -gt "0" ]; then
	if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
	    $ECHO SecureClient already installed in $SRDIR.
    	$ECHO Please uninstall before installing.
	fi
    exit -1
fi


#=============================================================
# Unpack package file
if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO "Unpacking package..."
fi

$MKDIR /opt 1>/dev/null  2>&1
$MKDIR $SRDIR
$TAR xfz $SRPACK --directory=$SRDIR

#=============================================================
# Accept license agreement

#if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
#	$ECHO ' '
#	$ECHO Please read the following license agreement.
#	$ECHO ENTER to continue...
#	<<<word
#	$MORE $SRDIR/license.txt
#	while ["1"]; do
#	    $ECHO ' '
#	    $ECHO 'Do you accept all the terms of this license agreement (y/n) ?'
#	    $_YN=<<<word
#	    if [ "$_YN" != "y" ]; then 
#			$ECHO Installation canceled.
#			exit 0
#	    fi
#	done
#fi


#=============================================================
# Create VARDIR

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO "Creating VARDIR..."
fi

if [ ! -d /var/opt ]; then
	$MKDIR /var/opt
fi
if [ -d $VARDIR ]; then
	$RM -rf $VARDIR
fi

$MKDIR $VARDIR

#conf
if [ -d $SRDIR/conf ]; then
    $MV  $SRDIR/conf $VARDIR
    $RM -rf $SRDIR/conf
    $LN -s $VARDIR/conf $SRDIR/conf
fi

#database
if [ -d $SRDIR/database ]; then
    $MV $SRDIR/database $VARDIR
    $RM -rf $SRDIR/database
    $LN -s $VARDIR/database $SRDIR/database 
fi

#policy
if [ -d $SRDIR/policy ]; then
    $MV $SRDIR/policy $VARDIR
    $RM -rf $SRDIR/policy
    $LN -s $VARDIR/policy $SRDIR/policy
fi

#state
if [ -d $SRDIR/state ]; then
    $MV $SRDIR/state $VARDIR
    $RM -rf $SRDIR/state
    $LN -s $VARDIR/state $SRDIR/state
fi

#log
if [ -d $SRDIR/log ]; then
    $MV $SRDIR/log $VARDIR
    $RM -rf $SRDIR/log
    $LN -s $VARDIR/log $SRDIR/log
fi

#tmp
if [ -d $SRDIR/tmp ]; then
    $MV $SRDIR/tmp $VARDIR
    $RM -rf $SRDIR/tmp
    $LN -s $VARDIR/tmp $SRDIR/tmp
fi

#registry

if [ -d $VARDIR/registry ]; then
	$RM -rf $VARDIR/registry
fi
$MKDIR $VARDIR/registry
$LN -s $VARDIR/registry $SRDIR/registry

#package customization - check for added userc.C 
USERCEXISTS=`ls -l $PACKAGE_PATH/Contents/Resources/userc.C | wc -l | awk '{print $1}'`
if [ "$USERCEXISTS" -gt "0" ]; then
	if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
	    $ECHO Replacing userc.C file.
	fi
    cp $PACKAGE_PATH/Contents/Resources/userc.C $SRDIR/database/userc.C
fi
#=============================================================
# Update files permissions

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO "Updating files permissions..."
fi

# user can read directory and execute the user-mode binaries
$CHMOD o+rx /opt
$CHMOD 775 $SRDIR

$CHMOD 775 $SRDIR/bin/cpdos2unix
# dos2unix
$SRDIR/bin/cpdos2unix \
	$SRDIR/bin/scuninstall \
	$SRDIR/bin/SCStart \
	$SRDIR/bin/SCStop \
	$SRDIR/bin/collect \
	$SRDIR/.cshrc \
	$SRDIR/database/userc.C \
	$SRDIR/state/userc.* \
	$SRDIR/lib/tcpip.def
	


$CHMOD 775 $SRDIR/bin
$CHMOD 775 $SRDIR/bin/scc
$CHMOD 775 $SRDIR/.cshrc
$CHMOD 775 $SRDIR/bin/collect
$CHMOD 775 $SRDIR/boot/SecureClient/SecureClient
$CHMOD 775 $SRDIR/bin/scuninstall	

$CHMOD 750 $SRDIR/bin/envelope
$CHMOD 750 $SRDIR/bin/SCStart 
$CHMOD 750 $SRDIR/bin/SCStop 
$CHMOD 750 $SRDIR/bin/CPRegSvr
$CHMOD 750 $SRDIR/bin/SR_Service
$CHMOD 750 $SRDIR/bin/SR_Watchdog
$CHMOD 750 $SRDIR/bin/StartupItemsMgr
$CHMOD 750 $SRDIR/bin/srfw
$CHMOD 750 $SRDIR/bin/ckp_regedit
$CHMOD 750 $SRDIR/bin/conn_config
$CHMOD 750 $SRDIR/bin/cphash
$CHMOD 750 $SRDIR/bin/cpinfo
$CHMOD 750 $SRDIR/bin/cpprod_util
$CHMOD 750 $SRDIR/bin/fwboot
$CHMOD 750 $SRDIR/bin/install_name_tool
$CHMOD 750 $SRDIR/bin/kernel
$CHMOD 750 $SRDIR/bin/monitor
$CHMOD 750 $SRDIR/bin/vna_utils
$CHMOD 644 $SRDIR/bin/SecureClient.app/Contents/Frameworks/Qt*
$CHMOD 644 $SRDIR/bin/*dylib
$CHMOD 755 $SRDIR/bin/SecureClient.app/Contents/plugins/imageformats/libqmng.dylib


# conf, policy and database - root&wheel rw
$CHMOD -R 660 $VARDIR/conf
$CHMOD 770 $VARDIR/conf
$CHMOD -R 660 $VARDIR/policy
$CHMOD 770 $VARDIR/policy
$CHMOD -R 660 $VARDIR/database
$CHMOD 775 $VARDIR/database

# update boot modules
$CHOWN -R root 	$SRDIR/boot
$CHGRP -R wheel $SRDIR/boot
$CHMOD -R 740	$SRDIR/boot

# recreate these links with all-user access on them
umask 000
$RM $SRDIR/log
$LN -s $VARDIR/log $SRDIR/log
$RM $SRDIR/tmp
$LN -s $VARDIR/tmp $SRDIR/tmp

# VARDIR, log, registry and tmp - rw only for user+group
$CHMOD 775 $VARDIR
$CHMOD -R 660 $VARDIR/registry
$CHMOD 775 $VARDIR/registry
$CHMOD -R 660 $VARDIR/log
$CHMOD 777 $VARDIR/log
$CHMOD -R 660 $VARDIR/tmp
$CHMOD 777 $VARDIR/tmp
$CHMOD 555 $SRDIR/bin/collect

#=============================================================
# Create registry

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO "Creating registry..."
fi

# create HKLM as needed
if [ ! -f $SRDIR/registry/HKLM_registry.data ]; then
	$SRDIR/bin/ckp_regedit -c
fi

# create HKU as needed
if [ ! -f $SRDIR/registry/HKU_registry.data ]; then
	#$CP $SRDIR/conf/HKU_registry.data $SRDIR/registry/HKU_registry.data
	$MV $SRDIR/registry/HKLM_registry.data $SRDIR/registry/HKLM_registry.data_1
	$SRDIR/bin/ckp_regedit -c
	$MV $SRDIR/registry/HKLM_registry.data $SRDIR/registry/HKU_registry.data
	$MV $SRDIR/registry/HKLM_registry.data_1 $SRDIR/registry/HKLM_registry.data
fi


# SecureClient entries - build specific entries
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote CurrentVersion 1 $CP_VER 0	1>/dev/null 2>&1
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote SRDIR 1 $SRDIR 1		1>/dev/null 2>&1
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote FWDIR 1 $FWDIR 1		1>/dev/null 2>&1
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote PRODDIR 1 $SRDIR 1		1>/dev/null 2>&1
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote CurrentLabel 1 "FCS" 1	1>/dev/null 2>&1
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote//5.0//SP$SP_VER PrevSP 1 0 0	1>/dev/null 2>&1
$SRDIR/bin/cpprod_util CPPROD_SetValue SecuRemote CurrentSP 1 $SP_VER 1		1>/dev/null 2>&1

# Add entries from the file conf/Registry.conf be creating a temp batch file
$RM -f $REG_FILE
$CAT <<EOF> $REG_FILE
#!/bin/sh

EOF

$AWK '{FS=";"}{if ($1 !~  /^#/) print "$SRDIR/bin/cpprod_util CPPROD_SetValue "$1" "$2" "$4" "$3" 0 1>/dev/null 2>&1"}'  $SRDIR/conf/Registry.conf > $REG_FILE

$CAT <<EOF>> $REG_FILE

exit 0
EOF

$CHMOD 770 $REG_FILE
$REG_FILE

# Register dylibs from te file conf/regdll.conf
if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO "Registering DYLDs..."
fi
$SRDIR/bin/CPRegSvr /f $SRDIR/conf/regdll.conf


#==============================================================================
# Misc. configurations

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
     $ECHO "Preparing..."
fi

# fw lic
$TOUCH $SRDIR/conf/cp.macro
$TOUCH $SRDIR/conf/cp.license

# userc.C - take the one from the installation dir
if [ -f userc.C ]; then
	if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
		$ECHO "Using userc.C from installation directory."
	fi
	$CP userc.C $SRDIR/database/userc.C
fi



# Add SecureClient application link in Applications folder
$LN -s $SRDIR/bin/SecureClient.app "/Applications/SecureClient"
# Add SecureClient application link in Applications folder
$MKDIR "$APPLIPATH"
$LN -fs $SRDIR/bin/SecureClient.app "$APPLIPATH/SecureClient"
$LN -fs $SRDIR/help/index.htm "$APPLIPATH/SecureClient Help"
$LN -f $SRDIR/bin/scuninstall $SRDIR/scuninstall.command
$LN -s $SRDIR/bin/scuninstall $SRDIR/cpclean
$CHMOD 555 $SRDIR/scuninstall.command
$CHOWN root $SRDIR/bin/scuninstall
$CHMOD 555 $SRDIR/bin/scuninstall
$CHOWN root $SRDIR/bin/Uninstaller
$CHMOD 555 $SRDIR/bin/Uninstaller
$LN -fs $SRDIR/scuninstall.command "$APPLIPATH/SecureClient Uninstall"




# add a link to the logs folder in the /var/log dir where all the machine
# logs are.
$LN -s $VARDIR/log /var/log/SecureClient

#=============================================================

# TEMP: For debugging

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then

	# SR_Service log
    $RM -f $SRDIR/log/sr_service_tde.log 1>/dev/null  2>&1
    $TOUCH $SRDIR/log/sr_service_tde.log	
    $CHMOD 664 $SRDIR/log/sr_service_tde.log	
    
	# boot log
    $RM -f $SRDIR/log/ScBootlog.txt 1>/dev/null  2>&1
    $TOUCH $SRDIR/log/ScBootlog.txt	
    $CHMOD 664 $SRDIR/log/ScBootlog.txt
fi

#=============================================================
# Add a StartupItem 

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
     $ECHO "Adding a StartupItem..."
fi

$RM -rf $ST_ITEM_OLD/SecureClient 1>/dev/null  2>&1
$RM -f $ST_ITEM/SecureClient.plist 1>/dev/null  2>&1
$CP $SRDIR/boot/SecureClient/StartupParameters.plist $ST_ITEM/SecureClient.plist
$CHMOD 755 $ST_ITEM/SecureClient.plist
$TOUCH $ST_ITEM

$SRDIR/bin/StartupItemsMgr add /opt/CPsrsc-50/bin/SecureClient.app 1>/dev/null  2>&1

#==============================================================
# Add fwboot item

# if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
#      $ECHO "Setting up drivers..."
# fi

# $SRDIR/bin/StartupItemsMgr add-boot 1>/dev/null  2>&1

# Boot Policy
# ===========
# Note: The boot policy may be either acceptall or blockinbound.
# The relevant file is linked into $SRDIR/default.bin.
# In order to change the restrictions of the boot policy,
# replace sc_boot_acceptall with sc_boot_blockinbound.
# The relevant file is set according to the architecture
# ARCH=`uname -a | awk '{print $15}'`
# if [ "$ARCH" == "i386" ]; then
# BOOT_POLICY_FILE=sc_boot_acceptall.i386.bin
# else
# BOOT_POLICY_FILE=sc_boot_acceptall.ppc.bin
# fi
# $LN -s $SRDIR/conf/$BOOT_POLICY_FILE $SRDIR/default.bin

#
# Update kext cache
#
# Note: We have not added anything to the Extensions folder, but
# the loadng order may be changed.
#
# At first, we used to touch the Extensions folder for refreshing the cache.
# This was wrong - we have to delete the cache file as well.
#
$RM /System/Library/Extensions.kextcache
$RM /System/Library/Extensions.mkext
$TOUCH /System/Library/Extensions


##=============================================================
## Set environment variables
#
## This command will create file names /etc/csh.login in case such file doesn't exist,
## Otherwise it will only change its timestamp
#touch /etc/csh.login
#
## Delete existing secureclient's setenv commands (in case of upgrade we don't want to add these twice) 
## Append setenv commands for all required environment vairables
#
##!/bin/sh
#sed -e '/^setenv CPDIR \/opt\/CPsrsc-50/d'\
# -e '/^### SecureClient - Start ###/d'\
# -e '/^setenv FWDIR $CPDIR/d'\
# -e '/^setenv SRDIR $CPDIR/d'\
# -e '/^setenv FW_BOOT_DIR $CPDIR\/boot/d'\
# -e '/^setenv CPMDIR $CPDIR/d'\
# -e '/^setenv TMPDIR \/tmp/d'\
# -e '/^setenv PATH $FWDIR\/bin:$FWDIR\/lib:$PATH/d'\
# -e '/^setenv DYLD_LIBRARY_PATH $CPDIR\/bin/d'\
# -e '/^setenv DYLD_BIND_AT_LAUNCH 1/d'\
# -e '/^setenv CPTMPDIR $SRDIR\/tmp/d'\
# -e '/^### SecureClient - Finish ###/d'\
# -e '$s/$/\
#### SecureClient - 
 ###\
#setenv CPDIR \/opt\/CPsrsc-50 \
#setenv FWDIR $CPDIR \
#setenv SRDIR $CPDIR \
#setenv FW_BOOT_DIR $CPDIR\/boot \
#setenv CPMDIR $CPDIR \
#setenv TMPDIR \/tmp \
#setenv PATH $FWDIR\/bin:$FWDIR\/lib:$PATH \
#setenv DYLD_LIBRARY_PATH $CPDIR\/bin \
#setenv DYLD_BIND_AT_LAUNCH 1 \
#setenv CPTMPDIR $SRDIR\/tmp \
#### SecureClient - Finish ###\
#/g' /etc/csh.login > csh.login
#
#mv csh.login /etc

#============================================================
# For each exe and dylib file - set the exact path of each dylib it uses.
# otool list the dependant dylibs and install_name_tool is used to define
# the exact path of the dylib so we won't need DYLD_LIBRARY_PATH environment
# varible to find the dylibs during loading.
if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
	$ECHO "Setting files properties..."
fi

$CAT << EOF > set_install_names
#!/usr/bin/perl
my \$directory = "$SRDIR/bin";
my \$qtdir = "/usr/local/Trolltech/";
my \$qtdirpre = \$qtdir."Qt-4.1.1/lib";
my \$qtdirsuf = ".framework/Versions/4.0";
opendir (DIR, \$directory);
my @files= readdir DIR;
closedir(DIR);

my \$prefix;
my \$qtprefix;
my \$COLS;

# change fwboot dependant dylib
system ("$SRDIR/bin/install_name_tool -change libOS.dylib $SRDIR/bin/libOS.dylib $SRDIR/bin/fwboot");
system ("$SRDIR/bin/install_name_tool -change libOs.dylib $SRDIR/bin/libOS.dylib $SRDIR/bin/fwboot");

foreach my \$file (@files)
{
        \$prefix = substr(\$file, 0, 3);
        if (\$prefix eq "lib")
        {
#		for each dylib - define its exact path for the 3 executables
                system ("$SRDIR/bin/install_name_tool -change \$file \$directory/\$file \$directory/SecureClient.app/Contents/MacOS/SecureClient");
                system ("$SRDIR/bin/install_name_tool -change \$file \$directory/\$file \$directory/SR_Service");
                system ("$SRDIR/bin/install_name_tool -change \$file \$directory/\$file \$directory/SR_Watchdog");
                system ("$SRDIR/bin/install_name_tool -change \$file \$directory/\$file \$directory/StartupItemsMgr");

                my @DependantDylibs = ( );

#				get the list of dependant dylibs to temp file
				system("$SRDIR/bin/otool -L \$directory/\$file > tmpDylibDependencies");
                open(LIST_IN, "tmpDylibDependencies") or die "Couldn't open tmpDyLibDependencies for \$file";
                system("rm tmpDylibDependencies");

#				create a list from the temp file
                while ( <LIST_IN> )
                {
                        \$Record = \$_;
                        chomp(\$Record);
                        @NewRow = split(/[,(\t ]/, \$Record, \$COLS);
                        if (@NewRow[1] eq "") {}
                        else
                        {
                                push(@DependantDylibs, \$NewRow[1]);
                        }
                }
                close (LIST_IN);

#		for each dependant dylib define its exact path using install_name_tool utility
                \$ROWS = scalar(@DependantDylibs);
                for (\$CurRow=0; \$CurRow<\$ROWS; \$CurRow++)
                {
                        my \$CurDylib = \$DependantDylibs[\$CurRow];
                        my \$first_char = substr(\$CurDylib, 0, 1);
                        if (\$first_char eq '/') {}
                        else
                        {
				
                                system("$SRDIR/bin/install_name_tool -change \$CurDylib \$directory/\$CurDylib \$directory/\$file\n");
                        }
                }
        }

}


my \$qt_framework_directory = "$SRDIR/bin/SecureClient.app/Contents/Frameworks";
opendir (DIR, \$qt_framework_directory);
@files= readdir DIR;
closedir(DIR);

foreach my \$file (@files)
{

	\$qtprefix = substr(\$file, 0, 2);
        if (\$qtprefix eq "Qt")
        {
		# for each Qt Framework - define its exact path for the gui application
		system ("$SRDIR/bin/install_name_tool -change \$qtdirpre/\$file\$qtdirsuf/\$file \$qt_framework_directory/\$file \$directory/SecureClient.app/Contents/MacOS/SecureClient");
		# for each Qt Framework - define its exact path for libqmng library
		system ("$SRDIR/bin/install_name_tool -change \$qtdirpre/\$file\$qtdirsuf/\$file \$qt_framework_directory/\$file \$directory/SecureClient.app/Contents/plugins/imageformats/libqmng.dylib");
		# for each Qt Framework - find the other frameworks that it depends on and change it accordingly
		my @DependantDylibs = ( );
		# get the list of dependant dylibs to temp file
		system("$SRDIR/bin/otool -L \$qt_framework_directory/\$file > tmpDylibDependencies");
		open(LIST_IN, "tmpDylibDependencies") or die "Couldn't open tmpDyLibDependencies for \$file";
		system("rm tmpDylibDependencies");

		# create a list from the temp file
		while ( <LIST_IN> )
		{
			\$Record = \$_;
			chomp(\$Record);
			@NewRow = split(/[,(\t ]/, \$Record, \$COLS);
			if (@NewRow[1] eq "") {}
			else
			{
				push(@DependantDylibs, \$NewRow[1]);
			}
		}
		close (LIST_IN);

		# for each dependant dylib define its exact path using install_name_tool utility
		\$ROWS = scalar(@DependantDylibs);
		for (\$CurRow=0; \$CurRow<\$ROWS; \$CurRow++)
		{
			my \$CurDylib = \$DependantDylibs[\$CurRow];
			# looking for dependency in the form "/usr/local/Trolltech/Qt-4.1.1/lib/QtCore.framework/Versions/4.0/QtCore"
			if (\$CurDylib =~ /\$qtdir.*?(Qt\w+$)/) {
				\$Framework = \$1;
				system("$SRDIR/bin/install_name_tool -change \$CurDylib \$qt_framework_directory/\$Framework \$qt_framework_directory/\$file\n");
			} 
		}
	}
}	
EOF

# Run the shell while suppressing specific warning message "changing install names can't be redone for..."
/usr/bin/perl set_install_names 2>&1 | grep -v "install_name_tool: changing install names can't be redone for:"
$RM set_install_names

#=============================================================
# Set SecureClient default mode to CLI
/usr/bin/sed -e 's/:connect_api_support (false)/:connect_api_support (true)/'\
			 -e 's/:connect_mode (false)/:connect_mode (true)/' $SRDIR/database/userc.C > userc.C
mv userc.C $SRDIR/database

#=============================================================

# moving the Icon.Bundle to its correct location
mv $SRDIR/bin/SecureClient.app/Contents/Frameworks/Deployment/Icon.bundle $SRDIR/bin/SecureClient.app/Contents/Frameworks/
rm -rf $SRDIR/bin/SecureClient.app/Contents/Frameworks/Deployment/ 

# Expand the help tgz to $SRDIR/help

if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO Expanding help files...
fi

$GUNZIP $SRDIR/tmp/SR_Help_Osx.tgz
$MKDIR $SRDIR/help
pushd $SRDIR/help > /dev/null
$TAR -xf $SRDIR/tmp/SR_Help_Osx.tar
popd > /dev/null
$RM $SRDIR/tmp/SR_Help_Osx.tar

# Change permissions for help files
$CHMOD -R 744 $SRDIR/help/
$CHMOD 755 $SRDIR/help/
$CHMOD 755 $SRDIR/help/images/

# Change permissions for userc.C file
$CHMOD 664 $SRDIR/database/userc.C
	  
#=============================================================
# Finished...
if [ "$INST_DEBUG_LEVEL" -gt "0" ]; then
    $ECHO Installation complete. The Client will start upon reboot.
    $ECHO You can also start the Client now by running \'$SRDIR/bin/SCStart\'
    $ECHO =================================================
    $ECHO " "
fi

exit 0
