#!/bin/sh

#
# $Id: mkcmp,v 1.68.2.2 2006/03/28 16:28:41 jrumplik Exp $
# mkcmp
#
# 
#
#========================================================================
# MOD	DATE		WHO	WHAT
# ---	----     	---	----
# $Log: mkcmp,v $
# Revision 1.68.2.2  2006/03/28 16:28:41  jrumplik
# mods for patch globl2.2.0.105
#
# Revision 1.68.2.1  2004/06/01 12:33:10  jrumplik
# rcd 5888/tcd for services
#
# Revision 1.68  2002/08/14 15:26:35  jrumplik
# /dev/null for .info file creation for those that have no compdir
#
# Revision 1.67  2002/07/31 14:26:40  wmcbride
# added faxmgr.cfg
#
# Revision 1.66  2002/05/23 20:59:03  jrumplik
# ccm_admin.cfg
#
# Revision 1.65  2002/04/29 18:50:14  jrumplik
# change comment from Periphonics to Nortel on /etc/services updates
#
# Revision 1.64  2002/03/27 15:40:57  jrumplik
# if the component exists as vps and not as mps, adjust it to be named mps
#
# Revision 1.63  2002/02/22 19:42:19  jrumplik
# vps to mps chars
#
# Revision 1.62  2002/02/01 21:34:57  jrumplik
# BASEDIR/bin to VPSHOME/bin
#
# Revision 1.61  2001/12/03 18:53:54  jrumplik
# make mps component instead of vps component for PERImps
#
# Revision 1.60  2001/10/12 18:48:51  jrumplik
# srpregistry portno in services
#
# Revision 1.59  2001/04/05 14:56:47  jmuller
# Modified so start_vstat.sh is executed from $VPSHOME/bin.
#
# Revision 1.57  2001/04/05 14:30:14  jmuller
# Modified so binaries are run from ${BASEDIR}/bin and not ${BASEDIR}/PERIglobl/bin.
#
# Revision 1.56  2001/03/02 22:00:47  jrumplik
# *** empty log message ***
#
# Revision 1.55  2001/03/02 21:59:14  jrumplik
# if run on cmdline prompt for comptp and run mkcomptp.
#
# Revision 1.54  2001/01/17 23:48:18  tneary
# Merged globl2x into head
#
# Revision 1.46.4.11  2000/11/14 15:19:51  tneary
# Modified for renamed ipc, rtu and ptools libs
#
# Revision 1.46.4.10  2000/06/16 18:15:22  tneary
# Modified to create PERImps link
#
# Revision 1.46.4.9  2000/05/18 20:31:33  jrumplik
# added changes from globl1.1.1.39
#
# Revision 1.46.4.8  2000/04/03 14:07:46  jrumplik
# tmscomm component
#
# Revision 1.46.4.7  2000/03/27 17:41:23  tneary
# Removed extra fi in mmf_Dir
#
# Revision 1.46.4.6  2000/03/22 14:32:54  tneary
# Removed references to hardware.cfg
#
# Revision 1.46.4.5  2000/02/07 19:41:57  tneary
# Modified vpsEtcFiles to contain the rel6 VOS procs
#
# Revision 1.46.4.4  1999/08/30 16:14:26  tneary
# changed tms ports to 3000x instead of 300x
#
# Revision 1.46.4.3  1999/08/27 21:11:16  tneary
# Changed tmslrm from 3001 to 3000
#
# Revision 1.46.4.2  1999/08/25 16:12:53  tneary
# Add TMS ports to services file
#
# Revision 1.46.4.1  1999/08/04 15:26:52  tneary
# Commented out bootfile=elasys, owin_icons, and  vstat_cron from vps and v*
#
# Revision 1.46  1998/12/11 14:46:33  jrumplik
# removed boot image processing for PERIoscar
#
# Revision 1.45  1998/12/04 13:06:09  jrumplik
# *** empty log message ***
#
# Revision 1.43  1998/11/06 17:09:58  jrumplik
# mmf not compressed update
#
# Revision 1.42  1998/10/27 22:53:17  jrumplik
# copy mmf files instead of zcat uncompress
#
# Revision 1.41  1998/08/04 19:12:32  jrumplik
# do not set .info file perms for snmp
#
# Revision 1.40  1998/06/29 20:59:26  jrumplik
# added links for alm.log
#
# Revision 1.39  1998/06/22 19:17:05  jrumplik
# set env for vhman (via vpsrc.sh)
#
# Revision 1.38  1998/06/17 19:54:47  jrumplik
# removed sra1_oscar_mdm
#
# Revision 1.37  1998/06/02 15:51:08  jrumplik
# propogate changes in patch globl1.0.1.8
#
# Revision 1.36  1998/06/02 15:28:20  jrumplik
# move alm db build into PERIglobl postinstall
#
# Revision 1.32  1998/01/14 22:34:55  jrumplik
# cca_serv name
#
# Revision 1.31  1998/01/14 21:09:40  jrumplik
# oscar cfg updates
#
# Revision 1.30  1998/01/13 13:09:52  jrumplik
# oscar config files
#
# 0	1-jul-97	jar	Originate.(Using mkvps as base, adding
#				updates for new dir layout of pkg separation)
# 1	18-jul-97	jar	added ptlimages.cfg and copyVpsEtcFileOnce stuff
#				and new vhman comptype option
#				added several images for common etc
# 2	25-jul-97	jar	added oscar component support
# 3	31-jul-97	jar	added snmp component support
# 4    01-aug-97       jar     change version name to begin w/vps
# 5    07-aug-97       jar     oscar processing updates
# 6    20-aug-97       jar     consolidated copy functions
# 7    29-aug-97       jar     fix location of legacy pbin creation
# 8    2-sept-97       jar     save old format config files to name-pre53
# 9    3-sept-97       jar     add /etc/services update for srp and snmp
# 10   3-sept-97       jar     added oscar vhman for client, and data commondir
# 11   15-sept-97      jar     replaced fuser and xuser with fappl and xappl on
# 					alm commands.
# 12   24-sept-97      jar     adjusted fcns used for oscar component
# 13   26-sept-97      jar     update to be in globl pkg, common created in
#				globl, not PERIvps. diskless oscar common dirs
#				created here only. Also move alarm and several
#				other things to PERIglobl
# 14   2-oct-97      jar      update alm commands
# 15	 06-oct-97      jar      added charset config files
# 16	 10-oct-97      jar      added oscar startup, boot files, common
# 17	 20-oct-97      jar       set perms on etc
# 18	 27-oct-97      jar       correct optional, add mts basic component
# 19	 03-nov-97      jar       correct diskless alm generation, and oscar
#					cfg copy
# 20	04-nov-97	jar	upd xdm/Xsetup for rel53 dir path to alrmview
# 21	10-nov-97	jar	added global_users.cfg
# 22	12-nov-97	jar	mmf and apps/lib perms
# 23	13-nov-97	jar	added snmp and oscar files
# 24	01-dec-97	jar	add oscar srp.cfg parm
# Revision 1.29  1998/01/08 15:35:39  jrumplik
# added cca_serv.cfg
#
# Revision 1.28  1997/12/19 23:52:13  jrumplik
# periview.cfg check
#
# Revision 1.27  1997/12/19 15:52:45  jrumplik
# check for old format stats entry in periview.cfg and save if it is old
#
# Revision 1.26  1997/12/11 19:26:11  jrumplik
#  update openwin-menu stuff to rely on PATH env
#
#
# This script is called by mkX, where X is the component to be created.
# THe component is actually created here, depending on what is passed
# by mkX.
#
 
#========================================================================
# mkcmp must be called by a component defining script
# ie mkvps, mkvas, mkperiview, mkoscar or any others. 
#
# mkcmp determines the action by pattern matching $comptp, so a new
# comptp may require some update for more selective or add'l processing.

# The mkcmp script will install/update the $VPSHOME/common dir and the 
# $VPSHOME/component-dir with your component. The $VPSHOME/component-dir
# will end up being the dirname $VPSHOME/$comptp$compno
 
# Your commonent defining script must pass the following to mkcmp, at a minimum:
# comptp   component name, for instance periview vas vps or oscar
# compno   component number, for instance n in vps[n] 
# RELHOME  the distribution dir. 
# release  the version (release) to install. $RELHOME/$release is usually
#          $RELDIR as defined in pkg creation  
# VPSHOME  VPS dir in which to create component 
 
# Optional variables that mkcmp processes are:
# startfile startup script to be placed in /etc/rc3.d
# vpsdir  where PERIvps is installed, in most cases=VPSHOME.
# oldRelease used in vps for upgrading extremely old releases.

# 
#
#========================================================================
#-------------------------------------------------------------------

# Functions
#
# Exit with an error message.
#
terminate () {
	exitStatus=$?
	/bin/echo "\noperation failed, terminating"
	exit $exitStatus
}

#
# Make a component# directory and check for error.
#
mkComponentDir () {
	if [ $dir = $comptp ]; then
		if [ ! -d ${VPSHOME}/${comptp}$compno ]; then
			/bin/echo "\t${comptp}$compno"
			mkdir ${VPSHOME}/${comptp}$compno || terminate
		fi
	else
		if [ ! -d ${VPSHOME}/${comptp}${compno}/$dir ]; then
			/bin/echo "\t${comptp}${compno}/$dir"
			mkdir ${VPSHOME}/${comptp}${compno}/$dir || terminate
		fi
	fi
}

#
# Make a common directory and check for error.
#
makeCommonDir () {
		if [ ! -d ${VPSHOME}/common/$dir ]; then
			/bin/echo "\tcommon/$dir"
			mkdir -p ${VPSHOME}/common/$dir || terminate
                        # reset perms, for new dirs created in existing 
                        chown peri ${VPSHOME}/common/${dir}
                        chgrp peri ${VPSHOME}/common/${dir}
		fi
}

#
# Copy a file from the release to a component or other dir
#
copyFile () {
        if [ -f ${fromdir}/${file} ]; then
                /bin/echo "\t$file"
                cp ${fromdir}/${file} ${todir} || terminate
        fi
}

#
# Copy a file  only if it doesn't exist.
#
copyFileOnce () {
	if [ ! -f ${todir}/${file} ]; then
		if [ -f ${fromdir}/${file} ]; then
			/bin/echo "\t$file"
			cp ${fromdir}/${file} ${todir} || terminate
		fi
	else
		echo "${todir}/${file} already exists; copy cancelled."
	fi
}


#
# Copy a file from the release etc to the component etc only if it doesn't exist.
#
copyVpsEtcFileOnce () {
	if [ -f ${VPSHOME}/${comptp}${compno}/etc/cps.cfg ]; then
		mv -f ${VPSHOME}/${comptp}${compno}/etc/cps.cfg ${VPSHOME}/${comptp}${compno}/etc/hardware.cfg
	fi
	if [ -f ${VPSHOME}/${comptp}${compno}/etc/vpsgroups ]; then
		mv -f ${VPSHOME}/${comptp}${compno}/etc/vpsgroups ${VPSHOME}/${comptp}${compno}/etc/compgroups
	fi
        if [ -f ${RELHOME}/${release}/etc/${file} -a ! -f ${VPSHOME}/${comptp}${compno}/etc/${file} ]; then
                /bin/echo "\t$file"
                cp ${RELHOME}/${release}/etc/${file} ${VPSHOME}/${comptp}${compno}/etc || terminate
        fi
}

new_alm () {
. /etc/vpsrc.sh
#
# change the alarm database with the new version.
#
if [ -f ${VPSHOME}/${comptp}${compno}/etc/alarm.db.dir ]; then
	rm -f /tmp/alarm.usr.tmp /tmp/alarm.utx.tmp
	/bin/echo "\nExtracting Application alarms from alarm database."
	${VPSHOME}/bin/alm -d ${VPSHOME}/${comptp}${compno}/etc/alarm.db xappl /tmp/alarm.usr.tmp
	/bin/echo "\nExtracting User subrecords from alarm database."
        ${VPSHOME}/bin/alm -d ${VPSHOME}/${comptp}${compno}/etc/alarm.db deformat /tmp/alarm.utx.tmp
	/bin/echo "\nCleaning alarm from ${comptp}${compno}/etc..."
        mv -f ${VPSHOME}/${comptp}${compno}/etc/alarm.db.dir ${VPSHOME}/${comptp}${compno}/etc/alarm.db.dir-53nowincommon 2> /dev/null
        mv -f ${VPSHOME}/${comptp}${compno}/etc/alarm.db.pag ${VPSHOME}/${comptp}${compno}/etc/alarm.db.pag-53nowincommon 2> /dev/null
fi

/bin/echo "\nBuilding alarm database..."
${VPSHOME}/bin/alm -q -y create ${BASEDIR}/PERIglobl/misc/alarm.uts || terminate
/bin/echo

if [ -f /tmp/alarm.usr.tmp ]; then
	/bin/echo "\nAdding Application alarms into alarm database."
	${VPSHOME}/bin/alm fappl /tmp/alarm.usr.tmp
fi
if [ -f /tmp/alarm.utx.tmp ]; then
	/bin/echo "\nAdding User subrecords into alarm database."
	${VPSHOME}/bin/alm format /tmp/alarm.utx.tmp 
fi

}

do_vhman () {
#
# Update the vpshosts file to reflect a new (or updated) component.
#
. /etc/vpsrc.sh
localHost=`uname -n`
/bin/echo "\nUpdating vpshosts..."
${VPSHOME}/bin/vhman -qd -c${compno} -t${comptp}
#${VPSHOME}/bin/vhman -qa -c${compno} -t${comptp} -h$localHost -f
${VPSHOME}/bin/vhman -qa -c${compno} -t${comptp} -h- -f
}

vps_sys_etc () {
# copy in vpsrc and set fopr env.
/bin/echo "\nCopying files from globl to /etc..."
		fromdir=${BASEDIR}/PERIglobl/misc
		todir=/etc
for file in \
	vpsrc.sh vpsrc.csh
	do
		copyFileOnce
	done
/bin/echo "\nCopying files to /etc..."
		fromdir=${RELHOME}/${release}/misc
		todir=/etc
for file in \
	vpsback vpsrest vpspre53
	do
		copyFile
	done
}

vstat_cron () {
#if [ "$vps" -lt 256 ]; then
	#
	# Update system crontab to reflect vstat stuff.  We just call
	# an existing script
	#
	/bin/echo "\nUpdating crontab..."
	${VPSHOME}/bin/start_vstat.sh ${compno}
#fi
#
# Run the script to add the stats entry to periview.cfg if
# it exists.  We do this to end the confusion caused by
# installing a new release of VPS/is software when stats
# are already installed.
#
if [ -x $VPSHOME/common/stats/bin/update_periview.sh ]; then
	/bin/echo "\nUpdating periview.cfg..."
	$VPSHOME/common/stats/bin/update_periview.sh
	/bin/echo "\nUpdating Progress $comptp list..."
	curr_dir=`pwd`
	cd $VPSHOME/common/stats/bin
	sh ./bpro ../db/stats -p ins_vpsrec.p
	cd $curr_dir
fi
}

bootit () {
#
# Copy the ela boot image.
#
if [ ! -d /tftpboot ]; then
	/bin/echo "\nCreating /tftpboot directory"
	mkdir /tftpboot || terminate
fi
#if [ ${bootfile:-undef} != undef ]; then
/bin/echo "\nInstalling tftpboot"
for bf in $bootfile; do
	/bin/echo "\t${bf}"
	cp ${RELHOME}/${release}/images/${bf} /tftpboot || terminate
done
#fi
}

mmf_Dir () {
	if [ ! -d /mmf/peri ]; then
		mkdir -p /mmf/peri || terminate
		chmod 777 /mmf/peri
	fi
	mmfFiles="uscpd dtmf numset tdd"
	for file in $mmfFiles; do
	#
	# Uncompress and copy a file from the release misc to the common mmf.
	# As per mod #35, we can no longer assume that vocabs always come
	# in mm[di] pairs... it may be a vgen incremental.
	#
	# do copy instead of zcat, since input will be uncompressed
	if [ ! -f /mmf/peri/$file.mmd ]; then
                if [ -r ${RELHOME}/${release}/misc/${file}.Z ]; then
                        /bin/echo "\t${file}"
                        zcat ${RELHOME}/${release}/misc/${file}.Z > \
                                /mmf/peri/${file} || terminate
                else
                        if [ -r ${RELHOME}/${release}/misc/${file}.mmd.Z ]; then
                        /bin/echo "\t${file}.mmd"
                        zcat ${RELHOME}/${release}/misc/${file}.mmd.Z > \
                                /mmf/peri/${file}.mmd || terminate
                        /bin/echo "\t${file}.mmi"
                        zcat ${RELHOME}/${release}/misc/${file}.mmi.Z > \
                                /mmf/peri/${file}.mmi || terminate
           		else
                        if [ -r ${RELHOME}/${release}/misc/${file}.mmd ]; then
                        /bin/echo "\t${file}.mmd"
                                cp ${RELHOME}/${release}/misc/${file}.mmd /mmf/peri/${file}.mmd || terminate
                        /bin/echo "\t${file}.mmi"
                                cp ${RELHOME}/${release}/misc/${file}.mmi /mmf/peri/${file}.mmi || terminate
                        fi
			fi
                fi
        fi



#			/bin/echo "\t${file}.mmd"
#			cp ${RELHOME}/${release}/misc/${file}.mmd /mmf/peri || terminate
#			/bin/echo "\t${file}.mmi"
#			cp ${RELHOME}/${release}/misc/${file}.mmi /mmf/peri || terminate



		#if [ ! -r ${RELHOME}/${release}/misc/${file}.mmd.Z ]; then
		#	/bin/echo "\t${file}"
		#	zcat ${RELHOME}/${release}/misc/${file}.Z > \
		#		/mmf/peri/${file} || terminate
		#else
		#	/bin/echo "\t${file}.mmd"
		#	zcat ${RELHOME}/${release}/misc/${file}.mmd.Z > \
		#		/mmf/peri/${file}.mmd || terminate
		#	/bin/echo "\t${file}.mmi"
		#	zcat ${RELHOME}/${release}/misc/${file}.mmi.Z > \
		#		/mmf/peri/${file}.mmi || terminate
		#fi

	done
	chmod 777 /mmf
	chown -R peri /mmf
	chgrp -R peri /mmf
}

owin_icons () {
#
# Merge the cetables file so the file manager can know how to display
# our cool icons.  If the database exists, do a merge else a create.
#
ceFile=${CEPATH:-/etc/cetables/cetables}
if [ -f `echo $ceFile | sed "s/[^:]*:\([^:][^:]*\).*$/\1/"` ]; then
	/bin/echo "\nMerging file manager icon database"
	ceAction=merge
else
	/bin/echo "\nCreating file manager icon database"
	ceAction=build
fi
ceProgram=${OPENWINHOME}/bin/ce_db_$ceAction
$ceProgram system -from_ascii ${RELHOME}/${release}/misc/system_ascii \
	1> /dev/null 2>&1 || terminate

#
# Copy any icons we have into the default directory.
#
if [ ! -d ${VPSHOME}/fmIcons ]; then
	/bin/echo "\nCreating ${VPSHOME}/fmIcons directory"
	mkdir ${VPSHOME}/fmIcons || terminate
fi
/bin/echo "\nCopying icons to ${VPSHOME}/fmIcons directory"
cp ${RELHOME}/${release}/misc/*.32xbm ${VPSHOME}/fmIcons || terminate
}

charset () {
        # recover from special chars as first line, for instance 
	# a null line only being an enter or
        # who knows what
#       echo "Resetting char test on first line"
        cfg_lev=pre53
        }

add_svc_ports () {
/bin/echo "\nUpdating /etc/services"
for portdata in $svcports; do
        portno=`echo $portdata | cut -d: -f2`
        pname=`echo $portdata | cut -d: -f1`
        # check if port # is in services file, in use by another, and not
        # commented out
        portused=`/bin/awk '{ if ($2 == "'$portno'" && $1 != "'$pname'" && $1 !~ /^#/) { print $1 } }' /etc/services`
        if [ "${portused:-not}" = not ]; then
                # check if already added for peri's service
                portdone=`/bin/awk '{ if ($2 == "'$portno'" && $1 == "'$pname'" && $1 !~ /^#/) { print $1 } }' /etc/services`
                if [ "${portdone:-not}" = not ]; then
                        echo "updating /etc/services for $pname $portno"
                        printf '%s %16s %40s\n' $pname $portno "# Nortel Networks" >> /etc/services
                fi 
        else
                echo "/etc/services port $portno already in use by $portused"
                echo "$comptp services not completely installed"
                exit 1
        fi
done
}

upd_srp_cfg () {
        /bin/echo "\nUpdating $VPSHOME/common/etc/srp.cfg"
for srpdata in $srpcmd; do
        cmdl=`echo $srpdata | cut -d: -f1`
        cmdop=`echo $srpdata | cut -d: -f2`
        # check if command line is already set in srp.cfg
        # commented out
        cmdused=`/bin/awk '{ if ($1 == "'$cmdl'") { print $0 } }' $VPSHOME/common/etc/srp.cfg`
        if [ "${cmdused:-not}" = not ]; then
                # command line not used, add it
                echo "$cmdl 	= $cmdop" >> $VPSHOME/common/etc/srp.cfg
        else
                echo "$cmdl already set: $cmdused"
                echo "No update will occur."
                echo "Manual adjustment may be necessary for required: $cmdl = $cmdop"
        fi
done
}

updmenu () {
# remove dirname to force PATH resolution for differenced between 5.3 & prior
if [ -f /home/peri/.openwin-menu-periphonics ]; then
ed /home/peri/.openwin-menu-periphonics << _DONE >/dev/null
g/\$VPSHOME\/common\/rbin\//s//
w
q
_DONE
fi
}

#-------------------------------------------------------------------

# main part of script
. /etc/vpsrc.sh
#
# force BASEDIR to be /opt/vps for links to pkgs
BASEDIR=/opt/vps

if [ "${comptp:-undefined}" = "undefined" ]; then
        /bin/echo "mk[component] script needs to be run for env settings, what is the component type: \c"
        read comptp
        mkscript=`ls ${BASEDIR}/*/mk${comptp} 2>/dev/null | grep $comptp | tr "\012" " " | cut -d" "  -f1`
        if [ "${mkscript:-undefined}" = "undefined" ]; then
                #still undefined, no mkscript, exit
                mks=`ls ${BASEDIR}/*/mk*`
                /bin/echo " no  mk${comptp} found in \n$mks"
                echo exiting.....
                exit 1
        else
                #run the mk script
                . $mkscript
                exit
        fi
fi

if [ ${oldRelease:-undefined} = undefined ]; then
	# this component did not pass oldRelease, do not process
	# saving old stuff
	oldRelease=none
fi

#
# Get VPSHOME if it isn't already defined.
#
if [ ${VPSHOME:-undefined} = undefined ]; then
	if [ -f /etc/vpshome ]; then
		ans=`cat /etc/vpshome`
	else
		ans=`ckpath -a -y -d /opt/vps -p "MPS home directory"` || \
			exit $?
		echo $ans > /etc/vpshome
	fi
	if [ ! -d $ans ]; then
		mkdir $ans || exit $?
	fi
	VPSHOME=$ans
fi

#
# useful when VPSHOME is in another dir, such as /export in oscar component
# make vpsdir default to the BASEDIR 
#
if [ ${vpsdir:-undefined} = undefined ]; then
	vpsdir=$BASEDIR
fi

# 
# check for pre5.3 files, and save in case of rel5.3+ backout
#
if [ -f ${VPSHOME}/common/etc/vpshosts -a ! -f ${VPSHOME}/common/etc/vpshosts-pre53 ]; then
        read line_one < $VPSHOME/common/etc/vpshosts
        vpshost_lev=`echo $line_one | cut -c1,2 | grep $[1-9]` || charset
        if [ "${vpshost_lev:-pre53}" = pre53 ]; then
                echo "Saving vpshosts to ${VPSHOME}/common/etc/vpshosts-pre53"
                cp ${VPSHOME}/common/etc/vpshosts ${VPSHOME}/common/etc/vpshosts-pre53
        fi
fi
if [ -f ${VPSHOME}/common/etc/gen.cfg -a ! -f ${VPSHOME}/common/etc/gen.cfg-pre53 ]; then
        read line_one < $VPSHOME/common/etc/gen.cfg
        cfg_lev=`echo $line_one | cut -c1,2 | grep $[2-9]` || charset
        if [ "${cfg_lev:-pre53}" = pre53 ]; then
                echo "Saving gen.cfg to ${VPSHOME}/common/etc/gen.cfg-pre53"
                cp ${VPSHOME}/common/etc/gen.cfg ${VPSHOME}/common/etc/gen.cfg-pre53
        fi
fi
if [ -f ${VPSHOME}/common/etc/periview.cfg -a ! -f ${VPSHOME}/common/etc/periview.cfg-pre53 ]; then
	xpm=`grep stats.64xpm3 ${VPSHOME}/common/etc/periview.cfg`
	if [ "$xpm" != "" ]; then
	set $xpm
	if [ $# = 6 ]; then
		# old format (6 fields, not 7)
                echo "Saving periview.cfg to ${VPSHOME}/common/etc/periview.cfg-pre53"
                cp ${VPSHOME}/common/etc/periview.cfg ${VPSHOME}/common/etc/periview.cfg-pre53
        fi
	fi
fi
if [ -f ${VPSHOME}/vps${compno}/etc/cps.cfg -a ! -f ${VPSHOME}/vps${compno}/etc/cps.cfg-pre53 ]; then
                echo "Saving cps.cfg to ${VPSHOME}/vps${compno}/etc/cps.cfg-pre53"
                cp ${VPSHOME}/vps${compno}/etc/cps.cfg ${VPSHOME}/vps${compno}/etc/cps.cfg-pre53
fi
if [ -f ${VPSHOME}/vps${compno}/etc/vpsgroups -a ! -f ${VPSHOME}/vps${compno}/etc/vpsgroups-pre53 ]; then
                echo "Saving vpsgroups to ${VPSHOME}/vps${compno}/etc/vpsgroups-pre53"
                cp ${VPSHOME}/vps${compno}/etc/vpsgroups ${VPSHOME}/vps${compno}/etc/vpsgroups-pre53
fi
if [ -f ${VPSHOME}/common/etc/srp.cfg  -a ! -f ${VPSHOME}/common/etc/srp.cfg-pre53 ]; then
cfg_lev=`cat ${VPSHOME}/common/etc/srp.cfg | egrep 'componentStartupTimeout|swapLWM|swapHWM|diskLWM|diskHWM|statelog|vosFlushQueue'`
        if [ "${cfg_lev:-pre53}" = pre53 ]; then
                echo "Saving srp.cfg to ${VPSHOME}/common/etc/srp.cfg-pre53"
                cp ${VPSHOME}/common/etc/srp.cfg ${VPSHOME}/common/etc/srp.cfg-pre53
        fi
fi
if [ -f ${VPSHOME}/vps${compno}/etc/aseLines.cfg -a ! -f ${VPSHOME}/vps${compno}/etc/aseLines.cfg-pre53 ]; then
        read line_one < ${VPSHOME}/vps${compno}/etc/aseLines.cfg
        cfg_lev=`echo $line_one | cut -c1,2 | grep $[1-9]` || charset
        if [ "${cfg_lev:-pre53}" = pre53 ]; then
                echo "Saving aseLines.cfg to ${VPSHOME}/vps${compno}/etc/aseLines.cfg-pre53"
                cp ${VPSHOME}/vps${compno}/etc/aseLines.cfg ${VPSHOME}/vps${compno}/etc/aseLines.cfg-pre53
        fi
fi
if [ -f /etc/vpsrc.csh -a ! -f /etc/vpsrc.csh-pre53 ]; then
csh_lev=`cat /etc/vpsrc.csh | grep BASEDIR`
        if [ "${csh_lev:-pre53}" = pre53 ]; then
                echo "Saving vpsrc.csh to /etc/vpsrc.csh-pre53"
                cp /etc/vpsrc.csh /etc/vpsrc.csh-pre53
        fi
fi
if [ -f /etc/vpsrc.sh  -a ! -f /etc/vpsrc.sh-pre53 ]; then
sh_lev=`cat /etc/vpsrc.sh | grep BASEDIR`
        if [ "${sh_lev:-pre53}" = pre53 ]; then
                echo "Saving vpsrc.sh to /etc/vpsrc.sh-pre53"
                cp /etc/vpsrc.sh /etc/vpsrc.sh-pre53
        fi
fi

# determine if this needs a component dir to be processed
if [ $comptp != periview -a $comptp != globl -a $comptp != snmp ]; then
	# check of this is a component[n] update or new install
	# and define new or update
	if [ -d ${VPSHOME}/${comptp}${compno} ]; then
		cmpdir=update
	else
		cmpdir=new
	fi
else
	cmpdir=na
fi

if [ $comptp = vps ]; then
	# See if the patch directories are missing.
	# If so, fix the legacy release.
	#
	if [ $oldRelease != none -a ! -d ${RELHOME}/${oldRelease}/pbin ]; then
	        /bin/echo "\t${oldRelease}/pbin"
	        mkdir -p ${RELHOME}/${oldRelease}/pbin || terminate
	fi
	if [ $oldRelease != none -a ! -d ${RELHOME}/${oldRelease}/plib ]; then
	        /bin/echo "\t${oldRelease}/plib"
	        mkdir -p ${RELHOME}/${oldRelease}/plib || terminate
	fi
	if [ $oldRelease != none -a ! -d ${RELHOME}/${oldRelease}/pimages ]; then
	        /bin/echo "\t${oldRelease}/pimages"
	        mkdir -p ${RELHOME}/${oldRelease}/pimages || terminate
	fi
fi

if [ $cmpdir != na ]; then
#
# process component# dir 
# only for component types that require a component# dir
#
cd $VPSHOME
if [ $cmpdir = new ]; then
        case $comptp in
                oscar)
        vpsEtcFiles="ormif.cfg vos-links.cfg  srasio.cfg \
                vos.cfg extts-a01.cfg extts-a02.cfg extts-a00.cfg  \
                extts-a03.cfg extif0.cfg \
                extif1.cfg extif2.cfg extif3.cfg extif4.cfg extif5.cfg \
                extts-a04.cfg extts-a05.cfg \
		lvr-a00.cfg lvr-a01.cfg lvr-a02.cfg lvr-a03.cfg lvr-a04.cfg \
		lvr-a05.cfg lvr-a06.cfg lvr-a07.cfg lnuance.cfg"
        vpsDirs="$comptp etc apps log stats apps/lib data"
                ;;
		mts)
	vpsDirs="$comptp etc apps log stats apps/lib"
	vpsEtcFiles="dm_amp.cfg fad.cfg mtsm.cfg vos.cfg"
		;;
                tmscomm)
        vpsDirs="$comptp etc apps log stats apps/lib"
        vpsEtcFiles="vos.cfg"
                ;;
                *)
	vpsDirs="$comptp etc apps log stats apps/lib"
	vpsEtcFiles="compgroups vos-links.cfg \
		ase.cfg aseLines.cfg hardware.cfg \
		vos.cfg *.*.charset \"
		ase.cfg aseLines.cfg ccm_phoneline.cfg vmm.cfg vmm-mmf.cfg \
		tcad.cfg tcad-tms.cfg trip.cfg commgr.cfg ccm_admin.cfg faxmgr.cfg"
                ;;

#               atte.cfg commgr.cfg
#		vpstn3270.cfg snatermk fad.cfg mtsm.cfg cca_mgr.cfg \
#		vos.cfg cca_serv.cfg geotel.cfg *.*.charset"

        esac
else
        case $comptp in
                oscar)
        vpsEtcFiles="vos-links.cfg \
                vos.cfg extts-a01.cfg extts-a02.cfg extts-a00.cfg  \
		lvr-a00.cfg lvr-a01.cfg lvr-a02.cfg lvr-a03.cfg lvr-a04.cfg \
                lvr-a05.cfg lvr-a06.cfg lvr-a07.cfg \
                extts-a03.cfg extif0.cfg \
                extif1.cfg extif2.cfg extif3.cfg extif4.cfg extif5.cfg \
                extts-a04.cfg extts-a05.cfg lnuance.cfg"
        vpsDirs="$comptp etc apps log stats apps/lib data"
                ;;
		mts)
	vpsDirs="$comptp etc apps log stats apps/lib"
	vpsEtcFiles="dm_amp.cfg fad.cfg mtsm.cfg vos.cfg"
		;;
	        tmscomm)
        vpsDirs="etc apps log stats apps/lib"
        vpsEtcFilesOnce="vos.cfg"
                ;;
                *)
	vpsDirs="etc apps log stats apps/lib"
	vpsEtcFiles=
	vpsEtcFilesOnce="compgroups vos-links.cfg \
		ase.cfg aseLines.cfg hardware.cfg \
		vos.cfg *.*.charset \"
		ase.cfg aseLines.cfg ccm_phoneline.cfg vmm.cfg vmm-mmf.cfg \
		tcad.cfg tcad-tms.cfg trip.cfg commgr.cfg ccm_admin.cfg faxmgr.cfg"
                ;;
        esac

	#
	# Special fix for the renaming of the smp-load.cfg file.
	#
	if [ -f ${comptp}${compno}/etc/smp-load.cfg ]; then
		/bin/echo "Renaming smp-load.cfg as smp-mmf.cfg..."
		mv ${comptp}${compno}/etc/smp-load.cfg ${comptp}${compno}/etc/smp-mmf.cfg
	fi

	#
	# Delete old links
	#
	/bin/echo "\nRemoving old ${comptp}${compno} links..."
	if [ -h release.vps${compno} ]; then
		/bin/echo "\trelease.vps${compno}"
		rm -f release.vps${compno} || terminate
	fi
	if [ -h ${comptp}${compno}/rbin ]; then
		/bin/echo "\t${comptp}${compno}/rbin"
		rm -f ${comptp}${compno}/rbin || terminate
	fi
	if [ -h ${comptp}${compno}/bin ]; then
		/bin/echo "\t${comptp}${compno}/bin"
		rm -f ${comptp}${compno}/bin || terminate
	fi
	if [ -h ${comptp}${compno}/rlib ]; then
		/bin/echo "\t${comptp}${compno}/rlib"
		rm -f ${comptp}${compno}/rlib || terminate
	fi
	if [ -h ${comptp}${compno}/lib ]; then
		/bin/echo "\t${comptp}${compno}/lib"
		rm -f ${comptp}${compno}/lib || terminate
	fi
	if [ -h ${comptp}${compno}/rimages ]; then
		/bin/echo "\t${comptp}${compno}/rimages"
		rm -f ${comptp}${compno}/rimages || terminate
	fi
	if [ -h ${comptp}${compno}/images ]; then
		/bin/echo "\t${comptp}${compno}/images"
		rm -f ${comptp}${compno}/images || terminate
	fi
        # check for oscar things
##        if [ -h ${VPSHOME}/att_tt/bin ]; then
#          /bin/echo "\tatt_tt/bin"
#          rm -f ${VPSHOME}/att_tt/bin || terminate
#        fi
#        if [ -d ${VPSHOME}/att_tt/lib ]; then
#          /bin/echo "\tatt_tt/lib"
#          rm -rf ${VPSHOME}/att_tt/lib || terminate
#        fi
#        if [ -h ${VPSHOME}/nuance ]; then
#          /bin/echo "\tnuance"
#          rm -f ${VPSHOME}/nuance || terminate
#        fi
#        if [ -d ${VPSHOME}/nuance ]; then
#          /bin/echo "\tnuance"
#          rm -rf ${VPSHOME}/nuance || terminate
#        fi
fi

#
# Make component# directories
#
/bin/echo "\nMaking ${comptp}${compno} directories..."
for dir in $vpsDirs; do
	# if mps component was vps, rename
	if [ "$comptp" = "mps" -a -d $VPSHOME/vps$compno -a ! -d $VPSHOME/$comptp$compno ]; then
		#move the dir from vps to mps
		mv  -f $VPSHOME/vps$compno $VPSHOME/$comptp$compno
		# remove from vpshosts
		${VPSHOME}/bin/vhman -qd -c${compno} -tvps
		# update pmgr.cfg
		if [ -f $VPSHOME/common/etc/pmgr.cfg ]; then
			sed s/vps/mps/g $VPSHOME/common/etc/pmgr.cfg > /tmp/pmgrnew
			mv -f /tmp/pmgrnew $VPSHOME/common/etc/pmgr.cfg
		fi
	fi
	mkComponentDir
done

#
# Make component# log directory writable by world
#
for alldir in \
        log apps apps/lib
        do
	/bin/echo "Making ${comptp}${compno}/$alldir writable by world..."
		chmod 777 ${comptp}${compno}/$alldir || terminate
done

#
# no longer supporting releases in component dir..
#
/bin/echo "\nChecking/Removing ${comptp}${compno} patch directories..."
if [ -d ${comptp}${compno}/bin ]; then
	echo "${comptp}${compno}/bin"
	rm -rf ${comptp}${compno}/bin
fi
if [ -d ${comptp}${compno}/lib ]; then
	echo "${comptp}${compno}/lib"
	rm -rf ${comptp}${compno}/lib
fi
if [ -d ${comptp}${compno}/images ]; then
	echo "${comptp}${compno}/images"
	rm -rf ${comptp}${compno}/images
fi

#
# ...and links to patch directories.  If the 'pXXX' directories don't
# exist in the release, it means it's old, so we make them and copy
# any patched code there from the vps 'XXX' directory.
#
/bin/echo "\nChecking for/Updating vps${vps} patch directories..."
if [ -d vps${vps}/bin ]; then
        if [ $oldRelease != none -a -d ${RELHOME}/${oldRelease}/pbin ]; then
                mv -f vps${vps}/bin/* ${RELHOME}/${oldRelease}/pbin 2> /dev/null
        fi
        rm -rf vps${vps}/bin
fi       
if [ -d vps${vps}/lib ]; then
        if [ $oldRelease != none -a -d ${RELHOME}/${oldRelease}/plib ]; then
                mv -f vps${vps}/lib/* ${RELHOME}/${oldRelease}/plib 2> /dev/null
        fi
        rm -rf vps${vps}/lib
fi       
if [ -d vps${vps}/images ]; then
        if [ $oldRelease != none -a -d ${RELHOME}/${oldRelease}/pimages ]; then
                mv -f vps${vps}/images/* ${RELHOME}/${oldRelease}/pimages 2> /dev/null
        fi
        rm -rf vps${vps}/images
fi

#
# Copy files to component#/etc
#
/bin/echo "\nCopying files to ${comptp}${compno}/etc..."
fromdir=${RELHOME}/${release}/etc
todir=${VPSHOME}/${comptp}${compno}/etc
for file in $vpsEtcFiles; do
	copyFile
	if [ -f ${VPSHOME}/${comptp}${compno}/etc/$file ]; then
		chown peri ${VPSHOME}/${comptp}${compno}/etc/$file
		chgrp peri ${VPSHOME}/${comptp}${compno}/etc/$file
	fi
done
if [ -f ${VPSHOME}/${comptp}${compno}/etc/aseLines.cfg ]; then
	chmod 644 ${VPSHOME}/${comptp}${compno}/etc/aseLines.cfg
	chown root ${VPSHOME}/${comptp}${compno}/etc/aseLines.cfg
fi

for file in $vpsEtcFilesOnce; do
	copyVpsEtcFileOnce
done

#
# Change the owner of the VPS specific files to the peri user.
# update vos.cfg
case $comptp in
        oscar) compdirs="data log stats"
                ;;
        *) compdirs="apps log stats"
	#
	# Update the vos.cfg file based on the component number (only if this is
	# an initial install).
	#
#	if [ $cmpdir = new ]; then
#		modvps=`expr $compno % 16 + 39`
#		sed -e "s/~~/$modvps/" ${RELHOME}/${release}/etc/vos.cfg > \
#			${VPSHOME}/${comptp}${compno}/etc/vos.cfg
#	fi
                ;;
esac

fi		# if cmpdir not na

touch ${VPSHOME}/${comptp}${compno}/etc/${comptp}.info 2> /dev/null
chmod 777 ${VPSHOME}/${comptp}${compno}/etc/${comptp}.info 2> /dev/null
#
# Set up a good try at PATH and LD_LIBRARY_PATH so we can run
# some programs.  Also try to set up OPENWINHOME.
#
if [ ${PATH:-undefined} = undefined ]; then
	PATH=${RELHOME}/${release}/bin
else
	PATH="${PATH}:${RELHOME}/${release}/bin"
fi
export PATH
if [ ${LD_LIBRARY_PATH:-undefined} = undefined ]; then
	LD_LIBRARY_PATH=${RELHOME}/${release}/lib
else
	LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${RELHOME}/${release}/lib"
fi
export LD_LIBRARY_PATH
if [ ${OPENWINHOME:-undefined} = undefined ]; then
	OPENWINHOME=/usr/openwin
	export OPENWINHOME
fi


#-------------------------------------------------------------------

cd $VPSHOME

#
#  update common dir structure for old rels
if [ -h ${VPSHOME}/common/rbin ]; then
	rbinlink=`/bin/ls -al ${VPSHOME}/common/rbin | awk ' { print $11 } '`
old_commonReldir=`dirname $rbinlink`
if [ -d ${old_commonReldir} ]; then
        /bin/echo "\nMaking commonRelease patch directories..."
        #
        # Just like the vps release, we check for legacy common
        # releases that are missing the patch directories.
        #
        if [ ! -d ${old_commonReldir}/pbin ]; then
                /bin/echo "\t${old_commonReldir}/pbin"
                mkdir -p ${old_commonReldir}/pbin || terminate
        fi
        if [ ! -d ${old_commonReldir}/plib ]; then
                /bin/echo "\t${old_commonReldir}/plib"
                mkdir -p ${old_commonReldir}/plib || terminate
        fi
        if [ ! -d ${old_commonReldir}/pimages ]; then
                /bin/echo "\t${old_commonReldir}/pimages"
                mkdir -p ${old_commonReldir}/pimages || terminate
        fi
fi

#
# Copy all patch code to release patch directories.
#
if [ -d ${VPSHOME}/common/bin ]; then
        /bin/echo "\nBacking up old common/bin files..."
        /bin/mv -f ${VPSHOME}/common/bin/*  \
                ${old_commonReldir}/pbin 2> /dev/null
fi
if [ -d ${VPSHOME}/common/lib ]; then
        /bin/echo "\nBacking up old common/lib files..."
        /bin/mv -f ${VPSHOME}/common/lib/* \
 {old_commonReldir}/plib 2> /dev/null
fi
if [ -d ${comptp}${compno}/images ]; then
 	echo "\nBacking up old ${comptp}${compno}/images"
        mv -f ${comptp}${compno}/images/* \
                ${old_commonReldir}/pimages 2> /dev/null
fi       
# Remove common links and ase/sql/web dirs from old rels
/bin/echo "Checking/Removing old \"common\" links..."
if [ -h ${VPSHOME}/common/rbin ]; then
        /bin/echo "\tcommon/rbin"
        rm -f ${VPSHOME}/common/rbin || terminate
fi
if [ -h ${VPSHOME}/common/bin ]; then
        /bin/echo "\tcommon/bin"
        rm -f ${VPSHOME}/common/bin || terminate
fi
if [ -h ${VPSHOME}/common/rlib ]; then
        /bin/echo "\tcommon/rlib"
        rm -f ${VPSHOME}/common/rlib || terminate
fi
if [ -h ${VPSHOME}/common/lib ]; then
        /bin/echo "\tcommon/lib"
        rm -f ${VPSHOME}/common/lib || terminate
fi
if [ -h ${VPSHOME}/common/rimages ]; then
        /bin/echo "\tcommon/rimages"
        rm -f ${VPSHOME}/common/rimages || terminate
fi
if [ -h ${VPSHOME}/common/images ]; then
        /bin/echo "\tcommon/images"
        rm -f ${VPSHOME}/common/images || terminate
fi
if [ -d ${VPSHOME}/common/link ]; then
        /bin/echo "\tcommon/link"
        rm -rf ${VPSHOME}/common/link || terminate
fi
if [ -d ${VPSHOME}/common/web ]; then
        /bin/echo "\tcommon/web"
        rm -rf ${VPSHOME}/common/web || terminate
fi
if [ -d ${VPSHOME}/common/copy ]; then
        /bin/echo "\tcommon/copy"
        rm -rf ${VPSHOME}/common/copy || terminate
fi

fi # common rbin link
#
# add common stuff now.
case $comptp in
	snmp) commonDirs="etc/snmp"
		snmp_commonFilesOnce="mgr.cnf snmp.sh snmpd.cnf"
		snmp_commonFiles="snmpinfo.dat VRU_Networkv1.mib
		  VRU_Networkv2.mib Periphonicsv1.mib Periphonicsv2.mib"
		;;
	oscar) commonDirs="data log stats include etc etc/ents etc/snps \
		 etc/grps etc/info etc/images etc/packages zap"
		commonFilesOnce="srp.cfg orm.cfg vpshosts gen.cfg \
		global_users.cfg"
		;;
	globl) commonFiles="comptypes.cfg" ;;
	tmscomm) ;;
	*)
	commonIncludeFiles="devstat.h service.h vagprotocol.h vastimer.h ves.h \
		vram.h vvp.h symflags.h vapi.h venopts.h vpshosts.h vrcond.h \
		vvpproto.h"
	commonFiles="periview.cfg vrc.vrp api.vrp alarm.uts ptlimages.cfg"
	commonFilesOnce="mts_cli.cfg ase.conf \
		 srp.cfg orm.cfg vpshosts gen.cfg \
		 snatext \
		 global_users.cfg"
#		tn3270-default.2host.charset tn3270-default.2local.charset \

	commonRelease=none
	commonImageFiles="*.*x*"
#	commonImageFiles="vps_up.32xpm3 vps_down.32xpm3 vps_unreach.32xpm3 \
#		appman.64xpm monitor.64xpm alrmview.64xpm \
#		vshtool.64xpm sched.64xpm peristudio.64xpm pproi.64xpm \
#		filexfer.64xpm spin.64xpm onlinedoc.64xpm \
#		periwwword.64xpm perisql.64xpm \
#	expand_vpss_drop.48xpm3 vps_doc.48xpm3 vps_up.16xpm3 vps_down.16xpm3 \
#	vps_unreach.16xpm3 vps_doc.64xbm vas_up.32xpm3 vas_down.32xpm3 \
#	vas_unreach.32xpm3 expand_vass_drop.48xpm3 vas_doc.48xpm3 \
# vas_up.16xpm3 vas_down.16xpm3 vas_unreach.16xpm3 vas_nostate.16xpm3 \
# vas_doc.64xbm oscar_up.32xpm3 oscar_down.32xpm3 oscar_unreach.32xpm3 \ 
# expand_oscars_drop.48xpm3 oscar_doc.48xpm3 oscar_up.16xpm3 oscar_down.16xpm3 \
# oscar_unreach.16xpm3 oscar_doc.64xbm mts_up.32xpm3 mts_down.32xpm3 \
# mts_unreach.32xpm3 expand_mtss_drop.48xpm3 mts_doc.48xpm3 mts_up.16xpm3 \
# mts_down.16xpm3 mts_unreach.16xpm3 mts_doc.64xbm c7_up.32xpm3 c7_down.32xpm3 \
# c7_unreach.32xpm3 expand_c7s_drop.48xpm3 c7_doc.48xpm3 c7_up.16xpm3 \
# c7_down.16xpm3 c7_unreach.16xpm3 c7_doc.64xbm node_up.32xpm3 node_down.32xpm3 \
# node_unreach.32xpm3 expand_nodes_drop.48xpm3 node_doc.48xpm3 node_up.16xpm3 \
# node_down.16xpm3 node_unreach.16xpm3 node_doc.64xbm group_up.32xpm3 \
# group_down.32xpm3 group_unreach.32xpm3 expand_group_drop.48xpm3 \
# group_doc.48xpm3 \
# group_up.16xpm3 group_down.16xpm3 group_unreach.16xpm3 group_doc.64xbm \
# go_up.32xpm3 go_down.32xpm3 go_unreach.32xpm3 go_doc.48xpm3 go_up.16xpm3 \
# go_down.16xpm3 go_unreach.16xpm3 go_doc.64xbm ent_doc.48xpm3 \
# ent_doc.64xbm vps_vas_up.32xpm3 vps_vas_down.32xpm3 vps_vas_unreach.32xpm3
# collapse_drop.48xpm3 expand_res_drop.48xpm3 app_ppro_config.32xpm3 \
# app_ppro_config_run.32xpm3 vas_app.32xpm3 expand_app_configs_drop.48xpm3 \
# admin_app_blank.16xpm3 admin_app.16xpm3 admin_app_run.16xpm3 \
# old_blue_phone_blank.16xpm3 old_blue_phone.16xpm3 old_blue_phone_run.16xpm3 \
#	periLogo_up.32xpm3 periLogo_down.32xpm3 periLogo_unreach.32xpm3 \
# ctxcomm_up.32xpm3 ctxcomm_down.32xpm3 ctxcomm_unreach.32xpm3 expand_ctxcomms_drop.48xpm3 \
# ctxcomm_doc.48xpm3 ctxcomm_up.16xpm3 ctxcomm_down.16xpm3 ctxcomm_unreach.16xpm3 \
# ctxcomm_doc.64xbm"
		;;

esac

#
# Make common directories
#
/bin/echo "\nChecking/Making \"common\" directories..."
for dir in $commonDirs; do
	makeCommonDir
done
touch $VPSHOME/common/etc/node.info
chmod 777 $VPSHOME/common/etc/node.info

#
# Make common log directory writable by world
#
/bin/echo "Making common/log writable by world..."
chmod 777 ${VPSHOME}/common/log || terminate

#       
# 
# Create a link to the release
#
case $comptp in
	oscar) if [ ! -h ${VPSHOME}/PERImps -a "${VPSHOME}" != "/opt/oscar" ]; then 
		# establish PERImps link on diskless oscar client
			/bin/echo "\tPERImps -> ${vpsdir}/PERImps"
			ln -s ${vpsdir}/PERImps  ${VPSHOME}/PERImps || terminate 
		fi
		if [ -h ${VPSHOME}/PERIoscar ]; then
			echo "upgrading PERIoscar link"
			rm -f ${VPSHOME}/PERIoscar || terminate
		fi
		if [ ! -h ${VPSHOME}/PERIoscar -a -d ${RELHOME}/${release} ]; then
			/bin/echo "\tPERIoscar -> ${RELHOME}/${release}"
			ln -s ${RELHOME}/${release} ${VPSHOME}/PERIoscar || terminate 
		fi
		if [ ! -h ${VPSHOME}/PERIglobl ]; then 
		# establish PERIglobl link
			/bin/echo "\tPERIglobl -> ${BASEDIR}/PERIglobl"
			ln -s ${BASEDIR}/PERIglobl  ${VPSHOME}/PERIglobl || terminate 
		fi
		;;
#	vps|periview|vas) if [ -h ${BASEDIR}/PERIvps -o -h ${BASEDIR}/PERIvps ]; then
	periview|vas) if [ -h ${BASEDIR}/PERImps -o -h ${BASEDIR}/PERImps ]; then
			echo "removing old PERImps link"
			rm -f ${BASEDIR}/PERImps || terminate
		fi
		if [ ! -h ${BASEDIR}/PERImps ]; then 
			/bin/echo "\tUpgrading link: PERImps -> ${RELHOME}/${release}"
			ln -s ${RELHOME}/${release} ${BASEDIR}/PERImps || terminate 
		fi
		;;
#        mps) if [ -h ${BASEDIR}/PERImps -o -h ${BASEDIR}/PERImps ]; then
  #      vps) if [ -h ${BASEDIR}/PERImps -o -h ${BASEDIR}/PERImps ]; then
        vps|mps) if [ -h ${BASEDIR}/PERImps -o -h ${BASEDIR}/PERImps ]; then
                        echo "removing old PERImps link"
                        rm -f ${BASEDIR}/PERImps || terminate
                fi
                if [ ! -h ${BASEDIR}/PERImps ]; then
                        /bin/echo "\tUpgrading link: PERImps -> ${RELHOME}/${release}"
                        ln -s ${RELHOME}/${release} ${BASEDIR}/PERImps || terminate
                fi
                ;;
	*)
		;;
esac

#
# Copy files to common
#
if [ "${commonFiles:-undefined}" != undefined ]; then
	/bin/echo "\nChecking/Copying files to common/etc..."
	fromdir=${RELHOME}/${release}/etc
	todir=${VPSHOME}/common/etc
	for file in $commonFiles; do
		copyFile
		# if it was never copied and is in globl distribution, get it from there
		if [ ! -f ${VPSHOME}/common/etc/$file -a -f ${BASEDIR}/PERIglobl/etc/$file ]; then
		/bin/echo "\t$file not found. copying from PERIglobl"
		cp ${BASEDIR}/PERIglobl/etc/$file ${todir} || terminate
		fi
	done
fi
if [ "${commonFilesOnce:-undefined}" != undefined ]; then
	fromdir=${RELHOME}/${release}/etc
	todir=${VPSHOME}/common/etc
	for file in $commonFilesOnce; do
		copyFileOnce
		if [ ! -f ${VPSHOME}/common/etc/$file -a -f ${BASEDIR}/PERIglobl/etc/$file ]; then
		/bin/echo "\t$file not found. copying from PERIglobl"
		cp ${BASEDIR}/PERIglobl/etc/$file ${todir} || terminate
		fi
	done
fi
if [ -f $VPSHOME/common/etc/global_users.cfg ]; then
	chmod 644 $VPSHOME/common/etc/global_users.cfg
	chown root $VPSHOME/common/etc/global_users.cfg
fi

# snmp common
if [ "${snmp_commonFiles:-undefined}" != undefined ]; then
        /bin/echo "\nChecking/Copying files to common/etc/snmp..."
        fromdir=${RELHOME}/${release}/etc
        todir=${VPSHOME}/common/etc/snmp
        for file in $snmp_commonFiles; do
                copyFile 
        done
fi
if [ "${snmp_commonFilesOnce:-undefined}" != undefined ]; then
        fromdir=${RELHOME}/${release}/etc
        todir=${VPSHOME}/common/etc/snmp
        for file in $snmp_commonFilesOnce; do 
                copyFileOnce
        done
fi

#
# Copy files to common/include
#

if [ "${commonIncludeFiles:-undefined}" != undefined ]; then
	/bin/echo "\nChecking/Copying files to common/include..."
	fromdir=${RELHOME}/${release}/misc
	todir=${VPSHOME}/common/include
	for file in $commonIncludeFiles; do
		copyFile
	done
fi

#
# COpy files to common/etc/images
#
        if [ "${commonImageFiles:-undefined}" != undefined ]; then
                /bin/echo "\nChecking/Copying files to common/etc/images..."
	fromdir=${RELHOME}/${release}/etc/images
	todir=${VPSHOME}/common/etc/images
                for file in $commonImageFiles; do
                        copyFile
                done
        fi
	
#
# depending on component type....
#
case $comptp in
	oscar)
		svcports="srpvtdb:5998/tcp srpnonvtdb:5999/tcp tmslrm:30000/tcp tmsadsm:30001/tcp tmssim:30002/tcp tmsvmem:30003/tcp"
		add_svc_ports
		vps_sys_etc
		srpcmd="runawayLimit:65535"
		upd_srp_cfg
		if [ "$diskless" != "yes" ]; then
			new_alm
			startfile=S20oscar.startup
	        	if [ -f ${RELHOME}/${release}/etc/srasio.tbl ]; then
	                	/bin/echo "\n${VPSHOME}/common/etc/srasio.tbl"
		                cp ${RELHOME}/${release}/etc/srasio.tbl ${VPSHOME}/common/etc || terminate
		        fi
		        if [ ! -d /$VPSHOME/common/mmf ]; then
				mkdir $VPSHOME/common/mmf
		        fi
			oscar_mmf="oscar.mmi oscar.mmd"
			for mfile in $oscar_mmf; do
	        	if [ -f ${RELHOME}/${release}/misc/$mfile -a ! -f ${VPSHOME}/common/mmf/$mfile ]; then
		                /bin/echo "\n${VPSHOME}/common/mmf/$mfile"
		                cp ${RELHOME}/${release}/misc/$mfile ${VPSHOME}/common/mmf || terminate
			fi
			done
		fi
		;;
	vps|mps)
		mmf_Dir
		vps_sys_etc
#		bootfile="elasys"
		bootit
		new_alm
		vstat_cron
		do_vhman
#		owin_icons
		svcports="rcd:5888/tcd srpregistry:5997/tcp srpvtdb:5998/tcp srpnonvtdb:5999/tcp tmslrm:30000/tcp tmsadsm:30001/tcp tmssim:30002/tcp tmsvmem:30003/tcp"
		add_svc_ports
		;;
	snmp)
		svcports="snmp:161/udp snmp-trap:162/udp"
		add_svc_ports
		;;
	mts)
		vps_sys_etc
		new_alm
		;;
	tmscomm)
                do_vhman
                ;;
	v*)
		mmf_Dir
		vps_sys_etc
		new_alm
#		bootfile="elasys"
		bootit
		do_vhman
#		owin_icons
		svcports="srpvtdb:5998/tcp srpnonvtdb:5999/tcp tmslrm:30000/tcp tmsadsm:30001/tcp tmssim:30002/tcp tmsvmem:30003/tcp"
		add_svc_ports
		;;
	*) ;;
esac

#
# Set up our stuff in the real /etc.
#
if [ ! -f /etc/vpshome ]; then
	/bin/echo "\nInstalling /etc/vpshome"
	echo ${VPSHOME} > /etc/vpshome || terminate
fi

if [ $cmpdir = new ]; then
	chown -R peri ${VPSHOME}/common
	chgrp -R peri ${VPSHOME}/common
	chmod 755 ${VPSHOME}/common/etc
	chown root ${VPSHOME}/common/etc
fi
if [ -f $VPSHOME/common/etc/global_users.cfg ]; then
	chmod 644 $VPSHOME/common/etc/global_users.cfg
	chown root $VPSHOME/common/etc/global_users.cfg
fi
#
# Copy the rc3.d startup file if if doesn't exist.
#
if [ ${startfile:-undef} != undef ]; then
	/bin/echo "\nInstalling $comptp startup file: /etc/rc3.d/$startfile"
	cp ${RELHOME}/${release}/misc/$startfile /etc/rc3.d || terminate
	chmod 744 /etc/rc3.d/$startfile || terminate
	chgrp sys /etc/rc3.d/$startfile  || terminate
fi

# update openwin-menu stuff to rely on PATH env.
updmenu

#
# check if Xsetup has been updated for new alrmview path
#
if [ -f /usr/openwin/lib/xdm/Xsetup_0 ]; then
X53upd=`cat /usr/openwin/lib/xdm/Xsetup_0 | grep rel5.3:alrmview`
if [ "$X53upd" = "" ]; then
ed /usr/openwin/lib/xdm/Xsetup_0  << END > /dev/null
/VPSHOME
+3
i

# rel5.3:alrmview and up
if [ \${VPSHOME:-undef} != "undef" -a \${srpIsUp} -ne 0 -a -f /opt/vps/bin/alrmview ]; then
        alrmview -n -Wp 10 350 -Ws 700 370 -WP 955 266 -Wi &
fi
.
w
q
END
fi
else
	echo "=============================WARNING==========================="
	echo "=============================WARNING==========================="
	echo "/usr/openwin/lib/xdm/Xsetup_0 not found"
	echo "alrmview console display unpredictable"
	echo "=============================WARNING==========================="
	echo "=============================WARNING==========================="
fi

#-------------------------------------------------------------------

echo $comptp configuration complete
