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