Home | History | Annotate | Download | only in scripts
      1 #! /usr/bin/ksh -p
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 
     23 #
     24 # Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # Create an encumbered binaries tarball from a full build proto area,
     28 # less the contents of an OpenSolaris proto area.  Special handling
     29 # for crypto binaries that need to be signed by Sun Release
     30 # Engineering.
     31 #
     32 
     33 usage="bindrop [-n] full-root open-root basename"
     34 
     35 isa=`uname -p`
     36 
     37 PATH="$PATH:/usr/bin:/usr/sfw/bin"
     38 
     39 function fail {
     40 	print -u2 "bindrop: $@"
     41 	exit 1
     42 }
     43 
     44 function warn {
     45 	print -u2 "bindrop: warning: $@"
     46 }
     47 
     48 [[ -n "$SRC" ]] || fail "SRC must be set."
     49 [[ -n "$CODEMGR_WS" ]] || fail "CODEMGR_WS must be set."
     50 
     51 #
     52 # Create the README from boilerplate and the contents of the closed
     53 # binary tree.
     54 #
     55 # usage: mkreadme targetdir
     56 #
     57 function mkreadme {
     58 	typeset targetdir="$1"
     59 	typeset readme="README.ON-BINARIES.$isa"
     60 
     61 	sed -e s/@ISA@/$isa/ -e s/@DELIVERY@/ON-BINARIES/ \
     62 	    "$SRC/tools/opensolaris/README.binaries.tmpl" > "$targetdir/$readme"
     63 	(cd "$targetdir"; find "$rootdir" -type f -print | \
     64 	    sort >> "$targetdir/$readme")
     65 }
     66 
     67 nondebug=n
     68 while getopts n flag; do
     69 	case $flag in
     70 	n)
     71 		nondebug=y
     72 		;;
     73 	?)
     74 		print -u2 "usage: $usage"
     75 		exit 1
     76 		;;
     77 	esac
     78 done
     79 shift $(($OPTIND - 1))
     80 
     81 if [[ $# -ne 3 ]]; then
     82 	print -u2 "usage: $usage"
     83 	exit 1
     84 fi
     85 
     86 full="$1"
     87 open="$2"
     88 tarfile="$CODEMGR_WS/$3.$isa.tar"
     89 
     90 rootdir="root_$isa"
     91 if [[ "$nondebug" = y ]]; then
     92 	rootdir="root_$isa-nd"
     93 fi
     94 
     95 [[ -d "$full" ]] || fail "can't find $full."
     96 [[ -d "$open" ]] || fail "can't find $open."
     97 
     98 tmpdir=$(mktemp -dt bindropXXXXX)
     99 [[ -n "$tmpdir" ]] || fail "can't create temporary directory."
    100 mkdir -p "$tmpdir/closed/$rootdir" || exit 1
    101 
    102 #
    103 # This will hold a temp list of directories that must be kept, even if
    104 # empty.
    105 #
    106 needdirs=$(mktemp -t needdirsXXXXX)
    107 [[ -n "$needdirs" ]] || fail "can't create temporary directory list file."
    108 
    109 #
    110 # Copy the full tree into a temp directory.
    111 #
    112 (cd "$full"; tar cf - .) | (cd "$tmpdir/closed/$rootdir"; tar xpf -)
    113 
    114 #
    115 # Remove internal ON crypto signing certs
    116 #
    117 delete="
    118 	etc/certs/SUNWosnetSE
    119 	etc/certs/SUNWosnetSolaris
    120 	etc/crypto/certs/SUNWosnet
    121 	etc/crypto/certs/SUNWosnetLimited
    122 	etc/crypto/certs/SUNWosnetCF
    123 	etc/crypto/certs/SUNWosnetCFLimited
    124 	"
    125 
    126 #
    127 # Remove miscellaneous files that we don't want to ship.
    128 #
    129 
    130 # SUNWsvvs (SVVS test drivers).
    131 delete="$delete
    132 	usr/include/sys/lo.h
    133 	usr/include/sys/tidg.h
    134 	usr/include/sys/tivc.h
    135 	usr/include/sys/tmux.h
    136 	usr/kernel/drv/amd64/lo
    137 	usr/kernel/drv/amd64/tidg
    138 	usr/kernel/drv/amd64/tivc
    139 	usr/kernel/drv/amd64/tmux
    140 	usr/kernel/drv/lo
    141 	usr/kernel/drv/lo.conf
    142 	usr/kernel/drv/sparcv9/lo
    143 	usr/kernel/drv/sparcv9/tidg
    144 	usr/kernel/drv/sparcv9/tivc
    145 	usr/kernel/drv/sparcv9/tmux
    146 	usr/kernel/drv/tidg
    147 	usr/kernel/drv/tidg.conf
    148 	usr/kernel/drv/tivc
    149 	usr/kernel/drv/tivc.conf
    150 	usr/kernel/drv/tmux
    151 	usr/kernel/drv/tmux.conf
    152 	usr/kernel/strmod/amd64/lmodb
    153 	usr/kernel/strmod/amd64/lmode
    154 	usr/kernel/strmod/amd64/lmodr
    155 	usr/kernel/strmod/amd64/lmodt
    156 	usr/kernel/strmod/lmodb
    157 	usr/kernel/strmod/lmode
    158 	usr/kernel/strmod/lmodr
    159 	usr/kernel/strmod/lmodt
    160 	usr/kernel/strmod/sparcv9/lmodb
    161 	usr/kernel/strmod/sparcv9/lmode
    162 	usr/kernel/strmod/sparcv9/lmodr
    163 	usr/kernel/strmod/sparcv9/lmodt
    164 "
    165 # encumbered binaries and associated files
    166 delete="$delete
    167 	kernel/drv/amd64/bmc
    168 	kernel/drv/bmc
    169 	kernel/drv/bmc.conf
    170 	kernel/drv/ifp.conf
    171 	kernel/drv/sparcv9/ifp
    172 	kernel/drv/sparcv9/isp
    173 	kernel/drv/spwr
    174 	kernel/drv/spwr.conf
    175 	kernel/kmdb/sparcv9/isp
    176 	usr/bin/ksh
    177 	usr/bin/pfksh
    178 	usr/bin/rksh
    179 	usr/include/sys/scsi/adapters/ifpcmd.h
    180 	usr/include/sys/scsi/adapters/ifpio.h
    181 	usr/include/sys/scsi/adapters/ifpmail.h
    182 	usr/include/sys/scsi/adapters/ifpreg.h
    183 	usr/include/sys/scsi/adapters/ifpvar.h
    184 	usr/include/sys/scsi/adapters/ispcmd.h
    185 	usr/include/sys/scsi/adapters/ispmail.h
    186 	usr/include/sys/scsi/adapters/ispreg.h
    187 	usr/include/sys/scsi/adapters/ispvar.h
    188 	usr/lib/mdb/kvm/sparcv9/isp.so
    189 	usr/platform/SUNW,Netra-T12/
    190 	usr/platform/sun4u/include/sys/memtestio.h
    191 	usr/platform/sun4u/include/sys/memtestio_ch.h
    192 	usr/platform/sun4u/include/sys/memtestio_chp.h
    193 	usr/platform/sun4u/include/sys/memtestio_ja.h
    194 	usr/platform/sun4u/include/sys/memtestio_jg.h
    195 	usr/platform/sun4u/include/sys/memtestio_sf.h
    196 	usr/platform/sun4u/include/sys/memtestio_sr.h
    197 	usr/platform/sun4u/include/sys/memtestio_u.h
    198 	usr/platform/sun4u/include/sys/memtestio_pn.h
    199 	usr/platform/sun4v/include/sys/memtestio.h
    200 	usr/platform/sun4v/include/sys/memtestio_ni.h
    201 	usr/platform/sun4v/include/sys/memtestio_v.h
    202 	usr/share/lib/sgml/locale/C/dtds/docbook/docbook.dtd
    203 	usr/share/lib/sgml/locale/C/dtds/docbook/
    204 	usr/share/lib/sgml/locale/C/dtds/solbookv1/solbook.dtd
    205 	usr/share/lib/sgml/locale/C/dtds/solbookv1/
    206 "
    207 # memory fault injector test framework
    208 delete="$delete
    209 	usr/bin/mtst
    210 	platform/sun4u/kernel/drv/sparcv9/memtest
    211 	platform/sun4u/kernel/drv/memtest.conf
    212 	platform/sun4v/kernel/drv/sparcv9/memtest
    213 	platform/sun4v/kernel/drv/memtest.conf
    214 	platform/i86pc/kernel/drv/memtest.conf
    215 	platform/i86pc/kernel/drv/memtest
    216 	platform/i86pc/kernel/drv/amd64/memtest
    217 	usr/platform/i86pc/lib/mtst/mtst_AuthenticAMD_15.so
    218 "
    219 for f in $delete; do
    220 	rm -rf "$tmpdir/closed/$rootdir/$f"
    221 done
    222 
    223 #
    224 # Remove files that the open tree already has.
    225 #
    226 (cd "$open"; find . -type f -print -o -type l -print) > "$tmpdir/deleteme"
    227 (cd "$tmpdir/closed/$rootdir"; cat "$tmpdir/deleteme" | xargs rm -f)
    228 
    229 #
    230 # Remove any header files.  If they're in the closed tree, they're
    231 # probably not freely redistributable.
    232 #
    233 (cd "$tmpdir/closed/$rootdir"; find . -name \*.h -exec rm -f {} \;)
    234 
    235 #
    236 # Remove empty directories that the open tree doesn't need.
    237 #
    238 # Step 1: walk the usr/src/pkgdefs files to find out which directories
    239 # are specified in the open packages; save that list to a temporary
    240 # file $needdirs.
    241 #
    242 (cd "$SRC/pkgdefs"; \
    243 	find . -name prototype\* -exec grep "^d" {} \; | awk '{print $3}' > \
    244 	"$needdirs")
    245 #
    246 # Step 2: go to our closed directory, and find all the subdirectories,
    247 # filtering out the ones needed by the open packages (saved in that
    248 # temporary file).  Sort in reverse order, so that parent directories
    249 # come after any subdirectories, and pipe that to rmdir.  If there are
    250 # still any lingering files, rmdir will complain.  That's fine--we
    251 # only want to delete empty directories--so redirect the complaints to
    252 # /dev/null.
    253 #
    254 (cd "$tmpdir/closed/$rootdir"; \
    255 	find * -type d -print | /usr/xpg4/bin/grep -xv -f $needdirs | \
    256 	sort -r | xargs -l rmdir 2>/dev/null )
    257 
    258 rm "$needdirs"
    259 
    260 #
    261 # Up above we removed the files that were already in the open tree.
    262 # But that blew away the minimal closed binaries that are needed to do
    263 # an open build, so restore them here.
    264 #
    265 
    266 mkclosed "$isa" "$full" "$tmpdir/closed/$rootdir" || \
    267     fail "can't restore minimal binaries."
    268 
    269 #
    270 # Exclude signed crypto binaries; they are delivered in their
    271 # own tarball.
    272 #
    273 ROOT="$tmpdir/closed/$rootdir" findcrypto "$SRC/tools/codesign/creds" |
    274     awk '{ print $2 }' | (cd "$tmpdir/closed/$rootdir"; xargs rm -f)
    275 
    276 #
    277 # Add binary license files.
    278 #
    279 
    280 cp -p "$SRC/tools/opensolaris/BINARYLICENSE.txt" "$tmpdir/closed" || \
    281     fail "can't add BINARYLICENSE.txt"
    282 mkreadme "$tmpdir/closed"
    283 cp -p "$CODEMGR_WS/THIRDPARTYLICENSE.ON-BINARIES" "$tmpdir/closed" || \
    284     fail "can't add THIRDPARTYLICENSE.ON-BINARIES."
    285 
    286 (cd "$tmpdir"; tar cf "$tarfile" closed) || fail "can't create $tarfile."
    287 bzip2 -f "$tarfile" || fail "can't compress $tarfile".
    288 
    289 rm -rf "$tmpdir"
    290 
    291 exit 0
    292