#!/bin/bash - # # copy a package directory from the portage cvs tree to overlay # source /usr/lib/portage/bin/isolated-functions.sh CVSDIR="/usr/portage" OVERLAYDIR="/home/dirtyepic/overlay" DEVOVERLAYDIR="/home/dirtyepic/svn/dirtyepic" GCCOVERLAYDIR="/home/dirtyepic/svn/gcc-porting" print_usage() { echo eerror "Usage: cp2overlay [--dev] [--gcc] " eerror " [--help]" eerror eerror " default is ${OVERLAYDIR}" eerror " --dev is ${DEVOVERLAYDIR}" eerror " --gcc is ${GCCOVERLAYDIR}" echo } if [[ -z $1 || $# -gt 2 ]]; then print_usage exit 1 fi while [[ ${1#--} != ${1} ]]; do if [[ ${1} == "--help" ]]; then print_usage exit 0 elif [[ ${1} == "--dev" ]]; then OVERLAYDIR="${DEVOVERLAYDIR}" shift elif [[ ${1} == "--gcc" ]]; then OVERLAYDIR="${GCCOVERLAYDIR}" shift elif [[ ${1} == "--" ]]; then break else echo eerror "Unknown option: ${1}" print_usage exit 1 fi done PKGCAT=${1%%/*} PKGNAME=${1##*/} [[ $PKGCAT == $PKGNAME ]] && PKGCAT="" if [[ -z ${PKGCAT} ]]; then PORTDIR=$(portageq portdir) 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 CVSFULL="${CVSDIR}/${PKGCAT}/${PKGNAME}" OVERLAYFULL="${OVERLAYDIR}/${PKGCAT}/${PKGNAME}" if [[ ! -d ${CVSFULL} ]]; 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 ${CVSFULL} > /dev/null tar -cf - --exclude='CVS' . | tar -xf - -C ${OVERLAYFULL} popd > /dev/null fi echo einfo "Copied ${PKGCAT}/${PKGNAME} to ${OVERLAYFULL}" echo exit 0