1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21 #
22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
24 #
25
26 ONLDCPIO=/tmp/SUNWonld.cpio.$$
27
28
29 #
30 # This script handles the installation of the new sgstools on
31 # both Solaris10 systems (which libraries moved to '/lib') and
32 # pre Solaris10 systems where libraries reside under '/usr/lib'.
33 #
34 # We test to deterine if '/lib' is a symlink (pre Solaris10) or a
35 # directory (Solaris10 & later). We key off of that for
36 # everything below.
37 #
38 if [ -h ${BASEDIR}/lib ]
39 then
40 LIBBASE=usr/lib
41 ETCLIST="etc/lib/ld.so.1 etc/lib/libdl.so.1"
42 else
43 LIBBASE=lib
44 fi
45 export LIBBASE
46
47
48 build_liblist ()
49 {
50 #
51 # Build '/lib' file list for backing up
52 #
53 cd $BASEDIR/$SGSDIR/lib
54 find . \( -type f -o -type l \) -print | sed 's/^\.\///'g |
55 while read file
56 do
57 if [ \( -f $BASEDIR/$LIBBASE/$file \) -o \
58 \( -h $BASEDIR/$LIBBASE/$file \) ]; then
59 echo $LIBBASE/$file
60 fi
61 done
62 }
63
64 build_filelist()
65 {
66 #
67 # Build rest of files
68 #
69 cd $BASEDIR/$SGSDIR
70 find usr \( -type f -o -type l \) -print | while read file
71 do
72 if [ \( -f $BASEDIR/$file \) -o \
73 \( -h $BASEDIR/$file \) ]; then
74 echo $file
75 fi
76 done
77 }
78
79 build_newitemsfile ()
80 {
81 rm -f ${SGSBACKUPDIR}.newfiles
82
83 # Build a list of files/directories that this package is going
84 # add to the system that do not already exist.
85 cd $BASEDIR/$SGSDIR/lib
86 find . -depth -print | sed 's/^\.\///'g | while read file
87 do
88 # Built in /bin/sh test lacks -e
89 /usr/bin/test \! -e "$BASEDIR/$LIBBASE/$file"
90 if [ $? = 0 ]; then
91 echo $LIBBASE/$file >> ${SGSBACKUPDIR}.newfiles
92 fi
93 done
94
95 cd $BASEDIR/$SGSDIR
96 find usr -depth -print | while read file
97 do
98 /usr/bin/test \! -e "$BASEDIR/$file"
99 if [ $? = 0 ]; then
100 echo $file >> ${SGSBACKUPDIR}.newfiles
101 fi
102 done
103 }
104
105 # Generate a file containing the names of the files and directories
106 # that are being added (as opposed to being replaced) to the system.
107 # These items will need to be explicitly removed at uninstall.
108 build_newitemsfile
109
110 # Generate a file containing the names of the original files backed
111 # up from the system. These items will be moved back at uninstall.
112 LIBLIST=`build_liblist`
113 FILELIST=`build_filelist`
114 for file in $LIBLIST $FILELIST $ETCLIST
115 do
116 echo $file
117 done > ${SGSBACKUPDIR}.origfiles
118
119 #
120 # backup all existing SGStools.
121 #
122 echo "Backup up existing SGS tools to $SGSBACKUPDIR..."
123 cd $BASEDIR
124 cpio -pdm $BASEDIR/$SGSBACKUPDIR < ${SGSBACKUPDIR}.origfiles
125
126
127 #
128 # Overwrite SGSTOOLS onto existing system. We use CPIO
129 # because it unlinks a file and then creates a new one
130 # instead of copying over an existing inode. This is
131 # required when updating libraries (and the run-time linker)
132 # which are currently being used.
133 #
134
135
136 #
137 # First '/lib' components
138 #
139 echo "Installing new SGSTOOLS from $BASEDIR/$SGSDIR"
140
141 prev_bindnow=$LD_BIND_NOW
142 LD_BIND_NOW=1
143 export LD_BIND_NOW
144
145 cd $BASEDIR/$SGSDIR/lib
146 find . -depth -print | cpio -o -O $ONLDCPIO
147 cd $BASEDIR/$LIBBASE
148 cpio -imdu < $ONLDCPIO
149 rm -f $ONLDCPIO
150
151 #
152 # Then everything else
153 #
154 cd $BASEDIR/$SGSDIR
155 find usr -depth -print | cpio -o -O $ONLDCPIO
156 cd $BASEDIR
157 cpio -imdu < $ONLDCPIO
158 rm -f $ONLDCPIO
159
160
161 #
162 # Populate '/etc/lib' directories on systems with the
163 # run-time linker installed under '/usr/lib/ld.so.1'
164 #
165 if [ "${ETCLIST}x" != "x" ]; then
166 cp $BASEDIR/usr/lib/ld.so.1 $BASEDIR/etc/lib/ld.so.1.onld
167 cp $BASEDIR/usr/lib/libdl.so.1 $BASEDIR/etc/lib/libdl.so.1.onld
168 cd $BASEDIR/etc/lib
169 mv ld.so.1.onld ld.so.1
170 mv libdl.so.1.onld libdl.so.1
171 fi
172
173 LD_BIND_NOW=$prev_bindnow