xref: /titanic_44/usr/src/cmd/sgs/packages/common/postinstall (revision 40e53e878049f6e18b3653b3c61e9e03e7f00cb1)
17c478bd9Sstevel@tonic-gate#
27c478bd9Sstevel@tonic-gate# CDDL HEADER START
37c478bd9Sstevel@tonic-gate#
47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
5ba4e3c84Sab196087# Common Development and Distribution License (the "License").
6ba4e3c84Sab196087# You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate#
87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate# and limitations under the License.
127c478bd9Sstevel@tonic-gate#
137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate#
197c478bd9Sstevel@tonic-gate# CDDL HEADER END
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate#
22*40e53e87SAli Bahrami# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate# Use is subject to license terms.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gateONLDCPIO=/tmp/SUNWonld.cpio.$$
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate# This script handles the installation of the new sgstools on
317c478bd9Sstevel@tonic-gate# both Solaris10 systems (which libraries moved to '/lib') and
327c478bd9Sstevel@tonic-gate# pre Solaris10 systems where libraries reside under '/usr/lib'.
337c478bd9Sstevel@tonic-gate#
347c478bd9Sstevel@tonic-gate# We test to deterine if '/lib' is a symlink (pre Solaris10) or a
357c478bd9Sstevel@tonic-gate# directory (Solaris10 & later).  We key off of that for
367c478bd9Sstevel@tonic-gate# everything below.
377c478bd9Sstevel@tonic-gate#
387c478bd9Sstevel@tonic-gateif [ -h ${BASEDIR}/lib ]
397c478bd9Sstevel@tonic-gatethen
407c478bd9Sstevel@tonic-gate	LIBBASE=usr/lib
417c478bd9Sstevel@tonic-gate	ETCLIST="etc/lib/ld.so.1 etc/lib/libdl.so.1"
427c478bd9Sstevel@tonic-gateelse
437c478bd9Sstevel@tonic-gate	LIBBASE=lib
447c478bd9Sstevel@tonic-gatefi
457c478bd9Sstevel@tonic-gateexport LIBBASE
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gatebuild_liblist ()
497c478bd9Sstevel@tonic-gate{
507c478bd9Sstevel@tonic-gate	#
517c478bd9Sstevel@tonic-gate	# Build '/lib' file list for backing up
527c478bd9Sstevel@tonic-gate	#
537c478bd9Sstevel@tonic-gate	cd $BASEDIR/$SGSDIR/lib
54*40e53e87SAli Bahrami	find . \( -type f -o -type l \) -print | sed 's/^\.\///'g |
55*40e53e87SAli Bahrami	while read file
567c478bd9Sstevel@tonic-gate	do
577c478bd9Sstevel@tonic-gate		if [ \( -f $BASEDIR/$LIBBASE/$file \)  -o \
587c478bd9Sstevel@tonic-gate		    \( -h $BASEDIR/$LIBBASE/$file \) ]; then
597c478bd9Sstevel@tonic-gate			echo $LIBBASE/$file
607c478bd9Sstevel@tonic-gate		fi
617c478bd9Sstevel@tonic-gate	done
627c478bd9Sstevel@tonic-gate}
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gatebuild_filelist()
657c478bd9Sstevel@tonic-gate{
667c478bd9Sstevel@tonic-gate	#
677c478bd9Sstevel@tonic-gate	# Build rest of files
687c478bd9Sstevel@tonic-gate	#
697c478bd9Sstevel@tonic-gate	cd $BASEDIR/$SGSDIR
707c478bd9Sstevel@tonic-gate	find usr \( -type f -o -type l \) -print | while read file
717c478bd9Sstevel@tonic-gate	do
727c478bd9Sstevel@tonic-gate		if [ \( -f $BASEDIR/$file \)  -o \
737c478bd9Sstevel@tonic-gate		    \( -h $BASEDIR/$file \) ]; then
747c478bd9Sstevel@tonic-gate			echo $file
757c478bd9Sstevel@tonic-gate		fi
767c478bd9Sstevel@tonic-gate	done
777c478bd9Sstevel@tonic-gate}
787c478bd9Sstevel@tonic-gate
794fa4b40cSab196087build_newitemsfile ()
804fa4b40cSab196087{
814fa4b40cSab196087	rm -f ${SGSBACKUPDIR}.newfiles
824fa4b40cSab196087
834fa4b40cSab196087	# Build a list of files/directories that this package is going
844fa4b40cSab196087	# add to the system that do not already exist.
854fa4b40cSab196087	cd $BASEDIR/$SGSDIR/lib
86*40e53e87SAli Bahrami	find . -depth -print | sed 's/^\.\///'g | while read file
874fa4b40cSab196087	do
884fa4b40cSab196087		# Built in /bin/sh test lacks -e
894fa4b40cSab196087		/usr/bin/test \! -e "$BASEDIR/$LIBBASE/$file"
904fa4b40cSab196087		if [ $? = 0 ]; then
914fa4b40cSab196087			echo $LIBBASE/$file >> ${SGSBACKUPDIR}.newfiles
924fa4b40cSab196087		fi
934fa4b40cSab196087	done
944fa4b40cSab196087
954fa4b40cSab196087	cd $BASEDIR/$SGSDIR
964fa4b40cSab196087	find usr -depth -print | while read file
974fa4b40cSab196087	do
984fa4b40cSab196087		/usr/bin/test \! -e "$BASEDIR/$file"
994fa4b40cSab196087		if [ $? = 0 ]; then
1004fa4b40cSab196087			echo $file >> ${SGSBACKUPDIR}.newfiles
1014fa4b40cSab196087		fi
1024fa4b40cSab196087	done
1034fa4b40cSab196087}
1044fa4b40cSab196087
1054fa4b40cSab196087# Generate a file containing the names of the files and directories
1064fa4b40cSab196087# that are being added (as opposed to being replaced) to the system.
1074fa4b40cSab196087# These items will need to be explicitly removed at uninstall.
1084fa4b40cSab196087build_newitemsfile
1094fa4b40cSab196087
110*40e53e87SAli Bahrami# Generate a file containing the names of the original files backed
111*40e53e87SAli Bahrami# up from the system. These items will be moved back at uninstall.
112*40e53e87SAli BahramiLIBLIST=`build_liblist`
113*40e53e87SAli BahramiFILELIST=`build_filelist`
114*40e53e87SAli Bahramifor file in $LIBLIST $FILELIST $ETCLIST
115*40e53e87SAli Bahramido
116*40e53e87SAli Bahrami	echo $file
117*40e53e87SAli Bahramidone > ${SGSBACKUPDIR}.origfiles
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate#
1207c478bd9Sstevel@tonic-gate# backup all existing SGStools.
1217c478bd9Sstevel@tonic-gate#
1227c478bd9Sstevel@tonic-gateecho "Backup up existing SGS tools to $SGSBACKUPDIR..."
1237c478bd9Sstevel@tonic-gatecd $BASEDIR
124*40e53e87SAli Bahramicpio -pdm $BASEDIR/$SGSBACKUPDIR < ${SGSBACKUPDIR}.origfiles
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate#
1287c478bd9Sstevel@tonic-gate# Overwrite SGSTOOLS onto existing system.  We use CPIO
129*40e53e87SAli Bahrami# because it unlinks a file and then creates a new one
130*40e53e87SAli Bahrami# instead of copying over an existing inode.  This is
1317c478bd9Sstevel@tonic-gate# required when updating libraries (and the run-time linker)
1327c478bd9Sstevel@tonic-gate# which are currently being used.
1337c478bd9Sstevel@tonic-gate#
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate#
1377c478bd9Sstevel@tonic-gate# First '/lib' components
1387c478bd9Sstevel@tonic-gate#
1397c478bd9Sstevel@tonic-gateecho "Installing new SGSTOOLS from $BASEDIR/$SGSDIR"
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gateprev_bindnow=$LD_BIND_NOW
1427c478bd9Sstevel@tonic-gateLD_BIND_NOW=1
1437c478bd9Sstevel@tonic-gateexport LD_BIND_NOW
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gatecd $BASEDIR/$SGSDIR/lib
1467c478bd9Sstevel@tonic-gatefind . -depth -print | cpio -o -O $ONLDCPIO
1477c478bd9Sstevel@tonic-gatecd $BASEDIR/$LIBBASE
1487c478bd9Sstevel@tonic-gatecpio -imdu < $ONLDCPIO
1497c478bd9Sstevel@tonic-gaterm -f $ONLDCPIO
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate#
1527c478bd9Sstevel@tonic-gate# Then everything else
1537c478bd9Sstevel@tonic-gate#
1547c478bd9Sstevel@tonic-gatecd $BASEDIR/$SGSDIR
1557c478bd9Sstevel@tonic-gatefind usr -depth -print | cpio -o -O $ONLDCPIO
1567c478bd9Sstevel@tonic-gatecd $BASEDIR
1577c478bd9Sstevel@tonic-gatecpio -imdu < $ONLDCPIO
1587c478bd9Sstevel@tonic-gaterm -f $ONLDCPIO
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate#
1627c478bd9Sstevel@tonic-gate# Populate '/etc/lib' directories on systems with the
1637c478bd9Sstevel@tonic-gate# run-time linker installed under '/usr/lib/ld.so.1'
1647c478bd9Sstevel@tonic-gate#
1657c478bd9Sstevel@tonic-gateif [ "${ETCLIST}x" != "x" ]; then
1667c478bd9Sstevel@tonic-gate	cp $BASEDIR/usr/lib/ld.so.1 $BASEDIR/etc/lib/ld.so.1.onld
1677c478bd9Sstevel@tonic-gate	cp $BASEDIR/usr/lib/libdl.so.1 $BASEDIR/etc/lib/libdl.so.1.onld
1687c478bd9Sstevel@tonic-gate	cd $BASEDIR/etc/lib
1697c478bd9Sstevel@tonic-gate	mv ld.so.1.onld ld.so.1
1707c478bd9Sstevel@tonic-gate	mv libdl.so.1.onld libdl.so.1
1717c478bd9Sstevel@tonic-gatefi
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gateLD_BIND_NOW=$prev_bindnow
174