1 #! /bin/sh 2 # 3 # $NetBSD: makesrctars,v 1.44 2022/08/21 07:10:03 lukem 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. Also skip 84 # .hg or .git repositories (if we got the source via git 85 # or mercurial) 86 printf "obj\n./.git\n./.hg\n" > "${intmp}" 87 egrep="$*" 88 if [ "${egrep}" = "" ]; then 89 egrep='.' 90 fi 91 set -f 92 ${MTREE} -c -X "${intmp}" | ${MTREE} -CS -k type | \ 93 ${EGREP} -v 'type=link' | ${EGREP} ${egrep} | \ 94 ${SED} -e 's:type=file:& mode=0664:' \ 95 -e 's:type=dir:& mode=0775:' \ 96 -e 's:$: uname=root gname=wsrc:' \ 97 -e '/\/move-if-change /s:\(mode\)=[0-9]*:\1=0775:' \ 98 -e '/^\.\/.*[.-]sh /s:\(mode\)=[0-9]*:\1=0775:' | \ 99 ${PAX} -M -N "${PASSWD}" -w -d -s'|^\.|'"${srcprefix}"'|' | \ 100 ${GZIP_CMD} > "${setdir}/${set}" 101 rm -f "${intmp}" 102 )} 103 104 105 # create (base)src sets 106 # 107 108 if ! cd "${srcdir}"; then 109 echo >&2 "${prog}: can't chdir to ${srcdir}" 110 exit 1 111 fi 112 113 srcprefix=usr/src 114 export setdir MTREE PAX CKSUM GZIP PASSWD srcprefix 115 116 makeset src . -v '^\.\/common|^\.\/external\/gpl2|^\.\/external\/gpl3|^\.\/share|^\.\/sys|^\.\/usr\.bin\/config' 117 118 makeset gnusrc . -e '^\..type=dir|^\.\/external.type=dir|^\.\/external\/gpl2|^\.\/external\/gpl3' 119 120 makeset syssrc . -e '^\..type=dir|^\.\/sys|^\.\/usr\.bin.type=dir|^\.\/usr\.bin\/config|^\.\/common' 121 122 makeset sharesrc share 123 124 125 # create xsrc sets 126 # 127 if [ -n "${xsrcdir}" ]; then 128 if ! cd "${xsrcdir}"; then 129 echo >&2 "${prog}: can't chdir to ${xsrcdir}" 130 exit 1 131 fi 132 srcprefix=usr/xsrc 133 makeset xsrc . 134 fi 135 136 137 msg "Creating checksum files" 138 (cd "${setdir}" 139 ${CKSUM} -a md5 *.tgz *.tar.xz > MD5 140 ${CKSUM} -a sha512 *.tgz *.tar.xz > SHA512 141 ) 142 exit 0 143