xref: /netbsd-src/distrib/sets/makesrctars (revision e3606ab09ead8e3dc0a34037c78eeada7bc67baa)
1#! /bin/sh
2#
3#	$NetBSD: makesrctars,v 1.46 2023/11/08 13:02:47 christos 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] 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
40umask 022
41# handle args
42while getopts N:qx: ch; do
43	case ${ch} in
44	q)
45		quiet=true
46		;;
47	x)
48		xsrcdir="${OPTARG}"
49		;;
50	N)
51		PASSWD="${OPTARG}"
52		;;
53	*)
54		usage
55		;;
56	esac
57done
58shift $((${OPTIND} - 1))
59
60if [ $# -ne 2 ]; then
61	usage
62fi
63srcdir="$1"
64setdir="$2"
65: ${PASSWD:="${srcdir}/etc"}
66
67if [ ! -d "${setdir}" ]; then
68	echo >&2 "${prog}: ${setdir} is not a directory"
69	exit 1
70fi
71
72makeset()
73{(
74	set="${1}.tgz"
75	shift
76	dir="$1"
77	shift
78	intmp="/tmp/in$$"
79	msg "Creating ${set}"
80	if [ "${dir}" != "." ]; then
81		cd "${dir}"
82		srcprefix="${srcprefix}/${dir}"
83	fi
84	# Gets rid of any obj dirs and things below it. Also skip
85	# .hg or .git repositories (if we got the source via git
86	# or mercurial)
87	printf "obj\n./.git\n./.hg\n" > "${intmp}"
88	egrep="$*"
89	if [ "${egrep}" = "" ]; then
90		egrep='.'
91	fi
92	set -f
93	${MTREE} -c -X "${intmp}" | ${MTREE} -CS -k type | \
94		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
95		${SED} -e 's:type=file:& mode=0664:' \
96			-e 's:type=dir:& mode=0775:' \
97			-e 's:$: uname=root gname=wsrc:' \
98			-e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \
99			-e '/^\.\/.*[.-]sh /s:\(mode\)=[0-9]*:\1=0775:' | \
100		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
101		${GZIP_CMD} > "${setdir}/${set}"
102	rm -f "${intmp}"
103)}
104
105
106# create (base)src sets
107#
108
109if ! cd "${srcdir}"; then
110	echo >&2 "${prog}: can't chdir to ${srcdir}"
111	exit 1
112fi
113
114srcprefix=usr/src
115export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
116
117makeset src . -v '^\.\/common|^\.\/external\/gpl2|^\.\/external\/gpl3|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config'
118
119makeset gnusrc . -e '^\..type=dir|^\.\/external.type=dir|^\.\/external\/gpl2|^\.\/external\/gpl3'
120
121makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common'
122
123makeset sharesrc share
124
125
126# create xsrc sets
127#
128if [ -n "${xsrcdir}" ]; then
129	if ! cd "${xsrcdir}"; then
130		echo >&2 "${prog}: can't chdir to ${xsrcdir}"
131		exit 1
132	fi
133	srcprefix=usr/xsrc
134	makeset xsrc .
135fi
136
137
138msg "Creating checksum files"
139(cd "${setdir}"
140	${CKSUM} -a md5  *.tgz *.tar.xz > MD5
141	${CKSUM} -a sha512 *.tgz *.tar.xz > SHA512
142)
143exit 0
144