xref: /onnv-gate/usr/src/tools/scripts/cryptodrop.sh (revision 11562:1ce42c60d482)
1#!/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
28#
29# Create a tarball with crypto binaries.
30#
31
32usage="cryptodrop [-n] result-path"
33
34isa=`uname -p`
35
36function fail {
37	print -u2 "cryptodrop: $@"
38	exit 1
39}
40
41[[ -n "$ROOT" ]] || fail "ROOT must be set."
42# Verify below (after adjusting for -n) that $ROOT exists, is a directory.
43[[ -n "$SRC" ]] || fail "SRC must be set."
44[[ -d "$SRC" ]] || fail "SRC ($SRC) is not a directory."
45[[ -n "$CODEMGR_WS" ]] || fail "CODEMGR_WS must be set."
46[[ -d "$CODEMGR_WS" ]] || fail "CODEMGR_WS ($CODEMGR_WS) is not a directory."
47
48#
49# Wrapper over cpio to filter out "NNN blocks" messages.
50#
51function cpio_filt {
52	integer cpio_stat
53
54	cpio "$@" > "$cpio_log" 2>&1
55	cpio_stat=$?
56	cat "$cpio_log" | awk '$0 !~ /[0-9]+ blocks/ { print }'
57	return $cpio_stat
58}
59
60#
61# Create the README from boilerplate and the contents of the closed
62# binary tree.
63#
64# usage: mkreadme targetdir
65#
66function mkreadme {
67	typeset targetdir="$1"
68	typeset readme="README.CRYPTO-BINARIES.$isa"
69
70	sed -e s/@ISA@/$isa/ -e s/@DELIVERY@/CRYPTO-BINARIES/ \
71	    "$SRC/tools/opensolaris/README.binaries.tmpl" > "$targetdir/$readme"
72	(cd "$targetdir"; find "$rootdir" -type f -print | \
73	    sort >> "$targetdir/$readme")
74}
75
76nondebug=n
77while getopts n flag; do
78	case $flag in
79	n)
80		nondebug=y
81		if [ "$MULTI_PROTO" = yes ]; then
82			export ROOT="$ROOT-nd"
83		fi
84		;;
85	?)
86		print -u2 "usage: $usage"
87		exit 1
88		;;
89	esac
90done
91shift $(($OPTIND - 1))
92
93if [[ $# -ne 1 ]]; then
94	print -u2 "usage: $usage"
95	exit 1
96fi
97[[ -d "$ROOT" ]] || fail "ROOT ($ROOT) is not a directory."
98
99tarfile="$1"
100
101if [[ "$nondebug" = n ]]; then
102	rootdir="root_$isa"
103else
104	rootdir="root_$isa-nd"
105fi
106
107tmpdir=$(mktemp -dt cryptodropXXXXX)
108[[ -n "$tmpdir" ]] || fail "could not create temporary directory."
109tmproot="$tmpdir/proto/$rootdir"
110mkdir -p "$tmproot" || exit 1
111cpio_log="$tmpdir/cpio.log"
112filelist="$tmpdir/files"
113
114#
115# Copy the crypto binaries into a temp directory.  This is a bit messy
116# because we want to preserve the permissions of intermediate
117# directories without including all the contents of those
118# directories.
119#
120
121# Echo all the parent directories of the given file.
122function alldirs {
123	d=$(dirname "$1")
124	while [ "$d" != . ]; do
125		echo $d
126		d=$(dirname "$d")
127	done
128}
129
130findcrypto "$SRC/tools/codesign/creds" | awk '{ print $2 }' > "$filelist"
131#
132# Both alldirs and the cpio -p invocation assume that findcrypto only
133# produces relative paths.
134#
135for f in $(cat "$filelist"); do
136	if [[ "$f" = /* ]]; then
137		fail "findcrypto produced absolute path ($f)"
138	fi
139done
140for f in $(cat "$filelist"); do
141	echo "$f"
142	alldirs "$f"
143done | sort -u | (cd "$ROOT"; cpio_filt -pdm "$tmproot")
144[[ $? -eq 0 ]] || fail "could not copy crypto files."
145
146rm -f "$cpio_log" "$filelist"
147
148#
149# Insert binary license files.
150#
151cp -p "$SRC/tools/opensolaris/BINARYLICENSE.txt" "$tmpdir/proto" || \
152    fail "could not add BINARYLICENSE.txt"
153mkreadme "$tmpdir/proto" || exit 1
154cp -p "$CODEMGR_WS/THIRDPARTYLICENSE.ON-CRYPTO" "$tmpdir/proto" || \
155    fail "could not add THIRDPARTYLICENSE.ON-CRYPTO."
156
157(cd "$tmpdir"; tar cf "$tarfile" proto) || fail "could not create $tarfile."
158bzip2 -f "$tarfile" || fail "could not compress $tarfile".
159
160rm -rf "$tmpdir"
161
162exit 0
163