#!/bin/bash - # # copy a package directory from the portage tree to overlay # [dirtyepic@gentoo.org] source /usr/lib/portage/bin/isolated-functions.sh PORTDIR="$(portageq portdir)" CVSDIR="/home/dirtyepic/cvs/gentoo-x86" OVERLAYDIR="/home/dirtyepic/overlay" DEVOVERLAYDIR="/home/dirtyepic/svn/dirtyepic" GCCOVERLAYDIR="/home/dirtyepic/svn/gcc-porting" print_usage() { echo eerror "Usage: cp2overlay [--fromcvs] [--dev] [--gcc] " eerror " [--help]" eerror eerror " default is ${OVERLAYDIR}" eerror " --dev is ${DEVOVERLAYDIR}" eerror " --gcc is ${GCCOVERLAYDIR}" eerror " --fromcvs copies from ${CVSDIR} instead of ${PORTDIR}" echo } if [[ -z $1 || $# -gt 3 ]]; then print_usage exit 1 fi while [[ ${1#--} != ${1} ]]; do if [[ ${1} == "--help" ]]; then print_usage exit 0 elif [[ ${1} == "--fromcvs" ]]; then CVSUP=true PORTDIR=${CVSDIR} shift elif [[ ${1} == "--dev" ]]; then OVERLAYDIR="${DEVOVERLAYDIR}" shift elif [[ ${1} == "--gcc" ]]; then OVERLAYDIR="${GCCOVERLAYDIR}" shift elif [[ ${1} == "--" ]]; then shift break else echo eerror "Unknown option: ${1}" print_usage exit 1 fi done PKGCAT=${1%%/*} PKGNAME=${1##*/} [[ $PKGCAT == $PKGNAME ]] && PKGCAT="" if [[ -z ${PKGCAT} ]]; then if [[ -e ${PORTDIR}/.ebuild.x ]]; then CATEGORY=$(sed -n "\\|/${1}/|s:/[^/]*\$::p" "${PORTDIR}"/.ebuild.x | uniq) else pushd "${PORTDIR}" &> /dev/null CATEGORY=$(ls -1d $(sed "s:\$:/${1}:" profiles/categories) 2>/dev/null) popd &> /dev/null fi if [[ $(echo ${CATEGORY} | wc -w) -gt 1 ]]; then echo eerror "Found multiple categories for \"${1}\"." eerror "Please use a fully qualified package name (cat/package)." echo exit 1 fi PKGCAT="${CATEGORY%%/*}" fi PORTFULL="${PORTDIR}/${PKGCAT}/${PKGNAME}" OVERLAYFULL="${OVERLAYDIR}/${PKGCAT}/${PKGNAME}" if [[ ! -d ${PORTFULL} ]]; then echo eerror "Can't find package \"${1}\" in the portage tree." echo exit 1 elif [[ -d ${OVERLAYFULL} ]]; then echo eerror "${PKGCAT}/${PKGNAME} already exists in the overlay." echo exit 1 else mkdir -p ${OVERLAYFULL} pushd ${PORTFULL} > /dev/null [[ ${CVSUP} ]] && cvs up tar -cf - --exclude='CVS' . | tar -xf - -C ${OVERLAYFULL} popd > /dev/null fi echo einfo "Copied ${PORTFULL} to ${OVERLAYFULL}" echo exit 0