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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  25 #
  26 # Create an encumbered binaries tarball from a full build proto area,
  27 # less the contents of an OpenSolaris proto area.  Special handling
  28 # for crypto binaries that need to be signed by Sun Release
  29 # Engineering.
  30 #
  31 
  32 usage="bindrop [-n] basename"
  33 
  34 isa=`uname -p`
  35 
  36 PATH="$PATH:/usr/bin:/usr/sfw/bin"
  37 
  38 function fail {
  39         print -u2 "bindrop: $@"
  40         exit 1
  41 }
  42 
  43 function warn {
  44         print -u2 "bindrop: warning: $@"
  45 }
  46 
  47 [[ -n "$SRC" ]] || fail "SRC must be set."
  48 [[ -n "$CODEMGR_WS" ]] || fail "CODEMGR_WS must be set."
  49 
  50 #
  51 # Create the README from boilerplate and the contents of the closed
  52 # binary tree.
  53 #
  54 # usage: mkreadme targetdir
  55 #
  56 function mkreadme {
  57         typeset targetdir="$1"
  58         typeset readme="README.ON-BINARIES.$isa"
  59 
  60         sed -e s/@ISA@/$isa/ -e s/@DELIVERY@/ON-BINARIES/ \
  61             "$SRC/tools/opensolaris/README.binaries.tmpl" > "$targetdir/$readme"
  62         (cd "$targetdir"; find "$rootdir" -type f -print | \
  63             sort >> "$targetdir/$readme")
  64 }
  65 
  66 nondebug=n
  67 while getopts n flag; do
  68         case $flag in
  69         n)
  70                 nondebug=y
  71                 ;;
  72         ?)
  73                 print -u2 "usage: $usage"
  74                 exit 1
  75                 ;;
  76         esac
  77 done
  78 shift $(($OPTIND - 1))
  79 
  80 if [[ $# -ne 1 ]]; then
  81         print -u2 "usage: $usage"
  82         exit 1
  83 fi
  84 
  85 tarfile="$CODEMGR_WS/$1.$isa.tar"
  86 
  87 rootdir="root_$isa"
  88 suffix=""
  89 if [[ "$nondebug" = y ]]; then
  90         rootdir="root_$isa-nd"
  91         suffix="-nd"
  92 fi
  93 
  94 [[ -d "${ROOT}${suffix}-closed" ]] || fail "can't find closed root proto area."
  95 
  96 tmpdir=$(mktemp -dt bindropXXXXX)
  97 [[ -n "$tmpdir" ]] || fail "can't create temporary directory."
  98 mkdir -p "$tmpdir/closed/$rootdir" || exit 1
  99 
 100 #
 101 # This will hold a temp list of directories that must be kept, even if
 102 # empty.
 103 #
 104 needdirs=$(mktemp -t needdirsXXXXX)
 105 [[ -n "$needdirs" ]] || fail "can't create temporary directory list file."
 106 
 107 #
 108 # Copy the closed root parallel tree into a temp directory.
 109 #
 110 (cd "${ROOT}${suffix}-closed"; tar cf - .) | (cd "$tmpdir/closed/$rootdir"; tar xpf -)
 111 
 112 #
 113 # Remove internal ON crypto signing certs
 114 #
 115 delete="
 116         etc/certs/SUNWosnetSE
 117         etc/certs/SUNWosnetSolaris
 118         etc/crypto/certs/SUNWosnet
 119         etc/crypto/certs/SUNWosnetLimited
 120         etc/crypto/certs/SUNWosnetCF
 121         etc/crypto/certs/SUNWosnetCFLimited
 122         "
 123 
 124 #
 125 # Remove miscellaneous files that we don't want to ship.
 126 #
 127 
 128 # SUNWsvvs (SVVS test drivers).
 129 delete="$delete
 130         usr/include/sys/svvslo.h
 131         usr/include/sys/tidg.h
 132         usr/include/sys/tivc.h
 133         usr/include/sys/tmux.h
 134         usr/kernel/drv/amd64/svvslo
 135         usr/kernel/drv/amd64/tidg
 136         usr/kernel/drv/amd64/tivc
 137         usr/kernel/drv/amd64/tmux
 138         usr/kernel/drv/sparcv9/svvslo
 139         usr/kernel/drv/sparcv9/tidg
 140         usr/kernel/drv/sparcv9/tivc
 141         usr/kernel/drv/sparcv9/tmux
 142         usr/kernel/drv/svvslo
 143         usr/kernel/drv/svvslo.conf
 144         usr/kernel/drv/tidg
 145         usr/kernel/drv/tidg.conf
 146         usr/kernel/drv/tivc
 147         usr/kernel/drv/tivc.conf
 148         usr/kernel/drv/tmux
 149         usr/kernel/drv/tmux.conf
 150         usr/kernel/strmod/amd64/lmodb
 151         usr/kernel/strmod/amd64/lmode
 152         usr/kernel/strmod/amd64/lmodr
 153         usr/kernel/strmod/amd64/lmodt
 154         usr/kernel/strmod/lmodb
 155         usr/kernel/strmod/lmode
 156         usr/kernel/strmod/lmodr
 157         usr/kernel/strmod/lmodt
 158         usr/kernel/strmod/sparcv9/lmodb
 159         usr/kernel/strmod/sparcv9/lmode
 160         usr/kernel/strmod/sparcv9/lmodr
 161         usr/kernel/strmod/sparcv9/lmodt
 162 "
 163 # encumbered binaries and associated files
 164 delete="$delete
 165         kernel/drv/amd64/bmc
 166         kernel/drv/bmc
 167         kernel/drv/bmc.conf
 168         kernel/drv/ifp.conf
 169         kernel/drv/sparcv9/ifp
 170         kernel/drv/sparcv9/isp
 171         kernel/drv/sparcv9/qus
 172         kernel/drv/spwr
 173         kernel/kmdb/sparcv9/isp
 174         usr/has/bin/ksh
 175         usr/has/bin/pfksh
 176         usr/has/bin/rksh
 177         usr/include/sys/scsi/adapters/ifpcmd.h
 178         usr/include/sys/scsi/adapters/ifpio.h
 179         usr/include/sys/scsi/adapters/ifpmail.h
 180         usr/include/sys/scsi/adapters/ifpreg.h
 181         usr/include/sys/scsi/adapters/ifpvar.h
 182         usr/include/sys/scsi/adapters/ispcmd.h
 183         usr/include/sys/scsi/adapters/ispmail.h
 184         usr/include/sys/scsi/adapters/ispreg.h
 185         usr/include/sys/scsi/adapters/ispvar.h
 186         usr/lib/mdb/kvm/sparcv9/isp.so
 187         usr/platform/sun4u/include/sys/memtestio.h
 188         usr/platform/sun4u/include/sys/memtestio_ch.h
 189         usr/platform/sun4u/include/sys/memtestio_chp.h
 190         usr/platform/sun4u/include/sys/memtestio_ja.h
 191         usr/platform/sun4u/include/sys/memtestio_jg.h
 192         usr/platform/sun4u/include/sys/memtestio_sf.h
 193         usr/platform/sun4u/include/sys/memtestio_sr.h
 194         usr/platform/sun4u/include/sys/memtestio_u.h
 195         usr/platform/sun4u/include/sys/memtestio_pn.h
 196         usr/platform/sun4v/include/sys/memtestio.h
 197         usr/platform/sun4v/include/sys/memtestio_ni.h
 198         usr/platform/sun4v/include/sys/memtestio_v.h
 199 "
 200 # memory fault injector test framework
 201 delete="$delete
 202         usr/bin/mtst
 203         platform/sun4u/kernel/drv/sparcv9/memtest
 204         platform/sun4u/kernel/drv/memtest.conf
 205         platform/sun4v/kernel/drv/sparcv9/memtest
 206         platform/sun4v/kernel/drv/memtest.conf
 207         kernel/drv/memtest.conf
 208         kernel/drv/memtest
 209         kernel/drv/amd64/memtest
 210         usr/platform/i86pc/lib/mtst/mtst_AuthenticAMD_15.so
 211         usr/platform/i86pc/lib/mtst/mtst_AuthenticAMD.so
 212         usr/platform/i86pc/lib/mtst/mtst_generic.so
 213         usr/platform/i86pc/lib/mtst/mtst_GenuineIntel.so
 214 "
 215 for f in $delete; do
 216         rm -rf "$tmpdir/closed/$rootdir/$f"
 217 done
 218 
 219 #
 220 # Remove any header files.  If they're in the closed tree, they're
 221 # probably not freely redistributable.
 222 #
 223 (cd "$tmpdir/closed/$rootdir"; find . -name \*.h \
 224         -a \! -name lc_core.h \
 225         -a \! -name localedef.h \
 226         -exec rm -f {} \;)
 227 
 228 #
 229 # Remove empty directories that the open tree doesn't need.
 230 #
 231 # Step 1: walk the redistributable manifests to find out which directories
 232 # are specified in the open packages; save that list to a temporary
 233 # file $needdirs.
 234 #
 235 MACH=$(uname -p)
 236 (cd "$SRC/pkg/packages.$MACH"; \
 237         nawk '/^dir/ {sub(/.+ path=/, ""); print $1;}' *.metadata.*.redist | \
 238         sort -u > "$needdirs")
 239 
 240 #
 241 # Step 2: go to our closed directory, and find all the subdirectories,
 242 # filtering out the ones needed by the open packages (saved in that
 243 # temporary file).  Sort in reverse order, so that parent directories
 244 # come after any subdirectories, and pipe that to rmdir.  If there are
 245 # still any lingering files, rmdir will complain.  That's fine--we
 246 # only want to delete empty directories--so redirect the complaints to
 247 # /dev/null.
 248 #
 249 (cd "$tmpdir/closed/$rootdir"; \
 250         find * -type d -print | /usr/xpg4/bin/grep -xv -f $needdirs | \
 251         sort -r | xargs -l rmdir 2>/dev/null )
 252 
 253 rm "$needdirs"
 254 
 255 #
 256 # Exclude signed crypto binaries; they are delivered in their
 257 # own tarball.
 258 #
 259 ROOT="$tmpdir/closed/$rootdir" findcrypto "$SRC/tools/codesign/creds" |
 260     awk '{ print $2 }' | (cd "$tmpdir/closed/$rootdir"; xargs rm -f)
 261 
 262 #
 263 # Add binary license files.
 264 #
 265 
 266 cp -p "$SRC/tools/opensolaris/BINARYLICENSE.txt" "$tmpdir/closed" || \
 267     fail "can't add BINARYLICENSE.txt"
 268 mkreadme "$tmpdir/closed"
 269 if [ -f "$CODEMGR_WS/THIRDPARTYLICENSE.ON-BINARIES" ]; then
 270     cp -p "$CODEMGR_WS/THIRDPARTYLICENSE.ON-BINARIES" "$tmpdir/closed"
 271 fi
 272 
 273 (cd "$tmpdir"; tar cf "$tarfile" closed) || fail "can't create $tarfile."
 274 bzip2 -f "$tarfile" || fail "can't compress $tarfile".
 275 
 276 rm -rf "$tmpdir"
 277 
 278 exit 0