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