From e52ed3f67f6adafb48046382cc30482d0ef933d5 Mon Sep 17 00:00:00 2001 From: jmmv Date: Fri, 17 Feb 2017 21:27:38 +0000 Subject: Initial addition of pkgtools/pkg_comp-cron, version 1.0: This package sets up periodic builds of binary packages using the pkgtools/pkg_comp utility given minimal configuration. All that is needed from the user is to determine which packages to build automatically. If you are on NetBSD, see also sysutils/sysbuild-user, which is the perfect companion to this package to periodically build the base system. --- pkgtools/Makefile | 3 +- pkgtools/pkg_comp-cron/DESCR | 7 +++ pkgtools/pkg_comp-cron/INSTALL | 81 +++++++++++++++++++++++++++++ pkgtools/pkg_comp-cron/MESSAGE | 27 ++++++++++ pkgtools/pkg_comp-cron/Makefile | 78 +++++++++++++++++++++++++++ pkgtools/pkg_comp-cron/PLIST | 3 ++ pkgtools/pkg_comp-cron/files/files.new | Bin 0 -> 513 bytes pkgtools/pkg_comp-cron/files/list.txt | 11 ++++ pkgtools/pkg_comp-cron/files/pkg_comp.conf | 29 +++++++++++ 9 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 pkgtools/pkg_comp-cron/DESCR create mode 100644 pkgtools/pkg_comp-cron/INSTALL create mode 100644 pkgtools/pkg_comp-cron/MESSAGE create mode 100644 pkgtools/pkg_comp-cron/Makefile create mode 100644 pkgtools/pkg_comp-cron/PLIST create mode 100644 pkgtools/pkg_comp-cron/files/files.new create mode 100644 pkgtools/pkg_comp-cron/files/list.txt create mode 100644 pkgtools/pkg_comp-cron/files/pkg_comp.conf (limited to 'pkgtools') diff --git a/pkgtools/Makefile b/pkgtools/Makefile index b4717031142..3871076c717 100644 --- a/pkgtools/Makefile +++ b/pkgtools/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.116 2017/02/17 21:25:46 jmmv Exp $ +# $NetBSD: Makefile,v 1.117 2017/02/17 21:27:38 jmmv Exp $ # COMMENT= Tools for use in the packages collection @@ -35,6 +35,7 @@ SUBDIR+= pkg SUBDIR+= pkg_alternatives SUBDIR+= pkg_chk SUBDIR+= pkg_comp +SUBDIR+= pkg_comp-cron SUBDIR+= pkg_comp1 SUBDIR+= pkg_distinst SUBDIR+= pkg_filecheck diff --git a/pkgtools/pkg_comp-cron/DESCR b/pkgtools/pkg_comp-cron/DESCR new file mode 100644 index 00000000000..3e3d9c98a7e --- /dev/null +++ b/pkgtools/pkg_comp-cron/DESCR @@ -0,0 +1,7 @@ +This package sets up periodic builds of binary packages using the +pkgtools/pkg_comp utility given minimal configuration. All that is +needed from the user is to determine which packages to build +automatically. + +If you are on NetBSD, see also sysutils/sysbuild-user, which is the +perfect companion to this package to periodically build the base system. diff --git a/pkgtools/pkg_comp-cron/INSTALL b/pkgtools/pkg_comp-cron/INSTALL new file mode 100644 index 00000000000..f5d0ef1f5f1 --- /dev/null +++ b/pkgtools/pkg_comp-cron/INSTALL @@ -0,0 +1,81 @@ +#! /bin/sh + +BUILDBASE="@BUILDBASE@" +EGDIR="@EGDIR@" +PKG_COMP_HOME="@PKG_COMP_HOME@" +PKG_COMP_USER="@PKG_COMP_USER@" +PKG_COMP_EGDIR="@PKG_COMP_EGDIR@" +SANDBOXCTL_EGDIR="@SANDBOXCTL_EGDIR@" + +# Regexp to match our crontab entry. +CRONTAB_RE="${PREFIX}/sbin/pkg_comp4cron .*${BUILDBASE}/pkg_comp.conf" + +# Dumps the pkg_comp user's crontab to a temporary file and outputs +# the path to the file. If the crontab does not exist, populates +# the output with some basic contents. +get_crontab() { + local tempfile="$(mktemp "${TMPDIR:-/tmp}/pkg_comp.XXXXXX")" + if ! crontab -u "${PKG_COMP_USER}" -l >>"${tempfile}"; then + cat >>"${tempfile}" </dev/null; then + echo "@daily ${PREFIX}/sbin/pkg_comp4cron -l \"${BUILDBASE}/log\"" \ + "-- -c \"${BUILDBASE}/pkg_comp.conf\" auto" \ + >>"${tempfile}" + crontab -u "${PKG_COMP_USER}" - <"${tempfile}" + echo "pkg_comp daily entry added to ${PKG_COMP_USER}'s crontab" + fi + rm -f "${tempfile}" +} + +# Removes the previously-configured crontab entry by this package. +uninstall_crontab() { + local tempfile; tempfile="$(get_crontab)" || return + if grep "${CRONTAB_RE}" "${tempfile}" >/dev/null; then + local tempfile2="$(mktemp "${TMPDIR:-/tmp}/pkg_comp.XXXXXX")" + grep -v "${CRONTAB_RE}" "${tempfile}" >>"${tempfile2}" + if [ -s "${tempfile2}" ]; then + crontab -u "${PKG_COMP_USER}" "${tempfile2}" + else + crontab -u "${PKG_COMP_USER}" -r + fi + echo "pkg_comp daily entry removed from ${PKG_COMP_USER}'s crontab" + rm -f "${tempfile2}" + fi + rm -f "${tempfile}" +} + +case "${STAGE}" in + POST-INSTALL) + if [ ! -e "${PKG_COMP_HOME}/sandbox.conf" ]; then + echo "${PKGNAME}: Installing sample sandbox.conf file" + ${MKDIR} -p "${PKG_COMP_HOME}" + sed "s,^SANDBOX_ROOT=.*$,SANDBOX_ROOT=${PKG_COMP_HOME}/sandbox," \ + "${SANDBOXCTL_EGDIR}/default.conf" \ + >"${PKG_COMP_HOME}/sandbox.conf" + fi + + if [ ! -e "${PKG_COMP_HOME}/extra.mk.conf" ]; then + echo "${PKGNAME}: Installing sample extra.mk.conf file" + ${MKDIR} -p "${PKG_COMP_HOME}" + cp "${PKG_COMP_EGDIR}/extra.mk.conf" "${PKG_COMP_HOME}/" + fi + + install_crontab + ;; + + DEINSTALL) + uninstall_crontab + ;; +esac diff --git a/pkgtools/pkg_comp-cron/MESSAGE b/pkgtools/pkg_comp-cron/MESSAGE new file mode 100644 index 00000000000..eba3fdbeca3 --- /dev/null +++ b/pkgtools/pkg_comp-cron/MESSAGE @@ -0,0 +1,27 @@ +=========================================================================== +$NetBSD: MESSAGE,v 1.1 2017/02/17 21:27:38 jmmv Exp $ + +The system has been configured to perform daily rebuilds of packages for +the current platform. Please take the time to review the following files: + + ${PKG_COMP_HOME}/extra.mk.conf + ${PKG_COMP_HOME}/list.txt + ${PKG_COMP_HOME}/pkg_comp.conf + ${PKG_COMP_HOME}/sandbox.conf + +At the very minimum, you will have to modify the list.txt file to specify +the set of packages you want to build. + +Make sure to review that the changes to the ${PKG_COMP_USER}'s crontab(5) +are correct and that the chosen schedule suits your needs. + +Built binary packages can be used by setting: + + PKG_PATH=file://${PKG_COMP_HOME}/packages/All + +Lastly, remember that you can trigger manual pkg_comp operations by doing: + + su - ${PKG_COMP_USER} ${PREFIX}/sbin/pkg_comp \ + -c ${PKG_COMP_HOME}/pkg_comp.conf + +=========================================================================== diff --git a/pkgtools/pkg_comp-cron/Makefile b/pkgtools/pkg_comp-cron/Makefile new file mode 100644 index 00000000000..dbad45cab57 --- /dev/null +++ b/pkgtools/pkg_comp-cron/Makefile @@ -0,0 +1,78 @@ +# $NetBSD: Makefile,v 1.1 2017/02/17 21:27:38 jmmv Exp $ + +DISTNAME= pkg_comp-cron-1.0 +CATEGORIES= pkgtools +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= jmmv@NetBSD.org +COMMENT= Configures periodic pkgsrc binary package builds +LICENSE= modified-bsd + +DEPENDS= pkg_comp>=2.0:../../pkgtools/pkg_comp + +BUILD_DEFS= VARBASE +DEINSTALL_TEMPLATES= INSTALL +NO_CHECKSUM= yes +NO_CONFIGURE= yes +WRKSRC= ${WRKDIR} + +PKG_COMP_USER?= ${REAL_ROOT_USER} +PKG_COMP_GROUP?= ${REAL_ROOT_GROUP} +PKG_COMP_HOME?= ${VARBASE}/pkg_comp + +EGDIR= ${PREFIX}/share/examples/pkg_comp-cron +OWN_DIRS_PERMS= ${PKG_COMP_HOME} ${PKG_COMP_USER} ${PKG_COMP_GROUP} 755 +CONF_FILES= ${EGDIR}/list.txt ${PKG_COMP_HOME}/list.txt +CONF_FILES+= ${EGDIR}/pkg_comp.conf ${PKG_COMP_HOME}/pkg_comp.conf + +BUILD_SUBST+= -e 's,@BUILDBASE@,${PKG_COMP_HOME},g' +BUILD_SUBST+= -e 's,@EGDIR@,${EGDIR},g' +BUILD_SUBST+= -e 's,@PKG_COMP_EGDIR@,${PREFIX}/share/examples/pkg_comp,g' +BUILD_SUBST+= -e 's,@PREFIX@,${PREFIX},g' +FILES_SUBST+= BUILDBASE=${PKG_COMP_HOME} +FILES_SUBST+= EGDIR=${EGDIR} +FILES_SUBST+= PKG_COMP_HOME=${PKG_COMP_HOME} +FILES_SUBST+= PKG_COMP_USER=${PKG_COMP_USER} +FILES_SUBST+= PKG_COMP_EGDIR=${PREFIX}/share/examples/pkg_comp +FILES_SUBST+= SANDBOXCTL_EGDIR=${PREFIX}/share/examples/sandboxctl +MESSAGE_SUBST+= EGDIR=${EGDIR} +MESSAGE_SUBST+= PKG_COMP_HOME=${PKG_COMP_HOME} +MESSAGE_SUBST+= PKG_COMP_USER=${PKG_COMP_USER} + +.include "../../mk/bsd.prefs.mk" + +# Configure the default pkg_comp.conf on a platform basis, providing +# reasonable defaults. The user has to review the installed file anyway +# so it is not strictly necessary to make these "perfect" -- but good +# defaults will help in getting started. +.if ${OPSYS} == "Darwin" +# Xcode ships with git only, not cvs, so default to git to simplify the +# bootstrapping process. +BUILD_SUBST+= -e 's,@FETCH_VCS@,git,g' +# Since macOS Sierra (11.12), /usr is a protected tree to which apps +# cannot write even as root. Default to somewhere else; because pkg_comp +# requires privileges to run, /opt/pkg is a reasonable location. +BUILD_SUBST+= -e 's,@LOCALBASE@,/opt/pkg,g' +BUILD_SUBST+= -e 's,@SYSCONFDIR@,/opt/pkg/etc,g' +BUILD_SUBST+= -e 's,@VARBASE@,/opt/pkg/var,g' +.else +BUILD_SUBST+= -e 's,@FETCH_VCS@,cvs,g' +BUILD_SUBST+= -e 's,@LOCALBASE@,/usr/pkg,g' +BUILD_SUBST+= -e 's,@SYSCONFDIR@,/etc,g' +BUILD_SUBST+= -e 's,@VARBASE@,/var,g' +.endif + +INSTALLATION_DIRS= share/examples/pkg_comp-cron + +do-build: +.for file in list.txt pkg_comp.conf + ${SED} ${BUILD_SUBST} <${FILESDIR}/${file} >${WRKSRC}/${file} +.endfor + +do-install: +.for file in list.txt pkg_comp.conf + ${INSTALL_DATA} ${WRKSRC}/${file} ${DESTDIR}${EGDIR}/ +.endfor + +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/pkg_comp-cron/PLIST b/pkgtools/pkg_comp-cron/PLIST new file mode 100644 index 00000000000..146af2a6bb1 --- /dev/null +++ b/pkgtools/pkg_comp-cron/PLIST @@ -0,0 +1,3 @@ +@comment $NetBSD: PLIST,v 1.1 2017/02/17 21:27:38 jmmv Exp $ +share/examples/pkg_comp-cron/list.txt +share/examples/pkg_comp-cron/pkg_comp.conf diff --git a/pkgtools/pkg_comp-cron/files/files.new b/pkgtools/pkg_comp-cron/files/files.new new file mode 100644 index 00000000000..aff218925b1 Binary files /dev/null and b/pkgtools/pkg_comp-cron/files/files.new differ diff --git a/pkgtools/pkg_comp-cron/files/list.txt b/pkgtools/pkg_comp-cron/files/list.txt new file mode 100644 index 00000000000..585dcaa7f50 --- /dev/null +++ b/pkgtools/pkg_comp-cron/files/list.txt @@ -0,0 +1,11 @@ +# Packages to build automatically during the periodic runs. +# +# List one package per line, using bare names or the category/name syntax. + +#shells/dash +#tmux + +# Don't forget to list pkg_comp-cron itself if you are building packages +# for this same machine! Otherwise, rebootstrapping your system +# configuration will require additional manual steps. +#pkg_comp-cron diff --git a/pkgtools/pkg_comp-cron/files/pkg_comp.conf b/pkgtools/pkg_comp-cron/files/pkg_comp.conf new file mode 100644 index 00000000000..feeb99a7614 --- /dev/null +++ b/pkgtools/pkg_comp-cron/files/pkg_comp.conf @@ -0,0 +1,29 @@ +# $NetBSD: pkg_comp.conf,v 1.1 2017/02/17 21:27:38 jmmv Exp $ + +# pkg_comp.conf(5) configuration file for unattended pkgsrc builds. + +# Remote VCS configuration. +FETCH_VCS=@FETCH_VCS@ +#CVS_ROOT=:ext:anoncvs@anoncvs.NetBSD.org:/cvsroot +#CVS_TAG=pkgsrc-2017Q1 +#GIT_URL=https://github.com/jsonn/pkgsrc.git +#GIT_BRANCH=trunk + +# Host file layout. +PKGSRCDIR="@BUILDBASE@/pkgsrc" +DISTDIR="@BUILDBASE@/distfiles" +PACKAGES="@BUILDBASE@/packages" +PBULK_PACKAGES="@BUILDBASE@/pbulk-packages" +EXTRA_MKCONF="@BUILDBASE@/extra.mk.conf" +SANDBOX_CONFFILE="@BUILDBASE@/sandbox.conf" + +# Target file layout. +LOCALBASE="@LOCALBASE@" +PKG_DBDIR="${LOCALBASE}/libdata/pkgdb" +SYSCONFDIR="@SYSCONFDIR@" +VARBASE="@VARBASE@" + +# List of packages to build during automatic execution. We source these +# from a separate file for simplicity, as maintaining a long list of +# package names in a shell variable can be cumbersome. +AUTO_PACKAGES="$(grep -v '^#' '@BUILDBASE@/list.txt')" -- cgit v1.2.3