Home | History | Annotate | Line # | Download | only in sets
makesrctars revision 1.41
      1 #! /bin/sh
      2 #
      3 #	$NetBSD: makesrctars,v 1.41 2017/04/12 17:29:49 christos 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] [-y extsrcsrcdir] 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 	-y extsrcsrcdir	build extsrc.tgz from extsrcsrcdir
     29 	srcdir		location of sources
     30 	setdir		where to write the .tgz files to
     31 USAGE
     32 	exit 1
     33 }
     34 
     35 msg()
     36 {
     37 	$quiet || echo $*
     38 }
     39 
     40 
     41 # handle args
     42 while getopts N:qx:y: ch; do
     43 	case ${ch} in
     44 	q)
     45 		quiet=true
     46 		;;
     47 	x)
     48 		xsrcdir="${OPTARG}"
     49 		;;
     50 	y)
     51 		extsrcsrcdir="${OPTARG}"
     52 		;;
     53 	N)
     54 		PASSWD="${OPTARG}"
     55 		;;
     56 	*)
     57 		usage
     58 		;;
     59 	esac
     60 done
     61 shift $((${OPTIND} - 1))
     62 
     63 if [ $# -ne 2 ]; then
     64 	usage
     65 fi
     66 srcdir="$1"
     67 setdir="$2"
     68 : ${PASSWD:="${srcdir}/etc"}
     69 
     70 if [ ! -d "${setdir}" ]; then
     71 	echo >&2 "${prog}: ${setdir} is not a directory"
     72 	exit 1
     73 fi
     74 
     75 makeset()
     76 {(
     77 	set="${1}.tgz"
     78 	shift
     79 	dir="$1"
     80 	shift
     81 	intmp="/tmp/in$$"
     82 	msg "Creating ${set}"
     83 	if [ "${dir}" != "." ]; then
     84 		cd "${dir}"
     85 		srcprefix="${srcprefix}/${dir}"
     86 	fi
     87 	# Gets rid of any obj dirs and things below it 
     88 	echo "obj" > "${intmp}"
     89 	egrep="$*"
     90 	if [ "${egrep}" = "" ]; then
     91 		egrep='.'
     92 	fi
     93 	set -f
     94 	${MTREE} -c -X "${intmp}" | ${MTREE} -CS -k type | \
     95 		${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \
     96 		${SED} -e 's:type=file:& mode=0664:' \
     97 			-e 's:type=dir:& mode=0775:' \
     98 			-e 's:$: uname=root gname=wsrc:' \
     99 			-e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \
    100 			-e '/^\.\/.*[.-]sh /s:\(mode\)=[0-9]*:\1=0775:' | \
    101 		${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \
    102 		${GZIP_CMD} > "${setdir}/${set}"
    103 	rm -f "${intmp}"
    104 )}
    105 
    106 
    107 # create (base)src sets
    108 #
    109 
    110 if ! cd "${srcdir}"; then
    111 	echo >&2 "${prog}: can't chdir to ${srcdir}"
    112 	exit 1
    113 fi
    114 
    115 srcprefix=usr/src
    116 export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix
    117 
    118 makeset src . -v '^\.\/common|^\.\/external\/gpl2|^\.\/external\/gpl3|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config'
    119 
    120 makeset gnusrc . -e '^\..type=dir|^\.\/external.type=dir|^\.\/external\/gpl2|^\.\/external\/gpl3'
    121 
    122 makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common'
    123 
    124 makeset sharesrc share
    125 
    126 
    127 # create xsrc sets
    128 #
    129 if [ -n "${xsrcdir}" ]; then
    130 	if ! cd "${xsrcdir}"; then
    131 		echo >&2 "${prog}: can't chdir to ${xsrcdir}"
    132 		exit 1
    133 	fi
    134 	srcprefix=usr/xsrc
    135 	makeset xsrc .
    136 fi
    137 
    138 
    139 # create extsrc sets
    140 #
    141 if [ -n "${extsrcsrcdir}" ]; then
    142 	if ! cd "${extsrcsrcdir}"; then
    143 		echo >&2 "${prog}: can't chdir to ${extsrcsrcdir}"
    144 		exit 1
    145 	fi
    146 	srcprefix=usr/extsrc
    147 	makeset extsrc .
    148 fi
    149 
    150 
    151 msg "Creating checksum files"
    152 (cd "${setdir}"
    153 	${CKSUM} -a md5  *.tgz > MD5
    154 	${CKSUM} -a sha512 *.tgz > SHA512
    155 )
    156 exit 0
    157