Home | History | Annotate | Line # | Download | only in sets
makesrctars revision 1.25
      1 #! /bin/sh
      2 #
      3 #	$NetBSD: makesrctars,v 1.25 2005/10/21 02:56:27 jmc Exp $
      4 #
      5 # makesrctars srcdir setdir
      6 #	Create source tarballs in setdir from the source under srcdir.
      7 #
      8 
      9 prog=${0##*/}
     10 
     11 # set defaults
     12 : ${CKSUM:=cksum}
     13 : ${MTREE:=/usr/sbin/mtree}
     14 : ${PAX:=pax}
     15 
     16 xsrcdir=
     17 
     18 GZIP=-9
     19 export GZIP
     20 
     21 usage()
     22 {
     23 	cat 1>&2 <<USAGE
     24 Usage: ${prog} [-N password/group dir] [-x xsrcdir] srcdir setdir
     25 	-N dir		location which contains master.passwd and group files
     26 			(defaults to ${srcdir}/etc)
     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 PASSWD=
     35 # handle args
     36 while getopts N:x: ch; do
     37 	case ${ch} in
     38 	x)	
     39 		xsrcdir=${OPTARG}
     40 		;;
     41 	N)
     42 		PASSWD=${OPTARG}
     43 		;;
     44 	*)
     45 		usage
     46 		;;
     47 	esac
     48 done
     49 shift $((${OPTIND} - 1))
     50 
     51 if [ $# -ne 2 ]; then
     52 	usage
     53 fi
     54 srcdir=$1
     55 setdir=$2
     56 : ${PASSWD:=${srcdir}/etc}
     57 
     58 if [ ! -d "${setdir}" ]; then
     59 	echo "${setdir} is not a directory"
     60 	exit 1
     61 fi
     62 
     63 makeset()
     64 {(
     65 	set=$1.tgz
     66 	shift
     67 	dir=$1
     68 	shift
     69 	echo "Creating ${set}"
     70 	if [ "${dir}" != "." ]; then
     71 		cd $dir
     72 		srcprefix="${srcprefix}/${dir}"
     73 	fi
     74 	# Gets rid of any obj dirs and things below it 
     75 	echo "obj" > /tmp/in$$
     76 	egrep=$*
     77 	if [ "$egrep" = "" ]; then
     78 	    egrep='.'
     79 	fi
     80 	set -f
     81 	${MTREE} -c -X /tmp/in$$ | ${MTREE} -C -k type | \
     82 		egrep -v 'type=link' | egrep $egrep | \
     83 		sed -e 's:type=file:& mode=0664:' \
     84 			-e 's:type=dir:& mode=0775:' \
     85 			-e 's:$: uname=root gname=wsrc:' | \
     86 		${PAX} -M -N ${PASSWD} -w -d -s'|^\.|'${srcprefix}'|' | \
     87 		gzip > "${setdir}/${set}"
     88 	rm -f /tmp/in$$
     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'
    104 
    105 makeset gnusrc gnu
    106 
    107 makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config'
    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