#!/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/matemerge.sh.in,v 1.64 2007/10/19 04:03:09 mezz Exp $ # # The path to the mate-ports ports without the trailing # module name (i.e. without the trailing /ports). For # example, add "/path/to" and the git will create a new # "mate-ports" directory in /path/to/mate-ports. SRCDIR="" # The path to the official ports collection. DESTDIR="/usr/ports" # If you want verbose output. VERBOSE="no" # You do not have to change anything beyond this line. PKGVERSION_CMD="/usr/sbin/pkg_version" PKGVERSION_ARGS="-l \<" GIT_CMD="/usr/local/bin/git" pkgversion="no" updating="no" unmerge="no" # End list of overrideable variables SCRIPTNAME=`basename $0` RMPORTS="MATERMPORTS" GITURL="https://github.com/jlmess77/mate-ports.git" GITDIR="mate-ports" generate_unmerge_file() { # Record a list of merged ports for later unmerging. echo "# This file is generated by matemerge for the purposes of backing" > ${DESTDIR}/MATE_UNMM-${GITDIR}.txt echo "# out or unmerging all changes. DO NOT MODIFY THIS FILE." >> ${DESTDIR}/MATE_UNMM-${GITDIR}.txt echo "# See http://www.marcuscom.com/matemerge.8.html for more details." >> ${DESTDIR}/MATE_UNMM-${GITDIR}.txt } run_unmerge() { foundone=0 unfiles="MATE_UNMM-${GITDIR}.txt" if [ -z "${unfiles}" ]; then unfiles=`cd ${DESTDIR} && /bin/ls -1 MATE_UNMM-*.txt 2> /dev/null` fi unfiles="${unfiles} MATE_UNMM.txt" # For backwards compat for unfile in ${unfiles} ; do if [ ! -f ${DESTDIR}/${unfile} ]; then if [ ${unfile} != "MATE_UNMM.txt" ]; then echo "${DESTDIR}/${unfile} does not exist. Have you run a successful matemerge for this mate-ports 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 [ -f ${DESTDIR}/MATE-UPDATING ]; then /bin/rm -f ${DESTDIR}/MATE-UPDATING fi if [ ${foundone} = 0 ]; then return 1 fi return 0 } while getopts "abilptUuvxc:d:Ss:m:" arg; do case "${arg}" in v) VERBOSE="yes" ;; u) updating="yes" ;; l) pkgversion="yes" ;; a) updating="yes" pkgversion="yes" ;; U) unmerge="yes" ;; *) echo "usage: ${SCRIPTNAME} [-u] [-v] [-l] [-a] [-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 SRCDIR=`/bin/realpath ${SRCDIR}` DESTDIR=`/bin/realpath ${DESTDIR}` # This function does, well, everything. It takes the module name as an argument. run_matemerge() { if [ ${SRCDIR} = ${DESTDIR} -o "${SRCDIR}/${GITDIR}" = ${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 mate-ports 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}/${GITDIR} ]; then first_time=1 printf "First we have to check out the ${GITDIR} from\nhttps://github.com/jlmess77/mate-ports.git\n\n" echo "===> Checking out the ${GITDIR}." mkdir -p ${SRCDIR} cd ${SRCDIR} ${GIT_CMD} clone ${GITURL} if [ $? != 0 ]; then printf "Failed to check out the mate-ports from GitHub.\n\n" exit 1 fi echo "===> Checkout done." fi # Update the mate-ports 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 mate-ports ports tree" cd "${SRCDIR}/${GITDIR}" ${GIT_CMD} pull if [ $? != 0 ]; then printf "Failed to update the mate-ports ports tree.\n\n" exit 1 fi echo "===> Updating done." fi # Handle ports that may have been moved or deleted in the mate-ports repo. if [ -f "${SRCDIR}/${GITDIR}/${RMPORTS}" ]; then echo "===> Removing obsolete ports from main tree" for i in `/bin/cat ${SRCDIR}/${GITDIR}/${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}/${GITDIR}/${RMPORTS} \ >> ${DESTDIR}/MOVED echo "===> done." fi if [ -f ${SRCDIR}/${GITDIR}/MATE-UPDATING ]; then cp ${SRCDIR}/${GITDIR}/MATE-UPDATING ${DESTDIR}/ fi echo "===> Merging files into the ports directory" echo "${SRCDIR}/${GITDIR} --> ${DESTDIR}" if [ -d ${SRCDIR}/${GITDIR}/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}/${GITDIR}/Mk/*.mk`; do cp ${mk} ${DESTDIR}/Mk mk_unmm=`echo ${mk} | sed -e "s|${SRCDIR}/${GITDIR}/||g"` echo "${mk_unmm}" >> ${DESTDIR}/MATE_UNMM-${GITDIR}.txt done fi for category in `ls -1 ${SRCDIR}/${GITDIR}`; do if [ ${category} = ".git" ]; then continue fi for port in `ls -1 ${SRCDIR}/${GITDIR}/${category}`; do if [ ${port} = ".git" ]; then continue fi if [ ! -f ${SRCDIR}/${GITDIR}/${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 "*/.git/*" -type f | \ xargs rm -f fi echo "${category}/${port}" >> ${DESTDIR}/MATE_UNMM-${GITDIR}.txt cd ${SRCDIR}/${GITDIR}/${category} tar --exclude "*/.git*" -cf - ${port} | \ tar -xf - -C ${DESTDIR}/${category} done done } # end of run_matemerge() if [ ${unmerge} = "yes" ]; then echo "===> Unmerge plus ports update done." echo "Your ports tree is now free of mate-ports ports." | /usr/bin/fmt 75 79 exit 0 fi ################# # # Actually perform the merge # generate_unmerge_file run_matemerge 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\" or \"portmaster -a\" to upgrade your ports tree. Be sure to check in ${DESTDIR}/MATE-UPDATING first before you run portupgrade or portmaster." | /usr/bin/fmt 75 79