Home | History | Annotate | Line # | Download | only in sets
regpkg revision 1.8
      1  1.1     agc #! /bin/sh
      2  1.1     agc #
      3  1.8     apb # $NetBSD: regpkg,v 1.8 2006/01/03 18:31:09 apb Exp $
      4  1.1     agc #
      5  1.1     agc # Copyright (c) 2003 Alistair G. Crooks.  All rights reserved.
      6  1.1     agc #
      7  1.1     agc # Redistribution and use in source and binary forms, with or without
      8  1.1     agc # modification, are permitted provided that the following conditions
      9  1.1     agc # are met:
     10  1.1     agc # 1. Redistributions of source code must retain the above copyright
     11  1.1     agc #    notice, this list of conditions and the following disclaimer.
     12  1.1     agc # 2. Redistributions in binary form must reproduce the above copyright
     13  1.1     agc #    notice, this list of conditions and the following disclaimer in the
     14  1.1     agc #    documentation and/or other materials provided with the distribution.
     15  1.1     agc # 3. All advertising materials mentioning features or use of this software
     16  1.1     agc #    must display the following acknowledgement:
     17  1.1     agc #	This product includes software developed by Alistair G. Crooks.
     18  1.1     agc #	for the NetBSD project.
     19  1.1     agc # 4. The name of the author may not be used to endorse or promote
     20  1.1     agc #    products derived from this software without specific prior written
     21  1.1     agc #    permission.
     22  1.1     agc #
     23  1.1     agc # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     24  1.1     agc # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     25  1.1     agc # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1     agc # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     27  1.1     agc # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1     agc # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     29  1.1     agc # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.1     agc # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     31  1.1     agc # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     32  1.1     agc # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     33  1.1     agc # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  1.1     agc #
     35  1.1     agc 
     36  1.1     agc # Usage: regpkg set pkgname
     37  1.1     agc 
     38  1.8     apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     39  1.6     erh 
     40  1.8     apb SYSPKGROOT="${PKG_DBDIR:-/var/db/pkg}"
     41  1.1     agc case "${SYSPKG_DBDIR}" in
     42  1.1     agc "")	;;
     43  1.8     apb *)	SYSPKGROOT="${SYSPKG_DBDIR}" ;;
     44  1.1     agc esac
     45  1.1     agc 
     46  1.8     apb PLIST="/tmp/.PLIST.$$"
     47  1.1     agc 
     48  1.1     agc verbose=""
     49  1.1     agc while [ $# -gt 2 ]; do
     50  1.8     apb 	case "$1" in
     51  1.8     apb 	-v)	verbose="$1" ;;
     52  1.1     agc 	*)	break ;;
     53  1.1     agc 	esac
     54  1.1     agc 	shift
     55  1.1     agc done
     56  1.1     agc 
     57  1.1     agc if [ $# -ne 2 ]; then
     58  1.1     agc 	echo "Usage: regpkg set pkgname"
     59  1.1     agc 	exit 1
     60  1.1     agc fi
     61  1.1     agc 
     62  1.8     apb pkgset="$1"
     63  1.1     agc 
     64  1.8     apb pkg="$2"
     65  1.1     agc 
     66  1.8     apb case "${verbose}" in
     67  1.8     apb -v)	echo "Making PLIST for \"${pkgset}\" set and \"${pkg}\" package" ;;
     68  1.1     agc esac
     69  1.1     agc 
     70  1.1     agc # create the skeleton PLIST from the pkgset description
     71  1.8     apb "${rundir}/makeplist" "${pkgset}" "${pkg}" > "${PLIST}"
     72  1.1     agc 
     73  1.2   jwise # create the pkg tiny version
     74  1.3     agc case "${SYSPKG_DATES}" in
     75  1.8     apb "")	tinyvers="$(${AWK} '$1 ~ '/"${pkg}"/' { print $2 }' "${rundir}/versions")"
     76  1.8     apb 	case "${tinyvers}" in
     77  1.3     agc 	"")	tinyvers=0
     78  1.3     agc 		;;
     79  1.3     agc 	esac
     80  1.3     agc 	if [ -f ../../sys/conf/osrelease.sh ]; then
     81  1.8     apb 		osvers="$(${HOST_SH} ../../sys/conf/osrelease.sh)"
     82  1.4  dyoung 		method=osreleases
     83  1.3     agc 	else
     84  1.8     apb 		osvers="$(${UNAME} -r)"
     85  1.3     agc 		method=uname
     86  1.3     agc 	fi
     87  1.8     apb 	t="${osvers}.${tinyvers}"
     88  1.3     agc 	;;
     89  1.8     apb *)	args="$(${AWK} '
     90  1.3     agc 		/^@cwd/ { prefix = $2; next }
     91  1.3     agc 		/^@dirrm/ { next }
     92  1.8     apb 		{ printf("%s%s\n", prefix, $0) }' "${PLIST}")"
     93  1.3     agc 	# first try for any RCS identifiers in the files
     94  1.3     agc 	t=0
     95  1.8     apb 	case "${args}" in
     96  1.3     agc 	"")	;;
     97  1.8     apb 	*)	t="$(${IDENT} ${args} 2>/dev/null | ${AWK} '
     98  1.3     agc 			BEGIN { last = 0 }
     99  1.3     agc 			$2 == "crt0.c,v" { next }
    100  1.3     agc 			NF == 8 { t = $4; gsub("/", "", t); if (t > last) last = t; }
    101  1.8     apb 			END { print last }')"
    102  1.3     agc 		method=ident
    103  1.3     agc 		;;
    104  1.3     agc 	esac
    105  1.8     apb 	case "${t}" in
    106  1.3     agc 	0)	# we need the last mtime of the files which make up the package
    107  1.8     apb 		t="$(${ENV_CMD} TZ=UTC LOCALE=C ${LS} -lT ${args} | ${AWK} '
    108  1.3     agc 			BEGIN { newest = 0 }
    109  1.3     agc 			{
    110  1.3     agc 				t = $9 "";
    111  1.3     agc 				if ($6 == "Jan") t = t "01";
    112  1.3     agc 				if ($6 == "Feb") t = t "02";
    113  1.3     agc 				if ($6 == "Mar") t = t "03";
    114  1.3     agc 				if ($6 == "Apr") t = t "04";
    115  1.3     agc 				if ($6 == "May") t = t "05";
    116  1.3     agc 				if ($6 == "Jun") t = t "06";
    117  1.3     agc 				if ($6 == "Jul") t = t "07";
    118  1.3     agc 				if ($6 == "Aug") t = t "08";
    119  1.3     agc 				if ($6 == "Sep") t = t "09";
    120  1.3     agc 				if ($6 == "Oct") t = t "10";
    121  1.3     agc 				if ($6 == "Nov") t = t "11";
    122  1.3     agc 				if ($6 == "Dec") t = t "12";
    123  1.3     agc 				if ($7 < 10) t = t "0";
    124  1.3     agc 				t = t $7;
    125  1.3     agc 				#these next two lines add the 24h clock onto the date
    126  1.3     agc 				#gsub(":", "", $8);
    127  1.3     agc 				#t = sprintf("%s.%4.4s", t, $8);
    128  1.3     agc 				if (t > newest) newest = t;
    129  1.3     agc 			}
    130  1.8     apb 			END { print newest }')"
    131  1.3     agc 		method=ls
    132  1.3     agc 		;;
    133  1.3     agc 	esac
    134  1.2   jwise 	;;
    135  1.2   jwise esac
    136  1.2   jwise 
    137  1.3     agc # print version number that we're using
    138  1.8     apb case "${verbose}" in
    139  1.8     apb -v)	echo "${pkg} - ${t} version using ${method} method" ;;
    140  1.3     agc esac
    141  1.1     agc 
    142  1.1     agc # create the directory and minimal contents
    143  1.8     apb SYSPKGDIR="${SYSPKGROOT}/${pkg}-${t}"
    144  1.8     apb if [ -d "${SYSPKGDIR}" ]; then
    145  1.8     apb 	echo "There is already a ${pkg}-${t} package installed (${SYSPKGDIR})"
    146  1.1     agc 	exit 1
    147  1.1     agc fi
    148  1.1     agc 
    149  1.8     apb mkdir -p "${SYSPKGDIR}"
    150  1.1     agc 
    151  1.4  dyoung # add the dependencies
    152  1.8     apb ${AWK} '$1 ~ '/"${pkg}"/' { print $2 }' "${rundir}/deps" | ${SORT} | \
    153  1.8     apb     ${AWK} '{ print "@pkgdep " $1 "-[0-9]*" }' >> "${PLIST}"
    154  1.4  dyoung 
    155  1.1     agc # create the comment
    156  1.8     apb comment="$(${AWK} '$1 ~ '/"${pkg}"/' { print substr($0, length($1) + 2) }' \
    157  1.8     apb 	"${rundir}/comments")"
    158  1.8     apb case "${comment}" in
    159  1.8     apb "")	echo "***WARNING ***: no comment for \"${pkg}\"" 2>&1
    160  1.8     apb 	comment="System package for ${pkg}"
    161  1.1     agc 	;;
    162  1.1     agc esac
    163  1.8     apb echo "${comment}" > "${SYSPKGDIR}/+COMMENT"
    164  1.1     agc 
    165  1.1     agc # create the description
    166  1.8     apb descr="$(${AWK} '$1 ~ '/"${pkg}"/' { print substr($0, length($1) + 2) }' \
    167  1.8     apb 	"${rundir}/descrs")"
    168  1.8     apb case "${descr}" in
    169  1.8     apb "")	echo "***WARNING ***: no description for \"${pkg}\"" 2>&1
    170  1.8     apb 	descr="System package for ${pkg}"
    171  1.1     agc 	;;
    172  1.1     agc esac
    173  1.8     apb echo "${descr}" > "${SYSPKGDIR}/+DESC"
    174  1.8     apb ${PRINTF} "\nHomepage:\nhttp://www.NetBSD.org/\n" >> "${SYSPKGDIR}/+DESC"
    175  1.1     agc 
    176  1.1     agc # create the build information
    177  1.8     apb if [ x"${BUILD_INFO_CACHE}" = x ]; then
    178  1.5  dyoung 	{
    179  1.8     apb 	echo "OPSYS=$(${UNAME} -s)"
    180  1.8     apb 	echo "OS_VERSION=$(${UNAME} -r)"
    181  1.7     apb 	${MAKE} -f- all <<EOF
    182  1.4  dyoung .include <bsd.own.mk>
    183  1.4  dyoung all:
    184  1.4  dyoung 	@echo OBJECT_FMT=${OBJECT_FMT}
    185  1.4  dyoung 	@echo MACHINE_ARCH=${MACHINE_ARCH}
    186  1.4  dyoung 	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
    187  1.4  dyoung EOF
    188  1.8     apb 	echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
    189  1.8     apb 	} > "${SYSPKGDIR}/+BUILD_INFO"
    190  1.5  dyoung else
    191  1.8     apb 	cp "${BUILD_INFO_CACHE}" "${SYSPKGDIR}/+BUILD_INFO"
    192  1.5  dyoung fi
    193  1.1     agc 
    194  1.1     agc # test for attributes
    195  1.1     agc args=""
    196  1.8     apb attrs="$(${AWK} '$1 ~ '/"${pkg}"/' { print substr($0, length($1) + 2) }' \
    197  1.8     apb 	"${rundir}/attrs")"
    198  1.8     apb for a in "${attrs}"; do
    199  1.8     apb 	case "${attrs}" in
    200  1.1     agc 	"")		;;
    201  1.8     apb 	preserve)	echo "${pkg}-${t}" > "${SYSPKGDIR}/+PRESERVE"
    202  1.8     apb 			args="${args} -n ${SYSPKGDIR}/+PRESERVE"
    203  1.1     agc 			;;
    204  1.1     agc 	esac
    205  1.1     agc done
    206  1.1     agc 
    207  1.8     apb ${PKG_CREATE} -v -c "${SYSPKGDIR}/+COMMENT" \
    208  1.8     apb 	-d "${SYSPKGDIR}/+DESC" \
    209  1.8     apb 	${args} \
    210  1.8     apb 	-f "${PLIST}" -l -b /dev/null -B "${SYSPKGDIR}/+BUILD_INFO" \
    211  1.8     apb 	-s /dev/null -S /dev/null -O "${pkg}-${t}.tgz" \
    212  1.8     apb 		> "${SYSPKGDIR}/+CONTENTS"
    213  1.1     agc 
    214  1.8     apb rm "${PLIST}"
    215