summaryrefslogtreecommitdiff
path: root/distrib/sets/makesrctars
blob: 00adfe5dac9bc61b8ff2eb82ded275a90f6645b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#! /bin/sh
#
#	$NetBSD: makesrctars,v 1.40 2015/02/05 07:52:49 snj Exp $
#
# makesrctars srcdir setdir
#	Create source tarballs in setdir from the source under srcdir.
#

prog="${0##*/}"
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
. "${rundir}/sets.subr"

# set defaults
xsrcdir=
quiet=false

GZIP=-9n
export GZIP

usage()
{
	cat 1>&2 <<USAGE
Usage: ${prog} [-N password/group dir] [-q] [-x xsrcdir] [-y extsrcsrcdir] srcdir setdir
	-N dir		location which contains master.passwd and group files
			(defaults to \${srcdir}/etc)
	-q		quiet operation
	-x xsrcdir	build xsrc.tgz from xsrcdir
	-y extsrcsrcdir	build extsrc.tgz from extsrcsrcdir
	srcdir		location of sources
	setdir		where to write the .tgz files to
USAGE
	exit 1
}

msg()
{
	$quiet || echo $*
}


# handle args
while getopts N:qx:y: ch; do
	case ${ch} in
	q)
		quiet=true
		;;
	x)
		xsrcdir="${OPTARG}"
		;;
	y)
		extsrcsrcdir="${OPTARG}"
		;;
	N)
		PASSWD="${OPTARG}"
		;;
	*)
		usage
		;;
	esac
done
shift $((${OPTIND} - 1))

if [ $# -ne 2 ]; then
	usage
fi
srcdir="$1"
setdir="$2"
: ${PASSWD:="${srcdir}/etc"}

if [ ! -d "${setdir}" ]; then
	echo >&2 "${prog}: ${setdir} is not a directory"
	exit 1
fi

makeset()
{(
	set="${1}.tgz"
	shift
	dir="$1"
	shift
	intmp="/tmp/in$$"
	msg "Creating ${set}"
	if [ "${dir}" != "." ]; then
		cd "${dir}"
		srcprefix="${srcprefix}/${dir}"
	fi
	# Gets rid of any obj dirs and things below it 
	echo "obj" > "${intmp}"
	egrep="$*"
	if [ "${egrep}" = "" ]; then
		egrep='.'
	fi
	set -f
	${MTREE} -c -X "${intmp}" | ${MTREE} -CS -k type | \
		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
		${SED} -e 's:type=file:& mode=0664:' \
			-e 's:type=dir:& mode=0775:' \
			-e 's:$: uname=root gname=wsrc:' \
			-e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \
			-e '/^\.\/.*[.-]sh /s:\(mode\)=[0-9]*:\1=0775:' | \
		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
		${GZIP_CMD} > "${setdir}/${set}"
	rm -f "${intmp}"
)}


# create (base)src sets
#

if ! cd "${srcdir}"; then
	echo >&2 "${prog}: can't chdir to ${srcdir}"
	exit 1
fi

srcprefix=usr/src
export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix

makeset src . -v '^\.\/common|^\.\/external\/gpl2|^\.\/external\/gpl3|^\.\/gnu|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config'

makeset gnusrc . -e '^\..type=dir|^\.\/gnu|^\.\/external.type=dir|^\.\/external\/gpl2|^\.\/external\/gpl3'

makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common'

makeset sharesrc share


# create xsrc sets
#
if [ -n "${xsrcdir}" ]; then
	if ! cd "${xsrcdir}"; then
		echo >&2 "${prog}: can't chdir to ${xsrcdir}"
		exit 1
	fi
	srcprefix=usr/xsrc
	makeset xsrc .
fi


# create extsrc sets
#
if [ -n "${extsrcsrcdir}" ]; then
	if ! cd "${extsrcsrcdir}"; then
		echo >&2 "${prog}: can't chdir to ${extsrcsrcdir}"
		exit 1
	fi
	srcprefix=usr/extsrc
	makeset extsrc .
fi


msg "Creating checksum files"
(cd "${setdir}"
	${CKSUM} -a md5  *.tgz > MD5
	${CKSUM} -a sha512 *.tgz > SHA512
)
exit 0