#!/bin/bash # # Version 0.1 # NONPREFIX_PORTDIR_ORIGINAL=${EPREFIX}/usr/portage.main.plain NONPREFIX_PORTDIR_CONVERTED=${EPREFIX}/usr/portage.main.converted if [ -z "${PREFIX_PORTDIR}" ] then PREFIX_PORTDIR=${EPREFIX}/usr/portage fi #NONPREFIX_SYNC='rsync://junge/gentoo-portage' if [ -z "${SYNC}" ] then NONPREFIX_SYNC='rsync://rsync.gentoo.org/gentoo-portage' else NONPREFIX_SYNC="${SYNC}" fi MY_KEYWORD="~x86-macos" # Extra options #EXTRA_CP_OPTIONS="-l" # # Sync the copy of the main tree # dosync() { PORTDIR=${NONPREFIX_PORTDIR_ORIGINAL} SYNC=${NONPREFIX_SYNC} emerge --sync } # # Convert the new and not-yet-converted packages # doconvert() { local CATEGORY_DIR local CATEGORY_NAME local COMPONENT_DIR local COMPONENT_NAME # Loop through all categories for CATEGORY_DIR in ${NONPREFIX_PORTDIR_ORIGINAL}/*-* do CATEGORY_NAME=${CATEGORY_DIR#${NONPREFIX_PORTDIR_ORIGINAL}/} echo Category ${CATEGORY_DIR} >&2 # If the category dir is not yet existent in the target directory, create it test -d ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}|| mkdir -p ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME} # Loop through the components for COMPONENT_DIR in ${CATEGORY_DIR}/* do COMPONENT_NAME=${COMPONENT_DIR#${CATEGORY_DIR}/} if test -d ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} -a \ -d ${PREFIX_PORTDIR}/${CATEGORY_NAME}/${COMPONENT_NAME} then echo Deleting ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}, since ${PREFIX_PORTDIR}/${CATEGORY_NAME}/${COMPONENT_NAME} exists>&2 rm -R ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} elif test \ ! -d ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} \ -o \ ${NONPREFIX_PORTDIR_ORIGINAL}/${CATEGORY_NAME}/${COMPONENT_NAME} -nt \ ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} then echo Package ${COMPONENT_DIR} >&2 if [[ ${PIPE} ]] then echo convert_component ${CATEGORY_NAME} ${COMPONENT_NAME} else convert_component ${CATEGORY_NAME} ${COMPONENT_NAME} 1>&2 fi fi done #break 2 done } # # Convert a single package # convert_component() { local COMPONENT_DIR local CATEGORY_NAME local COMPONENT_NAME CATEGORY_NAME=$1 COMPONENT_NAME=$2 COMPONENT_DIR=${NONPREFIX_PORTDIR_ORIGINAL}/${CATEGORY_NAME}/${COMPONENT_NAME} # # Check if the component is already in the prefix tree # [ -z "${FORCE}" ] && test -d "${PREFIX_PORTDIR}/${CATEGORY_NAME}/${COMPONENT_NAME}" && return # # Create component dir if it doesn't exit # # We delete and recreate it, because otherwise we will have old ebuilds sitting there. # test -d ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} && rm -R ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} mkdir ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME} # # Check for corruption # # Since we regenerate the manifest at the end, if have to be sure that the # package has not been tampered with before it reached here. # check_component ${COMPONENT_DIR} || return # # Copy the files from the files dir, including MISC files like ChangeLog and metadata.xml # test -d ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/files && rm -R ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/files #cp -pr ${COMPONENT_DIR}/files `grep ^MISC ${COMPONENT_DIR}/Manifest | sed "s!^MISC \([^ ]*\) .*!${COMPONENT_DIR}/\1!"` ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/ cp -r ${EXTRA_CP_OPTIONS} ${COMPONENT_DIR} ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/ # # Copy the manifest # #cp ${COMPONENT_DIR}/Manifest ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/ # # Convert the ebuilds # for EBUILD_FILE in ${COMPONENT_DIR}/*.ebuild do #echo Ebuild ${EBUILD_FILE} EBUILD_NAME=${EBUILD_FILE#${COMPONENT_DIR}/} #test ! -f ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/${EBUILD_NAME} -o \ # ${EBUILD_FILE} -nt ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/${EBUILD_NAME} && \ convert_ebuild ${EBUILD_FILE} ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/${EBUILD_NAME} done # The last ebuild will be the one used for creating the manifest ebuild ${NONPREFIX_PORTDIR_CONVERTED}/${CATEGORY_NAME}/${COMPONENT_NAME}/${EBUILD_NAME} manifest } # # Check health of component by verifying the checksums of every file # that should be available locally. # check_component() { #grep MD5 $1/Manifest|grep -v files/digest|sed "s!^MD5 \([^ ]*\) \([^ ]*\) \([0-9]*\)!\1 $1/\2!" > /tmp/gentoo-MD5SUMS || return 1 #md5sum -c /tmp/gentoo-MD5SUMS > /dev/null || return 1 $HOME/bin/check-ebuilds.py $1 ${PREFIX_PORTDIR}/distfiles return 0 } # # Convert a single ebuild. # # That means we eapify it and also add the keyword for our architecture. # This function makes it impractical, btw, to use the converted tree as # a source for patches. :-/ # convert_ebuild() { OLD=$1 NEW=$2 cp ${OLD} ${NEW} ${PREFIX_PORTDIR}/scripts/eapify ${NEW} ${PREFIX_PORTDIR}/scripts/ecleankw ${NEW} check_keyword "${NEW}" "${MY_KEYWORD}" || ekeywordify "${NEW}" "${MY_KEYWORD}" #echo ebuild ${NEW} manifest >&2 } # # Check for the existence of a certain keyword # check_keyword() { grep "^KEYWORDS=\".*$2.*\"" $1 > /dev/null return $? } # # Add a keyword to the ebuild # ekeywordify() { sed -e "s!^KEYWORDS=\"\([^\"]*\)\"!KEYWORDS=\"\1 $2\"!" -i $1 } # # Next one is the slave loop. # # It is ment to be used like this: # $0 -m convert | ( $0 -s & $0 -s ) # # That would mean two instances of the command run in parallel. # However, on my Darwin this didn't work out as expected. 'ps' # would show me only one slave instance. So this is would made # it work: # # mkfifo /tmp/fifo # $0 -s < /tmp/fifo & $0 -s < /tmp/fifo # $0 -m convert > /tmp/fifo # # The second form has also the advantage that you can make it # using more CPUs at runtime. ;) # slave_loop() { while read line do eval ${line} done } # # For using more than one CPU/core we support -m which brings this # instance into the master mode. Check the slave_loop for documentation # on how to use this. # if [ "$1" == "-m" ] then PIPE=1 shift fi COMMAND=$1 shift case $COMMAND in '--sync') dosync ;; '--convert') if [ -z "$1" ]; then doconvert else PACKAGE=$1 shift [ "$1" == "-f" ] && FORCE=1 convert_component ${PACKAGE/\// } fi ;; '--keywordify') while ! test -z "$1" do if test -f "$1" then check_keyword $1 ${MY_KEYWORD} || ekeywordify $1 ${MY_KEYWORD} ebuild $1 manifest elif test -d ${PREFIX_PORTDIR}/$1 then check_component ${PREFIX_PORTDIR}/$1 || exit 1 echo $0 --keywordify ${PREFIX_PORTDIR}/$1/*.ebuild $0 --keywordify ${PREFIX_PORTDIR}/$1/*.ebuild fi shift done ;; '-s') slave_loop ;; *) echo "Syntax:" echo "$0 --sync" echo "$0 [-m] --convert [/ [-f]]" echo "$0 --keywordify [ | ]" echo "$0 -s" ;; esac