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