makesrctars revision 1.26
1#! /bin/sh
2#
3#	$NetBSD: makesrctars,v 1.26 2005/10/21 03:57:07 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
34# handle args
35while getopts N:x: ch; do
36	case ${ch} in
37	x)	
38		xsrcdir=${OPTARG}
39		;;
40	N)
41		PASSWD=${OPTARG}
42		;;
43	*)
44		usage
45		;;
46	esac
47done
48shift $((${OPTIND} - 1))
49
50if [ $# -ne 2 ]; then
51	usage
52fi
53srcdir=$1
54setdir=$2
55: ${PASSWD:=${srcdir}/etc}
56
57if [ ! -d "${setdir}" ]; then
58	echo "${setdir} is not a directory"
59	exit 1
60fi
61
62makeset()
63{(
64	set=$1.tgz
65	shift
66	dir=$1
67	shift
68	echo "Creating ${set}"
69	if [ "${dir}" != "." ]; then
70		cd $dir
71		srcprefix="${srcprefix}/${dir}"
72	fi
73	# Gets rid of any obj dirs and things below it 
74	echo "obj" > /tmp/in$$
75	egrep=$*
76	if [ "$egrep" = "" ]; then
77	    egrep='.'
78	fi
79	set -f
80	${MTREE} -c -X /tmp/in$$ | ${MTREE} -C -k type | \
81		egrep -v 'type=link' | egrep $egrep | \
82		sed -e 's:type=file:& mode=0664:' \
83			-e 's:type=dir:& mode=0775:' \
84			-e 's:$: uname=root gname=wsrc:' | \
85		${PAX} -M -N ${PASSWD} -w -d -s'|^\.|'${srcprefix}'|' | \
86		gzip > "${setdir}/${set}"
87	rm -f /tmp/in$$
88)}
89
90
91# create (base)src sets
92#
93
94if ! cd "${srcdir}"; then
95	echo "Can't chdir to ${srcdir}"
96	exit 1
97fi
98
99srcprefix=usr/src
100export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
101
102makeset src . -v '^\.\/gnu|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config'
103
104makeset gnusrc gnu
105
106makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config'
107
108makeset sharesrc share
109
110
111# create xsrc sets
112#
113if [ -n "${xsrcdir}" ]; then
114	if ! cd "${xsrcdir}"; then
115		echo "Can't chdir to ${xsrcdir}"
116		exit 1
117	fi
118	srcprefix=usr/xsrc
119	makeset xsrc .
120fi
121
122
123echo "Creating checksum files"
124(cd ${setdir}
125	${CKSUM} -o1 *.tgz > BSDSUM
126	${CKSUM}     *.tgz > CKSUM
127	${CKSUM} -a md5  *.tgz > MD5
128	${CKSUM} -o2 *.tgz > SYSVSUM
129	${CKSUM} -a sha512 *.tgz > SHA512
130)
131