makesrctars revision 1.43
1#! /bin/sh
2#
3#	$NetBSD: makesrctars,v 1.43 2021/09/07 18:02:46 martin 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. Also skip
88	# .hg or .git repositories (if we got the source via git
89	# or mercurial)
90	printf "obj\n./.git\n./.hg\n" > "${intmp}"
91	egrep="$*"
92	if [ "${egrep}" = "" ]; then
93		egrep='.'
94	fi
95	set -f
96	${MTREE} -c -X "${intmp}" | ${MTREE} -CS -k type | \
97		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
98		${SED} -e 's:type=file:& mode=0664:' \
99			-e 's:type=dir:& mode=0775:' \
100			-e 's:$: uname=root gname=wsrc:' \
101			-e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \
102			-e '/^\.\/.*[.-]sh /s:\(mode\)=[0-9]*:\1=0775:' | \
103		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
104		${GZIP_CMD} > "${setdir}/${set}"
105	rm -f "${intmp}"
106)}
107
108
109# create (base)src sets
110#
111
112if ! cd "${srcdir}"; then
113	echo >&2 "${prog}: can't chdir to ${srcdir}"
114	exit 1
115fi
116
117srcprefix=usr/src
118export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
119
120makeset src . -v '^\.\/common|^\.\/external\/gpl2|^\.\/external\/gpl3|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config'
121
122makeset gnusrc . -e '^\..type=dir|^\.\/external.type=dir|^\.\/external\/gpl2|^\.\/external\/gpl3'
123
124makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common'
125
126makeset sharesrc share
127
128
129# create xsrc sets
130#
131if [ -n "${xsrcdir}" ]; then
132	if ! cd "${xsrcdir}"; then
133		echo >&2 "${prog}: can't chdir to ${xsrcdir}"
134		exit 1
135	fi
136	srcprefix=usr/xsrc
137	makeset xsrc .
138fi
139
140
141# create extsrc sets
142#
143if [ -n "${extsrcsrcdir}" ]; then
144	if ! cd "${extsrcsrcdir}"; then
145		echo >&2 "${prog}: can't chdir to ${extsrcsrcdir}"
146		exit 1
147	fi
148	srcprefix=usr/extsrc
149	makeset extsrc .
150fi
151
152
153msg "Creating checksum files"
154(cd "${setdir}"
155	${CKSUM} -a md5  *.tgz *.tar.xz > MD5
156	${CKSUM} -a sha512 *.tgz *.tar.xz > SHA512
157)
158exit 0
159