diff options
author | agc <agc@pkgsrc.org> | 2005-04-20 09:36:00 +0000 |
---|---|---|
committer | agc <agc@pkgsrc.org> | 2005-04-20 09:36:00 +0000 |
commit | 3375751ac4d45a86aa41328b9f3db9a1483832ca (patch) | |
tree | 3490b2eeee6d0ac026bcdfea4bb65d285a8cd7a0 /pkgtools/genrpm | |
parent | 81663f4f91940760f6e2461210416582cf7e173d (diff) | |
download | pkgsrc-3375751ac4d45a86aa41328b9f3db9a1483832ca.tar.gz |
Initial import of genrpm-1.0, a tool to generate rpm packages.
This package installs a script called genrpm, which is used to
generate a Redhat Package Manager (RPM) package from an installed
pkgsrc package. It does this by generating a spec file, and using
that to identify the components of the RPM and package them.
If a pkgsrc tree is present on the system, a source RPM (or srpm)
can also be generated. This will include the distfile, any pkgsrc
patches, and the files used to accomplish the pkgsrc packaging.
Diffstat (limited to 'pkgtools/genrpm')
-rw-r--r-- | pkgtools/genrpm/DESCR | 8 | ||||
-rw-r--r-- | pkgtools/genrpm/Makefile | 41 | ||||
-rw-r--r-- | pkgtools/genrpm/PLIST | 4 | ||||
-rw-r--r-- | pkgtools/genrpm/files/genrpm | 306 | ||||
-rw-r--r-- | pkgtools/genrpm/files/genrpm.0 | 37 | ||||
-rw-r--r-- | pkgtools/genrpm/files/genrpm.8 | 60 |
6 files changed, 456 insertions, 0 deletions
diff --git a/pkgtools/genrpm/DESCR b/pkgtools/genrpm/DESCR new file mode 100644 index 00000000000..7b796c3d930 --- /dev/null +++ b/pkgtools/genrpm/DESCR @@ -0,0 +1,8 @@ +This package installs a script called genrpm, which is used to +generate a Redhat Package Manager (RPM) package from an installed +pkgsrc package. It does this by generating a spec file, and using +that to identify the components of the RPM and package them. + +If a pkgsrc tree is present on the system, a source RPM (or srpm) +can also be generated. This will include the distfile, any pkgsrc +patches, and the files used to accomplish the pkgsrc packaging. diff --git a/pkgtools/genrpm/Makefile b/pkgtools/genrpm/Makefile new file mode 100644 index 00000000000..7fdf215cbcb --- /dev/null +++ b/pkgtools/genrpm/Makefile @@ -0,0 +1,41 @@ +# $NetBSD: Makefile,v 1.1.1.1 2005/04/20 09:36:00 agc Exp $ + +DISTNAME= genrpm-1.0 +CATEGORIES= pkgtools +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= agc@NetBSD.org +HOMEPAGE= http://www.pkgsrc.org/ +COMMENT= Generate an RPM package from an installed pkgsrc package + +DEPENDS+= pkg_tarup-[0-9]*:../../pkgtools/pkg_tarup +DEPENDS+= rpm-[0-9]*:../../misc/rpm + +PKG_INSTALLATION_TYPES= overwrite pkgviews + +WRKSRC= ${WRKDIR} +NO_CHECKSUM= yes + +INSTALLATION_DIRS= man/cat8 man/man8 sbin + +.include "../../mk/bsd.prefs.mk" + +do-build: + @for f in genrpm genrpm.8 genrpm.0; do \ + ${SED} -e 's|@PKGSRCDIR@|${PKGSRCDIR}|g' \ + -e 's|@SH@|${SH}|g' \ + ${FILESDIR}/$$f > ${WRKSRC}/$$f; \ + done +.if ${OPSYS} == "SunOS" || ${OPSYS} == "AIX" + # pre-created man-pages are "mandoc" pages, these OS need "man", + # so regen the .0 page + nroff -man ${WRKSRC}/genrpm.8 >${WRKSRC}/genrpm.0 +.endif + +do-install: + ${INSTALL_SCRIPT} ${WRKSRC}/genrpm ${PREFIX}/sbin + ${INSTALL_MAN} ${WRKSRC}/genrpm.0 ${PREFIX}/man/cat8 + ${INSTALL_MAN} ${WRKSRC}/genrpm.8 ${PREFIX}/man/man8 + +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/genrpm/PLIST b/pkgtools/genrpm/PLIST new file mode 100644 index 00000000000..cc5ff676cac --- /dev/null +++ b/pkgtools/genrpm/PLIST @@ -0,0 +1,4 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2005/04/20 09:36:00 agc Exp $ +man/cat8/genrpm.0 +man/man8/genrpm.8 +sbin/genrpm diff --git a/pkgtools/genrpm/files/genrpm b/pkgtools/genrpm/files/genrpm new file mode 100644 index 00000000000..9b6bdbdd134 --- /dev/null +++ b/pkgtools/genrpm/files/genrpm @@ -0,0 +1,306 @@ +#! @SH@ + +# $NetBSD: genrpm,v 1.1.1.1 2005/04/20 09:36:00 agc Exp $ + +# +# Copyright © 2005 Alistair G. Crooks. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by Alistair G. Crooks +# 4. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# small shell script to convert from an installed NetBSD package to an rpm +# +# Usage: pkg2rpm [--distdir=distdir] [--objdir=objdir] [--rpmdir=rpmdir] [--srpmdir=srpmdir] [--sign] [-s] [-v] pkgname + +# find a program and set a global variable with its path +check_prog() +{ + _var="$1"; _name="$2" + + eval _tmp=\"\$$_var\" + if [ "x$_tmp" != "x" ]; then + # Variable is already set (by the user, for example) + return 0 + fi + + for _d in `echo $PATH | tr ':' ' '`; do + if [ -x "$_d/$_name" ]; then + # Program found + eval $_var=\""$_d/$_name"\" + return 1 + fi + done + + eval $_var=\"""\" +} + +# our definitions +DISTVENDOR=${DISTVENDOR:-"pkgsrc/genrpm"} +DISTRIBUTION=${DISTRIBUTION:-"pkgsrc genrpm `date +%Y%m%d`"} + +# program definitions +check_prog awk_cmd awk +check_prog cp_cmd cp +check_prog gzip_cmd gzip +check_prog ln_cmd ln +check_prog ls_cmd ls +check_prog mkdir_cmd mkdir +check_prog mv_cmd mv +check_prog pkg_info_cmd pkg_info +check_prog rm_cmd rm +check_prog sed_cmd sed +check_prog tar_cmd tar + +extract_cmd="${tar_cmd} xf -" + +# find the right name for make(1) +opsys=`uname -s | tr -d /` +case "${opsys}" in +NetBSD) check_prog bmake_cmd make ;; +*) check_prog bmake_cmd bmake ;; +esac + +# set defaults +DISTDIR=${DISTDIR:-@PKGSRCDIR@/distfiles} +objdir=/usr/obj +rpmdir=@PKGSRCDIR@/packages/rpms +srpmdir=@PKGSRCDIR@/packages/srpms + +PKG_DBDIR=${PKG_DBDIR:-/var/db/pkg} +PKGSRC=${PKGSRC:-@PKGSRCDIR@} + +verbose="" # by default, quiet running +sign="" # by default, no signature +genpat="-bb" # by default, just create a binary rpm + +# and the immutables +redhatdir=/usr/pkg/src/redhat +reqpkgs="pkg_tarup rpm" +metafiles="+BUILD_INFO +BUILD_VERSION +COMMENT +CONTENTS +DESC +SIZE_ALL +SIZE_PKG" + +# check any given args +while [ $# -gt 0 ]; do + case "$1" in + --distdir=*) DISTDIR=`echo "$1" | ${sed_cmd} -e 's|--distdir=||'` ;; + --objdir=*) objdir=`echo "$1" | ${sed_cmd} -e 's|--objdir=||'` ;; + --rpmdir=*) rpmdir=`echo "$1" | ${sed_cmd} -e 's|--rpmdir=||'` ;; + --srpmdir=*) srpmdir=`echo "$1" | ${sed_cmd} -e 's|--srpmdir=||'` ;; + --sign) sign="$1" ;; + -s) genpat="-ba" ;; + -v) verbose="-v"; set -x ;; + *) break ;; + esac + shift +done + +# check canonical directories are there on NetBSD +if [ ! -d $redhatdir ]; then + ${mkdir_cmd} -p $redhatdir + (cd $redhatdir && ${ln_cmd} -s $objdir/rpm BUILD) + (cd $redhatdir && ${ln_cmd} -s $rpmdir RPMS) + (cd $redhatdir && ${ln_cmd} -s $srpmdir SRPMS) + (cd $redhatdir && ${ln_cmd} -s $objdir/rpm/SOURCES SOURCES) +fi + +# check that we have required packages installed +for p in $reqpkgs; do + if ${pkg_info_cmd} -qe $p; then + echo "Using $p version `${pkg_info_cmd} -e $p`" + else + echo "The $p needs to be installed to use this rpm generator" 2>&1 + exit 1 + fi +done + +# generate an rpm for each package +while [ $# -gt 0 ]; do + if ${pkg_info_cmd} -qe "$1"; then + + # expand the package name to include version information + name=`${pkg_info_cmd} -e $1` + + # 3 components to package's name + pkgbase=`echo $name | ${sed_cmd} -e 's|-[0-9].*||'` + case "$name" in + *-[0-9]*nb*) + pkgversion=`echo $name | ${sed_cmd} -e 's|\(.*\)-\([0-9].*\)\(nb[0-9]*\)|\2|'` + nb=`echo $name | ${sed_cmd} -e 's|\(.*\)-\([0-9].*\)nb\([0-9]*\)|\3|'` + ;; + *) + pkgversion=`echo $name | ${sed_cmd} -e 's|\(.*\)-\([0-9].*\)|\2|'` + nb=0 + ;; + esac + + # retrieve information on prefix and pkgsrc directory from the package + pkgprefix=`${pkg_info_cmd} -qp $name | ${awk_cmd} '{ print $2; exit }'` + pkgpath=`${pkg_info_cmd} -B $name | ${awk_cmd} '/^PKGPATH=/ { sub("PKGPATH=", ""); print }'` + pkgname=$pkgbase-$pkgversion + + # generate the rpm spec file first + echo "Making an rpm spec file for $name - $pkgname - ($pkgbase-$pkgversion-$nb)" + + # make the build root + ${mkdir_cmd} -p $objdir/rpm/BUILD/$pkgname/$pkgprefix + + # make the single source directory + ${mkdir_cmd} -p $objdir/rpm/SOURCES + + # define the build directory + builddir=$objdir/rpm/BUILD/$pkgname + sourcesdir=$objdir/rpm/SOURCES/$pkgname + + # create the specfile in the right place + specfile=$builddir/$pkgbase.spec + + echo "%define name $pkgbase" > $specfile + echo "%define version $pkgversion" >> $specfile + echo "%define release $nb" >> $specfile + echo "%define prefix $pkgprefix" >> $specfile + echo "" >> $specfile + echo "" >> $specfile + + echo "Summary: %{name}, `${pkg_info_cmd} -qc $name`" >> $specfile + echo "Name: %{name}" >> $specfile + echo "Version: %{version}" >> $specfile + echo "Release: %{release}" >> $specfile + echo "Copyright: unknown" >> $specfile + echo "URL: `${pkg_info_cmd} -d $name | ${awk_cmd} '/^Homepage:/ { getline; print; exit }'`" >> $specfile + echo "Packager: Alistair Crooks <genrpm@alistaircrooks.com>" >> $specfile + echo "Distribution: ${DISTRIBUTION}" >> $specfile + echo "Vendor: ${DISTVENDOR}" >> $specfile + echo "Prefix: ${pkgprefix}" >> $specfile + for p in "" `${pkg_info_cmd} -qn $name`; do + case "$p" in + "") continue ;; + *) case "$p" in + *-[0-9]*) p=`echo "$p" | ${sed_cmd} -e 's|\(.*\)-\([0-9].*\)|\1=\2|'` ;; + esac + case "$p" in + *nb[0-9]*) p=`echo "$p" | ${sed_cmd} -e 's|\(.*\)nb\([0-9]*\)|\1-\2|'` ;; + esac + echo "Requires: $p" >> $specfile ;; + esac + done + for p in "" `${pkg_info_cmd} -qv $name | ${awk_cmd} '/conflicts with/ { print $4 }'`; do + case "$p" in + "") continue ;; + *) case "$p" in + *-[0-9]*) p=`echo "$p" | ${sed_cmd} -e 's|\(.*\)-\([0-9].*\)|\1=\2|'` ;; + esac + case "$p" in + *nb[0-9]*) p=`echo "$p" | ${sed_cmd} -e 's|\(.*\)nb\([0-9]*\)|\1-\2|'` ;; + esac + echo "Conflicts: $p" >> $specfile ;; + esac + done + + echo "Buildroot: $builddir" >> $specfile + echo "Group: $pkgpath" >> $specfile + srcs="`${pkg_info_cmd} -Q _DISTFILES $name`" + case "$srcs" in + "") srcs="`cd $PKGSRC/$pkgpath && ${bmake_cmd} show-var VARNAME=_DISTFILES`" ;; + esac + i=0 + for f in "" $srcs; do + case "$f" in + "") continue ;; + *) echo "Source$i: $f" >> $specfile + ${cp_cmd} $DISTDIR/$f $objdir/rpm/SOURCES + i=`expr $i + 1` + ;; + esac + done + if [ -d $PKGSRC/$pkgpath ]; then + (cd $PKGSRC/$pkgpath && tar -cf $objdir/rpm/SOURCES/$pkgname-pkgsrc.tar .) + echo "Source$i: $pkgname-pkgsrc.tar" >> $specfile + fi + echo "" >> $specfile + + i=0 + if [ -d $PKGSRC/$pkgpath/patches ]; then + (cd $PKGSRC/$pkgpath/patches && for f in "" patch-*; do + case "$f" in + "") continue ;; + *) echo "Patch$i: $pkgname-$f" >> $specfile + ${cp_cmd} $f $objdir/rpm/SOURCES/$pkgname-$f + i=`expr $i + 1` + ;; + esac + done) + echo "" >> $specfile + echo "" >> $specfile + fi + + echo "%description" >> $specfile + ${pkg_info_cmd} -qd $name | ${awk_cmd} 'NF == 0 { next } { print }' >> $specfile + + echo "" >> $specfile + echo "%prep" >> $specfile + echo "echo prep finished" >> $specfile + + echo "" >> $specfile + echo "%setup -c" >> $specfile + echo "echo setup finished" >> $specfile + + echo "" >> $specfile + echo "%build" >> $specfile + echo "echo build finished" >> $specfile + + echo "" >> $specfile + echo "%install" >> $specfile + echo "(cd $builddir/$pkgprefix && ${gzip_cmd} -d -c $builddir/$name.tgz | ${extract_cmd} && ${mkdir_cmd} -p $builddir/${PKG_DBDIR}/$name && ${mv_cmd} ./+CONTENTS $builddir/${PKG_DBDIR}/$name)" >> $specfile + + echo "" >> $specfile + echo "%clean" >> $specfile + echo "${rm_cmd} -rf $builddir $objdir/rpm/$name" >> $specfile + + echo "" >> $specfile + echo "%files" >> $specfile + ${pkg_info_cmd} -qL $name | ${sed_cmd} -e "s|${pkgprefix}|%{prefix}|g" >> $specfile + echo "${PKG_DBDIR}/$name/+CONTENTS" >> $specfile + + # make the build root, tarup the NetBSD binary package, and insert it in the build root + ${mkdir_cmd} -p $builddir/$pkgprefix + pkg_tarup -d $builddir $pkgbase + + # create the binary rpm itself + (cd $builddir && rpm $verbose $genpat $sign $pkgbase.spec) + + # tell people where we've put it/them + ${ls_cmd} -al $rpmdir/i386/$pkgname-* + + # cleanup + ${rm_cmd} -rf $builddir $objdir/rpm/$pkgname + else + echo "genrpm: WARNING!!! Package \"$1\" not found" 2>&1 + fi + + shift +done + +exit 0 diff --git a/pkgtools/genrpm/files/genrpm.0 b/pkgtools/genrpm/files/genrpm.0 new file mode 100644 index 00000000000..1c295c6dc9a --- /dev/null +++ b/pkgtools/genrpm/files/genrpm.0 @@ -0,0 +1,37 @@ +GENRPM(8) NetBSD System Manager's Manual GENRPM(8) + +NNAAMMEE + ggeennrrppmm + +SSYYNNOOPPSSIISS + ggeennrrppmm [--ss] [--vv] package... + +DDEESSCCRRIIPPTTIIOONN + The ggeennrrppmm program takes an installed pkgsrc package and creates a Redhat + Package Manager package from that, optionally creating an RPM-style src + RPM in addition. If the --vv option is specified, ggeennrrppmm will carry out + its work in a verbose manner (the rpm utility is already a fairly verbose + utility). + + Package version extension will be done automatically by ggeennrrppmm so that + rpm packages do not need to know the individual version numbers of pkgsrc + packages. + + An optinoal source rpm package can also be created by using the appropri- + ate switch. + + The ggeennrrppmm package also requires that the pkg_tarup(pkgsrc/pkgtools) and + rpm(pkgsrc/misc) packages be installed. + +SSEEEE AALLSSOO + pkg_tarup(pkgsrc/pkgtools), rpm(pkgsrc/misc) and + + _D_o_c_u_m_e_n_t_a_t_i_o_n _o_n _t_h_e _N_e_t_B_S_D _P_a_c_k_a_g_e _S_y_s_t_e_m. @PKGSRCDIR@/Packages.txt + +HHIISSTTOORRYY + The ggeennrrppmm command was added to NetBSD's pkgsrc on April 20, 2005. + +AAUUTTHHOORR + The ggeennrrppmm command was written by Alistair Crooks (agc@NetBSD.org) + +NetBSD 3.0 April 20, 2005 NetBSD 3.0 diff --git a/pkgtools/genrpm/files/genrpm.8 b/pkgtools/genrpm/files/genrpm.8 new file mode 100644 index 00000000000..ee7f8e5beb6 --- /dev/null +++ b/pkgtools/genrpm/files/genrpm.8 @@ -0,0 +1,60 @@ +.\" $NetBSD: genrpm.8,v 1.1.1.1 2005/04/20 09:36:00 agc Exp $ +.Dd April 20, 2005 +.Os +.Dt GENRPM 8 +.Sh NAME +.Nm genrpm +.Sh SYNOPSIS +.Nm +.Op Fl s +.Op Fl v +package... +.Sh DESCRIPTION +The +.Nm +program takes an installed pkgsrc package and creates a +Redhat Package Manager package from that, optionally creating +an RPM-style src RPM in addition. +If the +.Fl v +option is specified, +.Nm +will carry out its work in a verbose manner (the rpm utility is +already a fairly verbose utility). +.Pp +Package version extension will be done automatically by +.Nm +so that rpm packages do not need to know the individual version +numbers of pkgsrc packages. +.Pp +An optinoal source rpm package can also +be created by using the appropriate switch. +.Pp +The +.Nm +package also requires that the +.Xr pkg_tarup pkgsrc/pkgtools +and +.Xr rpm pkgsrc/misc +packages be installed. +.Sh SEE ALSO +.Xr pkg_tarup pkgsrc/pkgtools , +.Xr rpm pkgsrc/misc +and +.Rs +.%T "Documentation on the NetBSD Package System" +.Re +@PKGSRCDIR@/Packages.txt +.Sh HISTORY +The +.Nm +command was added to +.Nx Ns 's +pkgsrc on April 20, 2005. +.\" .Sh AUTHORS +.Sh AUTHOR +The +.Nm +command was written by +.An Alistair Crooks (agc@NetBSD.org) +.\" .Sh SECURITY CONSIDERATIONS |