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