summaryrefslogtreecommitdiff
path: root/distrib/sets/maketars
blob: 1aa4de76191adebfbd6c0a0825095017849d34fb (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/sh
#
# $NetBSD: maketars,v 1.84 2015/05/27 15:18:29 martin Exp $
#
# Make release tar files for some or all lists.  Usage:
# maketars [-b] [-x] [-i installdir] [-a arch] [-m machine] [-s setsdir]
#	[-M metalog] [-N etcdir] [-F setlistsdir] [-d destdir]
#	[-t tardir] [-U] [setname ...]
#
# The default sets are "base comp debug etc games man misc tests text"
# The X sets are "xbase xcomp xdebug xetc xfont xserver"
# The extsrc sets are "extbase extcomp extetc"
#
# If '-i installdir' is given, copy the given sets to installdir
# (using pax -rw ...) instead of creating tar files.
# In this case, remove "etc", "xetc", and "extetc" from the list of default sets.
#

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

# set defaults
lists=
tars="${RELEASEDIR}"
dest="${DESTDIR}"
metalog=
installdir=
etcdir=
setlistdir=
setfilesonly=false
quiet=false
skipkeys=time,md5,sha1,sha384,sha512,rmd160,cksum
preserve="-pe"

usage()
{
	cat 1>&2 <<USAGE
Usage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine]
	    [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir]
	    [-d dest] [-t targetdir] [setname ...]
	-L base,x,ext	Make specified lists
	-b		Make both netbsd and x11 lists
	-x		Only make x11 lists
		[Default: make netbsd lists]
	-y		Only make extsrc lists
		[Default: make netbsd lists]
	-i idir		Install sets to idir instead of creating tar files
	-a arch		Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
	-m machine	Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
	-q		Quiet operation
	-s setsdir	Directory to find sets [${setsdir}]
	-F setlistdir	output directory for generated set lists [${dest}/etc/mtree/]
	-S		Exit after creating set files ${dest}/etc/mtree/set.*
	-M metalog	metalog file
	-N etcdir	etc dir for metalog use [${dest}/etc]
	-U		do not preserve file permissions (with -i ..)
	-d dest		\${DESTDIR}	[${dest}]
	-t targetdir	\${RELEASEDIR}	[${tars}]
	[setname ...]	Sets to build 	[${lists}]
USAGE
	exit 1
}

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

# handle args
while getopts L:bxyi:a:m:qs:F:SM:N:Ud:t: ch; do
	case ${ch} in
	L)
		save_IFS="${IFS}"
		IFS=,
		for _list in ${OPTARG}; do
			case $_list in
			base)	lists="${lists} ${nlists}" ;;
			x)	lists="${lists} ${xlists}" ;;
			ext)	lists="${lists} ${extlists}" ;;
			esac
		done
		IFS="${save_IFS}"
		;;
	# backward compat
	b)
		lists="${nlists} ${xlists}"
		;;
	x)
		lists="${xlists}"
		;;
	y)
		lists="${extlists}"
		;;
	i)
		installdir="${OPTARG}"
		;;
	a)
		MACHINE_ARCH="${OPTARG}"
		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
		;;
	m)
		MACHINE="${OPTARG}"
		;;
	q)
		quiet=true
		;;
	s)
		setsdir="${OPTARG}"
		;;
	F)
		setlistdir="${OPTARG}"
		;;
	S)
		setfilesonly=true
		;;
	M)
		metalog="${OPTARG}"
		;;
	N)
		etcdir="${OPTARG}"
		;;
	U)
		preserve=
		;;
	d)
		dest="${OPTARG}"
		;;
	t)
		tars="${OPTARG}"
		;;
	*)
		usage
		;;
	esac
done
shift $((${OPTIND} - 1))
if [ -n "${installdir}" ]; then	# if -i, remove etc + xetc + extetc from the default list
	lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
fi
if [ -n "$*" ]; then
	lists="$*"
fi

if [ -z "${tars}" -a -z "${installdir}" ]; then
	echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
	exit 1
fi

if [ -z "${dest}" ]; then
	echo >&2 "${prog}: \${DESTDIR} must be set"
	exit 1
fi
: ${etcdir:="${dest}/etc"}

SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
TMPFILES=

: ${setlistdir:="${dest}/etc/mtree"}

cleanup()
{
	es=$?
	/bin/rm -rf "${SDIR}" ${TMPFILES}
	trap - 0
	exit ${es}
}
trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE

#
# build the setfiles
#

for setname in ${lists}; do
	${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
	    -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
	    || exit 1
	if [ ! -s "${SDIR}/flist.${setname}" ]; then
		echo >&2 "makeflist output is empty for ${setname}"
		exit 1
	fi
	${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
	if [ -n "${metalog}" ]; then
		${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
		    > "${SDIR}/flist.${setname}.full" \
		    || exit 1
		(
			echo "/set uname=root gname=wheel"
			${AWK} -f "${rundir}/join.awk" \
				"${SDIR}/flist.${setname}.full" "${metalog}"
			echo "./etc/mtree/set.${setname} type=file mode=0444"
		) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \
		    > "${setlistdir}/set.${setname}" \
		    || exit 1
		# We deliberately do not add set.${setname} to ${metalog},
		# because we depend on it as an input.
	else
		${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \
		    -O "${SDIR}/flist.${setname}" | ${MTREE} -C -k all > \
		    "${setlistdir}/set.${setname}"
	fi
done
if ${setfilesonly}; then		# exit after creating the set lists
	exit 0
fi

runpax() {
	local s="$1"
	shift
	(cd "${dest}" && 
	    ${PAX} -dOw -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}")
}

#
# now build the tarfiles
#

GZIP=-9n		# for pax -z
export GZIP
es=0

for setname in ${lists:-${nlists}}; do
	out="${setname}.tgz"
	if [ -n "${installdir}" ]; then
		msg "Copying set ${setname}"
		runpax "${setname}" -r ${preserve} "${installdir}"
	else
		if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
		then
			msg "${out} is up to date"
			continue
		fi
		msg "Creating ${out}"
		rm -f "${tars}/${out}"
		TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
		runpax "${setname}" -z --use-compress-program \
		    ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" &&
		mv "${tars}/${out}.tmp" "${tars}/${out}"
	fi
	es=$((${es} + $?))
done
if [ ${es} -gt 255 ]; then
	es=255
fi
exit ${es}