Home | History | Annotate | Line # | Download | only in sets
makesrctars revision 1.35
      1 #! /bin/sh
      2 #
      3 #	$NetBSD: makesrctars,v 1.35 2009/04/03 22:36:35 perry Exp $
      4 #
      5 # makesrctars srcdir setdir
      6 #	Create source tarballs in setdir from the source under srcdir.
      7 #
      8 
      9 prog="${0##*/}"
     10 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     11 . "${rundir}/sets.subr"
     12 
     13 # set defaults
     14 xsrcdir=
     15 quiet=false
     16 
     17 GZIP=-9n
     18 export GZIP
     19 
     20 usage()
     21 {
     22 	cat 1>&2 <<USAGE
     23 Usage: ${prog} [-N password/group dir] [-q] [-x xsrcdir] srcdir setdir
     24 	-N dir		location which contains master.passwd and group files
     25 			(defaults to \${srcdir}/etc)
     26 	-q		quiet operation
     27 	-x xsrcdir	build xsrc.tgz from xsrcdir
     28 	srcdir		location of sources
     29 	setdir		where to write the .tgz files to
     30 USAGE
     31 	exit 1
     32 }
     33 
     34 msg()
     35 {
     36 	$quiet || echo $*
     37 }
     38 
     39 
     40 # handle args
     41 while getopts N:qx: ch; do
     42 	case ${ch} in
     43 	q)
     44 		quiet=true
     45 		;;
     46 	x)
     47 		xsrcdir="${OPTARG}"
     48 		;;
     49 	N)
     50 		PASSWD="${OPTARG}"
     51 		;;
     52 	*)
     53 		usage
     54 		;;
     55 	esac
     56 done
     57 shift $((${OPTIND} - 1))
     58 
     59 if [ $# -ne 2 ]; then
     60 	usage
     61 fi
     62 srcdir="$1"
     63 setdir="$2"
     64 : ${PASSWD:="${srcdir}/etc"}
     65 
     66 if [ ! -d "${setdir}" ]; then
     67 	echo >&2 "${prog}: ${setdir} is not a directory"
     68 	exit 1
     69 fi
     70 
     71 makeset()
     72 {(
     73 	set="${1}.tgz"
     74 	shift
     75 	dir="$1"
     76 	shift
     77 	intmp="/tmp/in$$"
     78 	msg "Creating ${set}"
     79 	if [ "${dir}" != "." ]; then
     80 		cd "${dir}"
     81 		srcprefix="${srcprefix}/${dir}"
     82 	fi
     83 	# Gets rid of any obj dirs and things below it 
     84 	echo "obj" > "${intmp}"
     85 	egrep="$*"
     86 	if [ "${egrep}" = "" ]; then
     87 		egrep='.'
     88 	fi
     89 	set -f
     90 	${MTREE} -c -X "${intmp}" | ${MTREE} -C -k type | \
     91 		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
     92 		${SED} -e 's:type=file:& mode=0664:' \
     93 			-e 's:type=dir:& mode=0775:' \
     94 			-e 's:$: uname=root gname=wsrc:' \
     95 			-e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \
     96 			-e '/^\.\/build.sh /s:\(mode\)=[0-9]*:\1=0775:' | \
     97 		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
     98 		${GZIP_CMD} > "${setdir}/${set}"
     99 	rm -f "${intmp}"
    100 )}
    101 
    102 
    103 # create (base)src sets
    104 #
    105 
    106 if ! cd "${srcdir}"; then
    107 	echo >&2 "${prog}: can't chdir to ${srcdir}"
    108 	exit 1
    109 fi
    110 
    111 srcprefix=usr/src
    112 export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
    113 
    114 makeset src . -v '^\.\/gnu|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config|^\.\/common'
    115 
    116 makeset gnusrc gnu
    117 
    118 makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common'
    119 
    120 makeset sharesrc share
    121 
    122 
    123 # create xsrc sets
    124 #
    125 if [ -n "${xsrcdir}" ]; then
    126 	if ! cd "${xsrcdir}"; then
    127 		echo >&2 "${prog}: can't chdir to ${xsrcdir}"
    128 		exit 1
    129 	fi
    130 	srcprefix=usr/xsrc
    131 	makeset xsrc .
    132 fi
    133 
    134 
    135 msg "Creating checksum files"
    136 (cd "${setdir}"
    137 	${CKSUM} -o1 *.tgz > BSDSUM
    138 	${CKSUM}     *.tgz > CKSUM
    139 	${CKSUM} -a md5  *.tgz > MD5
    140 	${CKSUM} -o2 *.tgz > SYSVSUM
    141 	${CKSUM} -a sha512 *.tgz > SHA512
    142 )
    143 exit 0
    144