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