#!/bin/sh #- # Copyright (c) 2002-2006 FreeBSD GNOME Team # 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. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. # # $MCom: portstools/marcusmerge.sh.in,v 1.63 2006/08/05 07:34:30 marcus Exp $ # # These variables are overrideable in /usr/local/etc/${SCRIPTNAME}.cfg. SRCDIR=${MARCUSMERGE_SRCDIR:=""} # The path to the MarcusCom ports without the trailing # module name (i.e. without the trailing /ports). DESTDIR=${MARCUSMERGE_DESTDIR:="/usr/ports"} # The path to the official ports collection. VERBOSE=${MARCUSMERGE_VERBOSE:="no"} # If you want verbose output. SUPFILE=${MARCUSMERGE_SUPFILE:=""} # The path your ports-supfile (default: auto). TARBALL=${MARCUSMERGE_TARBALL:="no"} # Set to yes to download a tarball instead of using CVS. MODULE=${MARCUSMERGE_PORTS:="ports"} # CVS module to check out. EXPMODULE=${MARCUSMERGE_EXPPORTS:="ports-experimental"} # Name of the experimental ports module STABLEMODULE=${MARCUSMERGE_STABLEPORTS:="ports-stable"} # Name of the stable ports module SUPUPDATE=${MARCUSMERGE_SUPUPDATE:="no"} # If you prefer upgrading your port tree using # "make update" (requires a correct setup in # /etc/make.conf) # You do not have to change anything beyond this line. PKGVERSION_CMD="/usr/sbin/pkg_version" PKGVERSION_ARGS="-l \<" CVSUP_CMD="/usr/bin/csup" FETCH_CMD="/usr/bin/fetch" FETCH_ARGS="-4 -q" CVS_ARGS="-z3" update_main="no" pkgversion="no" updating="no" fetchindex="no" unmerge="no" # End list of overrideable variables SCRIPTNAME=`basename $0` if [ -f /usr/local/etc/${SCRIPTNAME}.cfg ]; then . /usr/local/etc/${SCRIPTNAME}.cfg elif [ -f /usr/local/etc/`echo ${SCRIPTNAME} | sed -e 's/.sh$//'`.cfg ]; then . /usr/local/etc/`echo ${SCRIPTNAME} | sed -e 's/.sh$//'`.cfg fi SCRIPTNAME=`basename $0` CVSROOT=":pserver:anonymous@creme-brulee.marcuscom.com:/space/cvs/marcuscom-cvs" TARBALL_URL="http://www.marcuscom.com:8080/downloads/" RMPORTS="RMPORTS" MCVER_FILE="MCVER" MCVER="2006080501" get_tmpdir() { if [ -n "${MC_TMPDIR}" -a -d "${MC_TMPDIR}" ]; then tmpdir="${MC_TMPDIR}" elif [ -n "${TMPDIR}" -a -d "${TMPDIR}" ]; then tmpdir="${TMPDIR}" elif [ -d "/var/tmp" ]; then tmpdir="/var/tmp" elif [ -d "/tmp" ]; then tmpdir="/tmp" elif [ -d "/usr/tmp" ]; then tmpdir="/usr/tmp" else return 1 fi echo ${tmpdir} return 0 } get_tmpfile() { template=$1 tmpfile="" tmpfile="`get_tmpdir`/${template}.XXXXXX" tmpfile=`mktemp -q ${tmpfile}` echo ${tmpfile} return 0 } download_tarball() { tmpfile=`get_tmpfile mctmp` if [ $? != 0 ]; then printf "Unable to create a temporary file for the downloaded tarball.\nPlease set your MC_TMPDIR environment variable to a suitable temporary directory,\nand run this script again.\n" exit 1 fi echo "===> Downloading the tarball for the ${MODULE} module." ${FETCH_CMD} ${FETCH_ARGS} -o ${tmpfile} "${TARBALL_URL}/mc_${MODULE}.tar.bz2" if [ $? != 0 ]; then printf "Failed to download mc_${MODULE}.tar.bz2 from ${TARBALL_URL}.\n\n" exit 1 fi echo "===> Download done." echo "===> Extracting ${tmpfile} to ${SRCDIR}." mkdir -p ${SRCDIR} tar -C ${SRCDIR} -xvjf ${tmpfile} echo "===> Extraction done." rm -f ${tmpfile} } generate_unmerge_file() { module=$1 # Record a list of merged ports for later unmerging. echo "# This file is generated by marcusmerge for the purposes of backing" > ${DESTDIR}/MC_UNMM-${module}.txt echo "# out or unmerging all changes. DO NOT MODIFY THIS FILE." >> ${DESTDIR}/MC_UNMM-${module}.txt echo "# See http://www.marcuscom.com/marcusmerge.8.html for more details." >> ${DESTDIR}/MC_UNMM-${module}.txt } run_unmerge() { modules=$* unfiles="" foundone=0 for module in ${modules} ; do unfiles="${unfiles} MC_UNMM-${module}.txt" done if [ -z "${unfiles}" ]; then unfiles=`cd ${DESTDIR} && /bin/ls -1 MC_UNMM-*.txt 2> /dev/null` fi unfiles="${unfiles} MC_UNMM.txt" # For backwards compat for unfile in ${unfiles} ; do if [ ! -f ${DESTDIR}/${unfile} ]; then if [ ${unfile} != "MC_UNMM.txt" ]; then echo "${DESTDIR}/${unfile} does not exist. Have you run a successful marcusmerge for this module yet?" | /usr/bin/fmt 75 79 fi else echo "===> Unmerging previously merged ports from ${DESTDIR} using ${unfile}" cd ${DESTDIR} for port in `/usr/bin/sed -e 's|^#.*$||g' ${unfile}` ; do if [ "${VERBOSE}" = "yes" ]; then echo "Removing port directory for: ${port}" fi /bin/rm -rf ${port} done /bin/rm -f ${unfile} foundone=1 fi done if [ ${foundone} = 0 ]; then return 1 fi return 0 } while getopts "abilptUuvxc:d:Ss:m:" arg; do case "${arg}" in s) SRCDIR="${OPTARG}" ;; d) DESTDIR="${OPTARG}" ;; c) CVSROOT="${OPTARG}" ;; m) MODULE="${OPTARG}" ;; v) VERBOSE="yes" ;; t) TARBALL="yes" ;; u) updating="yes" ;; l) pkgversion="yes" ;; p) update_main="yes" ;; a) updating="yes" pkgversion="yes" update_main="yes" fetchindex="yes" ;; x) experimental="yes" ;; b) stable="yes" ;; i) fetchindex="yes" ;; S) SUPUPDATE="yes" ;; U) unmerge="yes" ;; *) echo "usage: ${SCRIPTNAME} [-s ] [-d ] [-c ] [-m ] [-t] [-u] [-v] [-l] [-p] [-a] [-x] [-b] [-i] [-S] [-U]" exit 1 esac done if [ ${unmerge} = "yes" ]; then run_unmerge if [ $? != 0 ]; then exit 0 fi echo "===> Unmerge done." echo "Please update your ports tree before doing anything else ports-related." | /usr/bin/fmt 75 79 exit 0 fi if [ -z "${SRCDIR}" ]; then echo "You did not specify a SRCDIR; aborting..." exit 1 fi if [ -z "${MODULE}" ]; then echo "You did not specify a MODULE; aborting..." exit 1 fi SRCDIR=`/bin/realpath ${SRCDIR}` DESTDIR=`/bin/realpath ${DESTDIR}` if [ ${unmerge} = "no" -a ${update_main} = "yes" ]; then if [ "${stable}" = "yes" ]; then run_unmerge ${STABLEMODULE} elif [ "${experimental}" = "yes" ]; then run_unmerge ${EXPMODULE} ${MODULE} else run_unmerge ${MODULE} fi fi # This function does, well, everything. It takes the module name as an argument. run_marcusmerge() { moduledir="$1" if [ ${SRCDIR} = ${DESTDIR} -o "${SRCDIR}/${moduledir}" = ${DESTDIR} ]; then printf "Your SRCDIR is set to the same path as your DESTDIR.\nPlease set it to a path where we can store the MarcusCom ports.\n\n" exit 1 fi first_time=0 # If the SRCDIR doesn't exist, we need to download the repo. Currently, we # can do this via CVS or from a tarball generated periodically. if [ ! -d ${SRCDIR} -o ! -d ${SRCDIR}/${moduledir} ]; then first_time=1 if [ "${TARBALL}" = "yes" ]; then download_tarball else printf "First we have to check out the ${moduledir} module from\nhttp://www.marcuscom.com:8080/cgi-bin/cvsweb.cgi\nPlease type 'anoncvs' as your password.\n\n" cvs ${CVS_ARGS} -d${CVSROOT} login echo "===> Checking out the ${moduledir} module." mkdir -p ${SRCDIR} cd ${SRCDIR} cvs ${CVS_ARGS} -d${CVSROOT} checkout -P ${moduledir} if [ $? != 0 ]; then printf "Failed to check out the MarcusCom ports tree.\n\n" exit 1 fi echo "===> Checkout done." fi fi # Update the MarcusCom repo if so requested. Don't update if we just checked # out (or downloaded) the repo for this first time. if [ ${updating} = "yes" -a ${first_time} = 0 ]; then echo "===> Updating the MarcusCom ports tree" if [ "${TARBALL}" = "yes" ]; then rm -rf "${SRCDIR}/${moduledir}" download_tarball else cd "${SRCDIR}/${moduledir}" cvs ${CVS_ARGS} update -Pd -A if [ $? != 0 ]; then printf "Failed to update the MarcusCom ports tree.\n\n" exit 1 fi fi echo "===> Updating done." fi # Determine if this repo needs a newer marcusmerge. mcver="0" if [ -f "${SRCDIR}/${moduledir}/${MCVER_FILE}" ]; then mcver=`/bin/cat "${SRCDIR}/${moduledir}/${MCVER_FILE}"` if [ "${mcver}" != "${MCVER}" ]; then echo "This repository requires a newer version of marcusmerge. Please go to http://www.marcuscom.com:8080/cgi-bin/cvsweb.cgi to download the latest version." | /usr/bin/fmt 75 79 exit 1 fi fi # Handle ports that may have been moved or deleted in the MarcusCom repo. if [ -f "${SRCDIR}/${moduledir}/${RMPORTS}" ]; then echo "===> Removing obsolete ports from main tree" for i in `/bin/cat ${SRCDIR}/${moduledir}/${RMPORTS} | cut -d '|' -f1`; do if [ "${VERBOSE}" = "yes" ]; then echo " Removing obsolete port ${i}" fi /bin/rm -rf ${DESTDIR}/${i} done if [ "${VERBOSE}" = "yes" ]; then echo "Adding removed ports to MOVED" fi date=`/bin/date "+%Y-%m-%d"` /usr/bin/sed -e "s|%%DATE%%|${date}|g" ${SRCDIR}/${moduledir}/${RMPORTS} \ >> ${DESTDIR}/MOVED echo "===> done." fi echo "===> Merging files into the ports directory" echo "${SRCDIR}/${moduledir} --> ${DESTDIR}" if [ -d ${SRCDIR}/${moduledir}/Mk ]; then if [ "${VERBOSE}" = "yes" ]; then echo "Merging Mk files" fi if [ ! -d ${DESTDIR}/Mk ]; then if [ "${VERBOSE}" = "yes" ]; then echo "Creating nonexistent destination category directory: Mk" fi mkdir -p ${DESTDIR}/Mk fi for mk in `ls -1 ${SRCDIR}/${moduledir}/Mk/*.mk`; do cp ${mk} ${DESTDIR}/Mk done fi for category in `ls -1 ${SRCDIR}/${moduledir}`; do if [ ${category} = "CVS" ]; then continue fi for port in `ls -1 ${SRCDIR}/${moduledir}/${category}`; do if [ ${port} = "CVS" ]; then continue fi if [ ! -f ${SRCDIR}/${moduledir}/${category}/${port}/Makefile ]; then continue fi if [ ! -d ${DESTDIR}/${category} ]; then if [ "${VERBOSE}" = "yes" ]; then echo "Creating nonexistent destination category directory: ${category}" fi mkdir -p ${DESTDIR}/${category} fi if [ -d ${DESTDIR}/${category}/${port} ]; then if [ "${VERBOSE}" = "yes" ]; then echo "Removing old directory for: ${category}/${port}" fi rm -rf ${DESTDIR}/${category}/${port}/work find ${DESTDIR}/${category}/${port} \! -path "*/CVS/*" -type f | \ xargs rm -f fi echo "${category}/${port}" >> ${DESTDIR}/MC_UNMM-${moduledir}.txt cd ${SRCDIR}/${moduledir}/${category} tar --exclude "*/CVS*" -cf - ${port} | \ tar -xf - -C ${DESTDIR}/${category} done done } # end of run_marcusmerge() # Try to get our cvsup supfile if we will be updating the main ports tree. if [ ${update_main} = "yes" -a ${SUPUPDATE} != "yes" ]; then if [ -z "${SUPFILE}" ]; then SUPFILE=`cd ${DESTDIR} && make -V PORTSSUPFILE` fi if [ -z "${SUPFILE}" ]; then printf "Update of main ports tree requested but you forgot\nto set SUPFILE in this script; aborting...\n\n" exit 1 fi if [ ! -f ${SUPFILE} ]; then printf "Update of main ports tree requested but I could not\nfind SUPFILE: ${SUPFILE}; aborting...\n\n" exit 1 fi fi # Update the main ports tree if so requested. if [ ${update_main} = "yes" ]; then echo "===> Updating the main ports tree" if [ ${SUPUPDATE} = "yes" ]; then cd ${DESTDIR} && make update else if [ ${VERBOSE} = "yes" ]; then ${CVSUP_CMD} ${SUPFILE} else ${CVSUP_CMD} ${SUPFILE} -L0 fi fi if [ $? != 0 ]; then printf "Failed to cvsup the ports tree.\n\n" exit 1 fi echo "===> Updating done." fi # Get INDEX[(-5|-6)] if so requested. if [ ${fetchindex} = "yes" ]; then echo "===> Running make fetchindex in ${DESTDIR}" cd ${DESTDIR} && make fetchindex echo "===> fetchindex done." fi if [ ${unmerge} = "yes" ]; then echo "===> Unmerge plus ports update done." echo "Your ports tree is now free of MarcusCom ports." | /usr/bin/fmt 75 79 exit 0 fi ################# # # Actually perform the merge # if [ "${stable}" = "yes" ]; then generate_unmerge_file ${STABLEMODULE} run_marcusmerge ${STABLEMODULE} else generate_unmerge_file ${MODULE} run_marcusmerge ${MODULE} if [ "${experimental}" = "yes" ]; then generate_unmerge_file ${EXPMODULE} run_marcusmerge ${EXPMODULE} fi fi echo "===> Merging done." echo "" if [ "${pkgversion}" = "yes" ]; then echo "===> Listing outdated ports..." ${PKGVERSION_CMD} ${PKGVERSION_ARGS} echo "===> Listing done." fi echo "" echo "You can now run \"portupgrade -a\" to upgrade your ports tree." | /usr/bin/fmt 75 79