1 #! /bin/sh 2 # 3 # $NetBSD: makesrctars,v 1.15.2.4 2005/10/21 05:49:48 riz 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 # handle args 35 while getopts N:x: ch; do 36 case ${ch} in 37 x) 38 xsrcdir=${OPTARG} 39 ;; 40 N) 41 PASSWD=${OPTARG} 42 ;; 43 *) 44 usage 45 ;; 46 esac 47 done 48 shift $((${OPTIND} - 1)) 49 50 if [ $# -ne 2 ]; then 51 usage 52 fi 53 srcdir=$1 54 setdir=$2 55 : ${PASSWD:=${srcdir}/etc} 56 57 if [ ! -d "${setdir}" ]; then 58 echo "${setdir} is not a directory" 59 exit 1 60 fi 61 62 makeset() 63 {( 64 set=$1.tgz 65 shift 66 dir=$1 67 shift 68 echo "Creating ${set}" 69 if [ "${dir}" != "." ]; then 70 cd $dir 71 srcprefix="${srcprefix}/${dir}" 72 fi 73 # Gets rid of any obj dirs and things below it 74 echo "obj" > /tmp/in$$ 75 egrep=$* 76 if [ "$egrep" = "" ]; then 77 egrep='.' 78 fi 79 set -f 80 ${MTREE} -c -X /tmp/in$$ | ${MTREE} -C -k type | \ 81 egrep -v 'type=link' | egrep $egrep | \ 82 sed -e 's:type=file:& mode=0664:' \ 83 -e 's:type=dir:& mode=0775:' \ 84 -e 's:$: uname=root gname=wsrc:' | \ 85 ${PAX} -M -N ${PASSWD} -w -d -s'|^\.|'${srcprefix}'|' | \ 86 gzip > "${setdir}/${set}" 87 rm -f /tmp/in$$ 88 )} 89 90 91 # create (base)src sets 92 # 93 94 if ! cd "${srcdir}"; then 95 echo "Can't chdir to ${srcdir}" 96 exit 1 97 fi 98 99 srcprefix=usr/src 100 export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix 101 102 makeset src . \ 103 -v '^\.\/gnu|^\.\/share|^\.\/sys|^\.\/contrib\.sys|^\.\/usr\.bin\/config' 104 105 makeset gnusrc gnu 106 107 makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/contrib.type=dir|^\.\/contrib\/sys|^\.\/usr\.sbin.type=dir|^\.\/usr\.sbin\/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} -m *.tgz > MD5 129 ${CKSUM} -o2 *.tgz > SYSVSUM 130 ) 131 exit 0 132