2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
6 # This script tries to quickly create a Gentoo binary package using the
7 # VDB_PATH/category/pkg/* files
9 # Resulting tbz2 file will be created in ${PKGDIR} ...
10 # default is /usr/portage/packages/All/
12 if [[ ${UID} != "0" ]] ; then
13 echo "You must run this as root"
17 # We need to ensure a sane umask for the packages that will be created.
20 # We need this portage cruft to be before --help output because
21 # we utilize some of these vars in the usage info :/
22 eval $(portageq envvar -v NOCOLOR PKGDIR PORTAGE_BIN_PATH PORTAGE_NICENESS \
23 PORTAGE_PYM_PATH PORTAGE_TMPDIR ROOT)
24 export PKGDIR PORTAGE_TMPDIR ROOT
26 [[ -n ${PORTAGE_NICENESS} ]] && renice $PORTAGE_NICENESS $$ > /dev/null
28 # Make sure the xpak module is in PYTHONPATH
29 export PYTHONPATH=${PORTAGE_PYM_PATH}
30 export PORTAGE_DB=$(portageq vdb_path)
35 echo "quickpkg-${svnrev% *}"
40 Usage: quickpkg [options] <list of pkgs>
43 -C, --nocolor Disable color output
44 -x, --debug Run with shell debug turned on
45 -V, --version Print version and exit
46 -h, --help This cruft output
48 A pkg can be of the form:
49 - ${PORTAGE_DB}/<CATEGORY>/<PKG-VERSION>/
50 - single depend-type atom ...
51 if portage can emerge it, quickpkg can make a package
52 for exact definitions of depend atoms, see ebuild(5)
55 quickpkg ${PORTAGE_DB}/net-www/apache-1.3.27-r1
56 package up apache, just version 1.3.27-r1
58 package up apache, all versions of apache installed
59 quickpkg =apache-1.3.27-r1
60 quickpkg =apache-1.3.27-r1
64 echo "Unknown arguments: $*" 1>&2
72 while [[ -n $1 ]] ; do
74 -C|--nocolor) export NOCOLOR="true";;
75 -x|--debug) SET_X="yes";;
76 -V|--version) version;;
83 [[ ${SET_X} == "yes" ]] && set -x
85 case ${NOCOLOR:-false} in
86 yes|true) unset_colors;;
87 no|false) set_colors;;
90 # here we make a package given a little info
91 # $1 = package-name w/version
94 mkdir -p "${PORTAGE_TMPDIR}/binpkgs" || exit 1
95 chmod 0750 "${PORTAGE_TMPDIR}/binpkgs"
96 MYDIR="${PORTAGE_TMPDIR}/binpkgs/$1"
97 SRCDIR="${PORTAGE_DB}/$2/$1"
98 LOG="${PORTAGE_TMPDIR}/binpkgs/$1-quickpkglog"
100 ebegin "Building package for $1"
102 # clean up temp directory
106 mkdir -p "${MYDIR}"/temp
107 cp "${SRCDIR}"/* "${MYDIR}"/temp/
108 [ -d "${PKGDIR}"/All ] || mkdir -p "${PKGDIR}"/All
109 local pkg_dest="${PKGDIR}/All/${1}.tbz2"
110 local pkg_tmp="${PKGDIR}/All/${1}.tbz2.$$"
112 # create filelist and a basic tbz2
117 else if ($1 == "sym")
121 }' "${SRCDIR}"/CONTENTS | cut -f2- -d" " - | sed -e 's:^/:./:' | \
123 [ -d "${ROOT}/${f}" ] && [ -h "${ROOT}/${f}" ] && continue
125 done > "${MYDIR}"/filelist
126 tar vjcf "${pkg_tmp}" -C "${ROOT}" --files-from="${MYDIR}"/filelist --no-recursion
128 # join together the basic tbz2 and the pkg info files
129 python -c "import xpak; t=xpak.tbz2('${pkg_tmp}'); t.recompose('${MYDIR}/temp')"
131 # move the final binary package to PKGDIR
132 mv -f "${pkg_tmp}" "${pkg_dest}"
133 [ -d "${PKGDIR}/$2" ] || mkdir -p "${PKGDIR}/$2"
134 ( cd "${PKGDIR}/$2" && ln -s ../All/$1.tbz2 )
140 if [ -e "${PKGDIR}/All/$1.tbz2" ] ; then
142 PKGSTATS="${PKGSTATS}"$'\n'"$(einfo $1: $(du -h "${PKGDIR}/All/$1.tbz2" | gawk '{print $1}'))"
146 PKGSTATS="${PKGSTATS}"$'\n'"$(ewarn $1: not created)"
151 # here we parse the parameters given to use on the cmdline
156 # they gave us full path
157 if [ -e "${x}"/CONTENTS ] ; then
159 pkg=$(echo ${x} | cut -d/ -f6)
160 cat=$(echo ${x} | cut -d/ -f5)
161 do_pkg "${pkg}" "${cat}"
163 # lets figure out what they want
165 DIRLIST=$(portageq match "${ROOT}" "${x}")
166 if [ -z "${DIRLIST}" ] ; then
167 eerror "Could not find anything to match '${x}'; skipping"
168 export PKGERROR="${PKGERROR} ${x}"
172 for d in ${DIRLIST} ; do
173 pkg=$(echo ${d} | cut -d/ -f2)
174 cat=$(echo ${d} | cut -d/ -f1)
175 if [ -f "${PORTAGE_DB}/${cat}/${pkg}/CONTENTS" ] ; then
177 elif [ -d "${PORTAGE_DB}/${cat}/${pkg}" ] ; then
178 ewarn "Package '${cat}/${pkg}' was injected; skipping"
180 eerror "Unhandled case (${cat}/${pkg}) !"
181 eerror "Please file a bug at http://bugs.gentoo.org/"
189 if [ -z "${PKGSTATS}" ] ; then
190 eerror "No packages found"
193 echo $'\n'"$(einfo Packages now in ${PKGDIR}:)${PKGSTATS}"
195 if [ ! -z "${PKGERROR}" ] ; then
196 ewarn "The following packages could not be found:"