Home | History | Annotate | Line # | Download | only in sets
maketars revision 1.63
      1 #!/bin/sh
      2 #
      3 # $NetBSD: maketars,v 1.63 2008/03/16 04:39:19 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] [-d destdir] [-t tardir] [setname ...]
      8 #
      9 # The default sets are "base comp etc games man misc tests text"
     10 # The X sets are "xbase xcomp xetc xfont xserver"
     11 #
     12 # If '-i installdir' is given, copy the given sets to installdir
     13 # (using pax -rw ...) instead of creating tar files.
     14 # In this case, remove "etc" and "xetc" from the list of default sets.
     15 #
     16 
     17 prog="${0##*/}"
     18 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     19 . "${rundir}/sets.subr"
     20 
     21 # set defaults
     22 lists="${nlists}"
     23 tars="${RELEASEDIR}"
     24 dest="${DESTDIR}"
     25 metalog=
     26 installdir=
     27 etcdir=
     28 setfilesonly=false
     29 
     30 usage()
     31 {
     32 	cat 1>&2 <<USAGE
     33 Usage: ${prog} [-b] [-x] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S]
     34 	    [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...]
     35 	-b		Make both netbsd and x11 lists
     36 	-x		Only make x11 lists
     37 		[Default: make netbsd lists]
     38 	-i idir		Install sets to idir instead of creating tar files
     39 	-a arch		Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
     40 	-m machine	Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
     41 	-s setsdir	Directory to find sets [${setsdir}]
     42 	-S		Exit after creating set files ${dest}/etc/mtree/set.*
     43 	-M metalog	metalog file
     44 	-N etcdir	etc dir for metalog use [${dest}/etc]
     45 	-d dest		\${DESTDIR}	[${dest}]
     46 	-t targetdir	\${RELEASEDIR}	[${tars}]
     47 	[setname ...]	Sets to build 	[${lists}]
     48 USAGE
     49 	exit 1
     50 }
     51 
     52 # handle args
     53 while getopts bxi:a:m:s:SM:N:d:t: ch; do
     54 	case ${ch} in
     55 	b)
     56 		lists="${nlists} ${xlists}"
     57 		;;
     58 	x)
     59 		lists="${xlists}"
     60 		;;
     61 	i)
     62 		installdir="${OPTARG}"
     63 		;;
     64 	a)
     65 		MACHINE_ARCH="${OPTARG}"
     66 		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
     67 		;;
     68 	m)
     69 		MACHINE="${OPTARG}"
     70 		;;
     71 	s)
     72 		setsdir="${OPTARG}"
     73 		;;
     74 	S)
     75 		setfilesonly=true
     76 		;;
     77 	M)
     78 		metalog="${OPTARG}"
     79 		;;
     80 	N)
     81 		etcdir="${OPTARG}"
     82 		;;
     83 	d)
     84 		dest="${OPTARG}"
     85 		;;
     86 	t)
     87 		tars="${OPTARG}"
     88 		;;
     89 	*)
     90 		usage
     91 		;;
     92 	esac
     93 done
     94 shift $((${OPTIND} - 1))
     95 if [ -n "${installdir}" ]; then	# if -i, remove etc & xetc from the default list
     96 	lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /')"
     97 fi
     98 if [ -n "$*" ]; then
     99 	lists="$*"
    100 fi
    101 
    102 if [ -z "${tars}" -a -z "${installdir}" ]; then
    103 	echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
    104 	exit 1
    105 fi
    106 
    107 if [ -z "${dest}" ]; then
    108 	echo >&2 "${prog}: \${DESTDIR} must be set"
    109 	exit 1
    110 fi
    111 : ${etcdir:="${dest}/etc"}
    112 
    113 SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
    114 TMPFILES=
    115 
    116 setlistdir="${dest}/etc/mtree"
    117 
    118 cleanup()
    119 {
    120 	es=$?
    121 	/bin/rm -rf "${SDIR}" ${TMPFILES}
    122 	trap - 0
    123 	exit ${es}
    124 }
    125 trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
    126 
    127 #
    128 # build the setfiles
    129 #
    130 
    131 for setname in ${lists}; do
    132 	${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
    133 	    -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}"
    134 	if [ -n "${metalog}" ]; then
    135 		${setfilesonly} && echo "Creating ${setlistdir}/set.${setname}"
    136 		${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
    137 		    | ${SORT} -u > "${SDIR}/flist.${setname}.full"
    138 		(
    139 			echo "/set uname=root gname=wheel"
    140 			${AWK} -f "${rundir}/join.awk" \
    141 				"${SDIR}/flist.${setname}.full" "${metalog}"
    142 			echo "./etc/mtree/set.${setname} type=file mode=0444"
    143 		) > "${setlistdir}/set.${setname}"
    144 		# We deliberately do not add set.${setname} to ${metalog},
    145 		# because we depend on it as an input.
    146 	elif ! cmp -s "${SDIR}/flist.${setname}" \
    147 			"${setlistdir}/set.${setname}" >/dev/null 2>&1; then
    148 		rm -f "${setlistdir}/set.${setname}"
    149 		cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}"
    150 	fi
    151 done
    152 if ${setfilesonly}; then		# exit after creating the set lists
    153 	exit 0
    154 fi
    155 
    156 #
    157 # now build the tarfiles
    158 #
    159 
    160 GZIP=-9			# for pax -z
    161 export GZIP
    162 es=0
    163 for setname in ${lists}; do
    164 	out="${setname}.tgz"
    165 	if [ -n "${installdir}" ]; then
    166 		echo "Copying set ${setname}"
    167 		( cd "${dest}"; \
    168 		    ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
    169 			"${installdir}" < "${setlistdir}/set.${setname}" )
    170 	else
    171 		if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
    172 		then
    173 			echo "${out} is up to date"
    174 			continue
    175 		fi
    176 		echo "Creating ${out}"
    177 		rm -f "${tars}/${out}"
    178 		TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
    179 		( cd "${dest}"; \
    180 		    ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
    181 			< "${setlistdir}/set.${setname}" ) \
    182 			> "${tars}/${out}.tmp" &&
    183 		mv "${tars}/${out}.tmp" "${tars}/${out}"
    184 	fi
    185 	es=$((${es} + $?))
    186 done
    187 if [ ${es} -gt 255 ]; then
    188 	es=255
    189 fi
    190 exit ${es}
    191