xref: /netbsd-src/distrib/sets/makesrctars (revision 56a34939419542e88b386b2229be7565f4f45461)
1#! /bin/sh
2#
3#	$NetBSD: makesrctars,v 1.34 2008/03/16 07:02:22 lukem 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=
15quiet=false
16
17GZIP=-9
18export GZIP
19
20usage()
21{
22	cat 1>&2 <<USAGE
23Usage: ${prog} [-N password/group dir] [-q] [-x xsrcdir] srcdir setdir
24	-N dir		location which contains master.passwd and group files
25			(defaults to \${srcdir}/etc)
26	-q		quiet operation
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
34msg()
35{
36	$quiet || echo $*
37}
38
39
40# handle args
41while getopts N:qx: ch; do
42	case ${ch} in
43	q)
44		quiet=true
45		;;
46	x)
47		xsrcdir="${OPTARG}"
48		;;
49	N)
50		PASSWD="${OPTARG}"
51		;;
52	*)
53		usage
54		;;
55	esac
56done
57shift $((${OPTIND} - 1))
58
59if [ $# -ne 2 ]; then
60	usage
61fi
62srcdir="$1"
63setdir="$2"
64: ${PASSWD:="${srcdir}/etc"}
65
66if [ ! -d "${setdir}" ]; then
67	echo >&2 "${prog}: ${setdir} is not a directory"
68	exit 1
69fi
70
71makeset()
72{(
73	set="${1}.tgz"
74	shift
75	dir="$1"
76	shift
77	intmp="/tmp/in$$"
78	msg "Creating ${set}"
79	if [ "${dir}" != "." ]; then
80		cd "${dir}"
81		srcprefix="${srcprefix}/${dir}"
82	fi
83	# Gets rid of any obj dirs and things below it
84	echo "obj" > "${intmp}"
85	egrep="$*"
86	if [ "${egrep}" = "" ]; then
87		egrep='.'
88	fi
89	set -f
90	${MTREE} -c -X "${intmp}" | ${MTREE} -C -k type | \
91		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
92		${SED} -e 's:type=file:& mode=0664:' \
93			-e 's:type=dir:& mode=0775:' \
94			-e 's:$: uname=root gname=wsrc:' \
95			-e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \
96			-e '/^\.\/build.sh /s:\(mode\)=[0-9]*:\1=0775:' | \
97		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
98		${GZIP_CMD} > "${setdir}/${set}"
99	rm -f "${intmp}"
100)}
101
102
103# create (base)src sets
104#
105
106if ! cd "${srcdir}"; then
107	echo >&2 "${prog}: can't chdir to ${srcdir}"
108	exit 1
109fi
110
111srcprefix=usr/src
112export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
113
114makeset src . -v '^\.\/gnu|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config|^\.\/common'
115
116makeset gnusrc gnu
117
118makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common'
119
120makeset sharesrc share
121
122
123# create xsrc sets
124#
125if [ -n "${xsrcdir}" ]; then
126	if ! cd "${xsrcdir}"; then
127		echo >&2 "${prog}: can't chdir to ${xsrcdir}"
128		exit 1
129	fi
130	srcprefix=usr/xsrc
131	makeset xsrc .
132fi
133
134
135msg "Creating checksum files"
136(cd "${setdir}"
137	${CKSUM} -o1 *.tgz > BSDSUM
138	${CKSUM}     *.tgz > CKSUM
139	${CKSUM} -a md5  *.tgz > MD5
140	${CKSUM} -o2 *.tgz > SYSVSUM
141	${CKSUM} -a sha512 *.tgz > SHA512
142)
143exit 0
144