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