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 2007 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"%Z%%M%	%I%	%E% SMI"
     28 #
     29 
     30 #
     31 # Create a set of BFU archives for posting, then deliver them as a
     32 # tarball, including binary license files.
     33 #
     34 # usage: bfudrop [-n] open-proto closed-bins build-id
     35 # -n			extract non-debug closed binaries.
     36 #			(open-proto and build-id are not modified.)
     37 # open-proto	absolute path to open-only proto area.
     38 # closed-bins	name of closed-bins tarball (bzipped, in $CODEMGR_WS)
     39 # build-ID		identifier for the archives, e.g.,
     40 #			"nightly-osol".
     41 #
     42 
     43 usage="bfudrop [-n] open-proto closed-bins build-ID"
     44 
     45 function fail {
     46 	print -u2 "bfudrop: $@"
     47 	exit 1
     48 }
     49 
     50 [[ -n "$SRC" ]] || fail "SRC must be set."
     51 [[ -n "$CODEMGR_WS" ]] || fail "CODEMGR_WS must be set."
     52 [[ -n "$CPIODIR" ]] || fail "CPIODIR must be set."
     53 
     54 #
     55 # Directory that we assemble everything in.  Includes these
     56 # subdirectories:
     57 # tmp			scratch directory
     58 # root_$MACH		combined proto area
     59 # archives-<build-ID>	copy of archives plus license files
     60 #
     61 stagedir=$(mktemp -dt bfudropXXXXX)
     62 
     63 [[ -n "$stagedir" ]] || fail "can't create staging directory."
     64 
     65 scratchdir="$stagedir/tmp"
     66 cpio_log="$stagedir/cpio.log"
     67 
     68 #
     69 # Wrapper over cpio to filter out "NNN blocks" messages.
     70 #
     71 function cpio_filt {
     72 	integer cpio_stat
     73 
     74 	cpio "$@" > "$cpio_log" 2>&1
     75 	cpio_stat=$?
     76 	cat "$cpio_log" | awk '$0 !~ /[0-9]+ blocks/ { print }'
     77 	return $cpio_stat
     78 }
     79 
     80 #
     81 # Generate README.BFU-ARCHIVES.$MACH from boilerplate and the contents
     82 # of the bfu archives.
     83 # usage: cd archivedir; mkreadme destdir
     84 #
     85 function mkreadme {
     86 	destdir="$1"
     87 	readme="$destdir/README.BFU-ARCHIVES.$MACH"
     88 	sed -e s/@ISA@/$MACH/ -e s/@DELIVERY@/BFU-ARCHIVES/ \
     89 	    "$SRC/tools/opensolaris/README.binaries.tmpl" > "$readme"
     90 	for f in *; do
     91 		print "==== $f ====" >> "$readme"
     92 		#
     93 		# The cpio table of contents includes directories, and
     94 		# we just want files.  So unpack the cpio file into a
     95 		# temp directory, do a find(1) to get the table of
     96 		# contents, and remove the temp directory.
     97 		#
     98 		mkdir -p "$scratchdir" || fail "can't create $scratchdir."
     99 		case $f in
    100 		*.gz)	cat=gzcat;;
    101 		*.Z)	cat=zcat;;
    102 		*.bz2)	cat=bzcat;;
    103 		*)	cat=cat;;
    104 		esac
    105 		if ! $cat $f | (cd "$scratchdir"; cpio_filt -id); then
    106 			fail "can't get contents for $f"
    107 		fi
    108 		#
    109 		# "find *" will miss dot files, but we don't expect
    110 		# any.  "find ." would catch them, but we'd have to
    111 		# clean up the resulting list (remove the "./").
    112 		#
    113 		(cd "$scratchdir"; find * -type f -print) | sort >> "$readme"
    114 		rm -rf "$scratchdir"
    115 	done
    116 }
    117 
    118 nondebug=n
    119 while getopts n flag; do
    120 	case $flag in
    121 	n)
    122 		nondebug=y
    123 		;;
    124 	?)
    125 		print -u2 "usage: $usage"
    126 		exit 1
    127 		;;
    128 	esac
    129 done
    130 shift $(($OPTIND - 1))
    131 
    132 if [[ $# -ne 3 ]]; then
    133 	print -u2 "usage: $usage"
    134 	exit 1
    135 fi
    136 srcroot="$1"
    137 closedtb="$2"
    138 build="$3"
    139 subdir="archives-$build"
    140 
    141 cpioparent="$(dirname $CPIODIR)"
    142 export CPIODIR="$cpioparent/$build"
    143 
    144 [[ -n "$MACH" ]] || MACH=$(uname -p)
    145 export MACH
    146 tarfile="$CODEMGR_WS/on-bfu-$build.$MACH.tar"
    147 
    148 newproto="$stagedir/root_$MACH"
    149 
    150 cd "$CODEMGR_WS"
    151 
    152 [[ -d "$srcroot" ]] || fail "can't find $srcroot."
    153 [[ -f "$closedtb" ]] || fail "can't find $closedtb."
    154 
    155 #
    156 # Copy the source proto area to a temp area and unpack the closed
    157 # binaries on top.  The source proto area is left alone so as not to
    158 # break future incremental builds.
    159 #
    160 
    161 mkdir -p "$newproto" || fail "can't create $newproto."
    162 (cd "$srcroot"; find . -depth -print | cpio_filt -pdm "$newproto")
    163 [[ $? -eq 0 ]] || fail "can't copy original proto area."
    164 
    165 mkdir -p "$scratchdir" || fail "can't create $scratchdir"
    166 (cd "$scratchdir"; bzcat "$CODEMGR_WS/$closedtb" | tar xf -)
    167 [[ $? -eq 0 ]] || fail "can't unpack closed binaries."
    168 closed_root="$scratchdir/closed/root_$MACH"
    169 [[ "$nondebug" = y ]] && closed_root="$closed_root-nd"
    170 if [[ ! -d "$closed_root" ]]; then
    171 	fail "can't find $(basename $closed_root) in closed binaries."
    172 fi
    173 (cd "$closed_root"; find . -depth -print | cpio_filt -pdmu "$newproto")
    174 [[ $? -eq 0 ]] || fail "can't copy closed binaries."
    175 rm -rf "$scratchdir"
    176 
    177 #
    178 # Generate the actual archives.
    179 #
    180 
    181 ROOT="$newproto" makebfu
    182 
    183 #
    184 # Bundle up the archives and license files.
    185 #
    186 
    187 mkdir -p "$stagedir/$subdir/$MACH" || \
    188     fail "can't create $stagedir/$subdir/$MACH."
    189 
    190 archvdir=$CPIODIR
    191 [[ -d "$archvdir" ]] || fail "can't find $archvdir."
    192 
    193 # copy archives
    194 (cd "$archvdir"; tar cf - .) | (cd "$stagedir/$subdir/$MACH"; tar xf -)
    195 
    196 # Insert binary license files.
    197 cp -p "$SRC/tools/opensolaris/BINARYLICENSE.txt" "$stagedir/$subdir" || \
    198     fail "can't add BINARYLICENSE.txt"
    199 (cd "$archvdir"; mkreadme "$stagedir/$subdir") || exit 1
    200 cp -p "$CODEMGR_WS/THIRDPARTYLICENSE.BFU-ARCHIVES" "$stagedir/$subdir" || \
    201     fail "can't add THIRDPARTYLICENSE.BFU-ARCHIVES."
    202 
    203 (cd "$stagedir"; tar cf "$tarfile" "$subdir") || fail "can't create $tarfile."
    204 bzip2 -f "$tarfile" || fail "can't compress $tarfile".
    205 
    206 rm -rf "$stagedir"
    207 
    208 exit 0
    209