Home | History | Annotate | Line # | Download | only in sets
maketars revision 1.84
      1 #!/bin/sh
      2 #
      3 # $NetBSD: maketars,v 1.84 2015/05/27 15:18:29 martin Exp $
      4 #
      5 # Make release tar files for some or all lists.  Usage:
      6 # maketars [-b] [-x] [-i installdir] [-a arch] [-m machine] [-s setsdir]
      7 #	[-M metalog] [-N etcdir] [-F setlistsdir] [-d destdir]
      8 #	[-t tardir] [-U] [setname ...]
      9 #
     10 # The default sets are "base comp debug etc games man misc tests text"
     11 # The X sets are "xbase xcomp xdebug xetc xfont xserver"
     12 # The extsrc sets are "extbase extcomp extetc"
     13 #
     14 # If '-i installdir' is given, copy the given sets to installdir
     15 # (using pax -rw ...) instead of creating tar files.
     16 # In this case, remove "etc", "xetc", and "extetc" from the list of default sets.
     17 #
     18 
     19 prog="${0##*/}"
     20 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     21 . "${rundir}/sets.subr"
     22 
     23 # set defaults
     24 lists=
     25 tars="${RELEASEDIR}"
     26 dest="${DESTDIR}"
     27 metalog=
     28 installdir=
     29 etcdir=
     30 setlistdir=
     31 setfilesonly=false
     32 quiet=false
     33 skipkeys=time,md5,sha1,sha384,sha512,rmd160,cksum
     34 preserve="-pe"
     35 
     36 usage()
     37 {
     38 	cat 1>&2 <<USAGE
     39 Usage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine]
     40 	    [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir]
     41 	    [-d dest] [-t targetdir] [setname ...]
     42 	-L base,x,ext	Make specified lists
     43 	-b		Make both netbsd and x11 lists
     44 	-x		Only make x11 lists
     45 		[Default: make netbsd lists]
     46 	-y		Only make extsrc lists
     47 		[Default: make netbsd lists]
     48 	-i idir		Install sets to idir instead of creating tar files
     49 	-a arch		Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
     50 	-m machine	Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
     51 	-q		Quiet operation
     52 	-s setsdir	Directory to find sets [${setsdir}]
     53 	-F setlistdir	output directory for generated set lists [${dest}/etc/mtree/]
     54 	-S		Exit after creating set files ${dest}/etc/mtree/set.*
     55 	-M metalog	metalog file
     56 	-N etcdir	etc dir for metalog use [${dest}/etc]
     57 	-U		do not preserve file permissions (with -i ..)
     58 	-d dest		\${DESTDIR}	[${dest}]
     59 	-t targetdir	\${RELEASEDIR}	[${tars}]
     60 	[setname ...]	Sets to build 	[${lists}]
     61 USAGE
     62 	exit 1
     63 }
     64 
     65 msg()
     66 {
     67 	$quiet || echo $*
     68 }
     69 
     70 # handle args
     71 while getopts L:bxyi:a:m:qs:F:SM:N:Ud:t: ch; do
     72 	case ${ch} in
     73 	L)
     74 		save_IFS="${IFS}"
     75 		IFS=,
     76 		for _list in ${OPTARG}; do
     77 			case $_list in
     78 			base)	lists="${lists} ${nlists}" ;;
     79 			x)	lists="${lists} ${xlists}" ;;
     80 			ext)	lists="${lists} ${extlists}" ;;
     81 			esac
     82 		done
     83 		IFS="${save_IFS}"
     84 		;;
     85 	# backward compat
     86 	b)
     87 		lists="${nlists} ${xlists}"
     88 		;;
     89 	x)
     90 		lists="${xlists}"
     91 		;;
     92 	y)
     93 		lists="${extlists}"
     94 		;;
     95 	i)
     96 		installdir="${OPTARG}"
     97 		;;
     98 	a)
     99 		MACHINE_ARCH="${OPTARG}"
    100 		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
    101 		;;
    102 	m)
    103 		MACHINE="${OPTARG}"
    104 		;;
    105 	q)
    106 		quiet=true
    107 		;;
    108 	s)
    109 		setsdir="${OPTARG}"
    110 		;;
    111 	F)
    112 		setlistdir="${OPTARG}"
    113 		;;
    114 	S)
    115 		setfilesonly=true
    116 		;;
    117 	M)
    118 		metalog="${OPTARG}"
    119 		;;
    120 	N)
    121 		etcdir="${OPTARG}"
    122 		;;
    123 	U)
    124 		preserve=
    125 		;;
    126 	d)
    127 		dest="${OPTARG}"
    128 		;;
    129 	t)
    130 		tars="${OPTARG}"
    131 		;;
    132 	*)
    133 		usage
    134 		;;
    135 	esac
    136 done
    137 shift $((${OPTIND} - 1))
    138 if [ -n "${installdir}" ]; then	# if -i, remove etc + xetc + extetc from the default list
    139 	lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
    140 fi
    141 if [ -n "$*" ]; then
    142 	lists="$*"
    143 fi
    144 
    145 if [ -z "${tars}" -a -z "${installdir}" ]; then
    146 	echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
    147 	exit 1
    148 fi
    149 
    150 if [ -z "${dest}" ]; then
    151 	echo >&2 "${prog}: \${DESTDIR} must be set"
    152 	exit 1
    153 fi
    154 : ${etcdir:="${dest}/etc"}
    155 
    156 SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
    157 TMPFILES=
    158 
    159 : ${setlistdir:="${dest}/etc/mtree"}
    160 
    161 cleanup()
    162 {
    163 	es=$?
    164 	/bin/rm -rf "${SDIR}" ${TMPFILES}
    165 	trap - 0
    166 	exit ${es}
    167 }
    168 trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
    169 
    170 #
    171 # build the setfiles
    172 #
    173 
    174 for setname in ${lists}; do
    175 	${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
    176 	    -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
    177 	    || exit 1
    178 	if [ ! -s "${SDIR}/flist.${setname}" ]; then
    179 		echo >&2 "makeflist output is empty for ${setname}"
    180 		exit 1
    181 	fi
    182 	${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
    183 	if [ -n "${metalog}" ]; then
    184 		${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
    185 		    > "${SDIR}/flist.${setname}.full" \
    186 		    || exit 1
    187 		(
    188 			echo "/set uname=root gname=wheel"
    189 			${AWK} -f "${rundir}/join.awk" \
    190 				"${SDIR}/flist.${setname}.full" "${metalog}"
    191 			echo "./etc/mtree/set.${setname} type=file mode=0444"
    192 		) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \
    193 		    > "${setlistdir}/set.${setname}" \
    194 		    || exit 1
    195 		# We deliberately do not add set.${setname} to ${metalog},
    196 		# because we depend on it as an input.
    197 	else
    198 		${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \
    199 		    -O "${SDIR}/flist.${setname}" | ${MTREE} -C -k all > \
    200 		    "${setlistdir}/set.${setname}"
    201 	fi
    202 done
    203 if ${setfilesonly}; then		# exit after creating the set lists
    204 	exit 0
    205 fi
    206 
    207 runpax() {
    208 	local s="$1"
    209 	shift
    210 	(cd "${dest}" && 
    211 	    ${PAX} -dOw -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}")
    212 }
    213 
    214 #
    215 # now build the tarfiles
    216 #
    217 
    218 GZIP=-9n		# for pax -z
    219 export GZIP
    220 es=0
    221 
    222 for setname in ${lists:-${nlists}}; do
    223 	out="${setname}.tgz"
    224 	if [ -n "${installdir}" ]; then
    225 		msg "Copying set ${setname}"
    226 		runpax "${setname}" -r ${preserve} "${installdir}"
    227 	else
    228 		if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
    229 		then
    230 			msg "${out} is up to date"
    231 			continue
    232 		fi
    233 		msg "Creating ${out}"
    234 		rm -f "${tars}/${out}"
    235 		TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
    236 		runpax "${setname}" -z --use-compress-program \
    237 		    ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" &&
    238 		mv "${tars}/${out}.tmp" "${tars}/${out}"
    239 	fi
    240 	es=$((${es} + $?))
    241 done
    242 if [ ${es} -gt 255 ]; then
    243 	es=255
    244 fi
    245 exit ${es}
    246