makesrctars revision 1.30
1#! /bin/sh
2#
3#	$NetBSD: makesrctars,v 1.30 2006/01/03 18:31:09 apb Exp $
4#
5# makesrctars srcdir setdir
6#	Create source tarballs in setdir from the source under srcdir.
7#
8
9prog="${0##*/}"
10rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
11. "${rundir}/sets.subr"
12
13# set defaults
14xsrcdir=
15
16GZIP=-9
17export GZIP
18
19usage()
20{
21	cat 1>&2 <<USAGE
22Usage: ${prog} [-N password/group dir] [-x xsrcdir] srcdir setdir
23	-N dir		location which contains master.passwd and group files
24			(defaults to \${srcdir}/etc)
25	-x xsrcdir	build xsrc.tgz from xsrcdir
26	srcdir		location of sources
27	setdir		where to write the .tgz files to
28USAGE
29	exit 1
30}
31
32# handle args
33while getopts N:x: ch; do
34	case ${ch} in
35	x)
36		xsrcdir="${OPTARG}"
37		;;
38	N)
39		PASSWD="${OPTARG}"
40		;;
41	*)
42		usage
43		;;
44	esac
45done
46shift $((${OPTIND} - 1))
47
48if [ $# -ne 2 ]; then
49	usage
50fi
51srcdir="$1"
52setdir="$2"
53: ${PASSWD:="${srcdir}/etc"}
54
55if [ ! -d "${setdir}" ]; then
56	echo "${setdir} is not a directory"
57	exit 1
58fi
59
60makeset()
61{(
62	set="${1}.tgz"
63	shift
64	dir="$1"
65	shift
66	intmp="/tmp/in$$"
67	echo "Creating ${set}"
68	if [ "${dir}" != "." ]; then
69		cd "${dir}"
70		srcprefix="${srcprefix}/${dir}"
71	fi
72	# Gets rid of any obj dirs and things below it 
73	echo "obj" > "${intmp}"
74	egrep="$*"
75	if [ "${egrep}" = "" ]; then
76		egrep='.'
77	fi
78	set -f
79	${MTREE} -c -X "${intmp}" | ${MTREE} -C -k type | \
80		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
81		${SED} -e 's:type=file:& mode=0664:' \
82			-e 's:type=dir:& mode=0775:' \
83			-e 's:$: uname=root gname=wsrc:' | \
84		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
85		${GZIP_CMD} > "${setdir}/${set}"
86	rm -f "${intmp}"
87)}
88
89
90# create (base)src sets
91#
92
93if ! cd "${srcdir}"; then
94	echo "Can't chdir to ${srcdir}"
95	exit 1
96fi
97
98srcprefix=usr/src
99export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
100
101makeset src . -v '^\.\/gnu|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config'
102
103makeset gnusrc gnu
104
105makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config'
106
107makeset sharesrc share
108
109
110# create xsrc sets
111#
112if [ -n "${xsrcdir}" ]; then
113	if ! cd "${xsrcdir}"; then
114		echo "Can't chdir to ${xsrcdir}"
115		exit 1
116	fi
117	srcprefix=usr/xsrc
118	makeset xsrc .
119fi
120
121
122echo "Creating checksum files"
123(cd "${setdir}"
124	${CKSUM} -o1 *.tgz > BSDSUM
125	${CKSUM}     *.tgz > CKSUM
126	${CKSUM} -a md5  *.tgz > MD5
127	${CKSUM} -o2 *.tgz > SYSVSUM
128	${CKSUM} -a sha512 *.tgz > SHA512
129)
130exit 0
131