#!/bin/sh #- # Copyright (c) 2002-2006 FreeBSD GNOME Team # Copyright (c) 2009-2010 KDE FreeBSD 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. # # Based on marcusmerge by Joe Marcus Clarke , # adapted for area51 by Martin Wilke , # user interface by Alberto Villa . # # Path to area51 trunk. if [ "`echo "$0" | /usr/bin/cut -c 1`" = "/" ]; then : ${MERGESRC:="${0%/*}/../.."} else : ${MERGESRC:="$PWD/${0%/*}/../.."} fi usage() { echo "usage: ${0##*/} -a | -d directory | -kpqy [-Cn] [ports tree]" echo " ${0##*/} -h" echo echo "options:" echo " -a Merge all the ports from trunk" echo " -C Keep any CVS metadata in the ports tree" echo " -d directory Merge from a given directory (to be used with branches or tags)" echo " -h Display this help message" echo " -k Merge the KDE ports" echo " -m Merge the generic ports" echo " -n Simulate all the steps but do not execute anything" echo " -p Merge the PyQt ports" echo " -q Merge the Qt ports" echo echo "examples:" echo "# Merge Qt and KDE to ~/ports." echo "${0##*/} -kq ~/ports" echo "# ...or (in sh-like shells)..." echo "MERGEDST=~/ports ${0##*/} -kq" echo "# Merge Qt 4.5 branch to /usr/ports." echo "${0##*/} -d /branches/qt-4.5 /usr/ports" exit 1 } directory="" ports=0 qt=0 pyqt=0 kde=0 keep_cvs=0 no_execute=0 while getopts "aCd:hkmnpq" option; do case "$option" in "a") ports=1; qt=1; pyqt=1; kde=1 ;; "C") keep_cvs=1 ;; "d") directory="$OPTARG" ;; "h") usage ;; "k") kde=1 ;; "m") ports=1 ;; "n") no_execute=1 ;; "p") pyqt=1 ;; "q") qt=1 ;; esac done shift "$(($OPTIND - 1))" # At least one option is required. if [ "$directory" = "" -a "$ports" -eq 0 -a "$qt" -eq 0 -a \ "$pyqt" -eq 0 -a "$kde" -eq 0 ]; then usage fi # Check the validness of the area51 directory. if [ ! -d "$MERGESRC/KDE" ]; then echo "Cannot find the area51 repository: please, set the environment variable MERGESRC to the full path of the area51 trunk." | /usr/bin/fmt 70 >&2 exit 1 fi # Set the destination ports tree (via command line or with an # environment variable). if [ -n "$1" ]; then MERGEDST="$1" fi if [ -z "$MERGEDST" -o ! -d "$MERGEDST" ]; then echo "Cannot find the destination ports tree: please, specify it on the command line, or set the environment variable MERGEDST to its full path." | /usr/bin/fmt 70 >&2 exit 1 fi # Check the validness of the source directory. if [ "$directory" != "" -a ! -d "$directory" ]; then echo "Cannot find the source repository: please, set the -d option to its full path." | /usr/bin/fmt 70 >&2 exit 1 fi # Get the real paths. MERGESRC="`/bin/realpath "$MERGESRC"`" MERGEDST="`/bin/realpath "$MERGEDST"`" if [ "$directory" != "" ]; then directory="`/bin/realpath "$directory"`" fi echo -n "===> " if [ "$no_execute" -eq 1 ]; then echo -n "Simulating merge of" else echo -n "Merging" fi echo " files from area51 to the ports directory." echo "${directory:-"$MERGESRC"} >> $MERGEDST" echo # Set the actual source directories. sources="" if [ "$directory" != "" ]; then sources="$directory" else [ "$ports" -eq 1 ] && sources="$sources $MERGESRC/PORTS" [ "$qt" -eq 1 ] && sources="$sources $MERGESRC/QT" [ "$pyqt" -eq 1 ] && sources="$sources $MERGESRC/PYQT" [ "$kde" -eq 1 ] && sources="$sources $MERGESRC/KDE" fi # Merge UPDATING. if [ "$no_execute" -ne 1 -a -f "$MERGESRC/UPDATING-area51" ]; then cp "$MERGESRC/UPDATING-area51" "$MERGEDST" fi # Iterate through the source directories and merge them. for source in `echo "$sources"`; do # Check for the real existence of this directory. if [ ! -d "$source" ]; then echo "Cannot find directory `/usr/bin/basename "$source"`: please, check your source repository." | /usr/bin/fmt 70 >&2 continue fi echo -n "===>>> Merging `/usr/bin/basename "$source"` " # Merge Mk files. if [ "$no_execute" -ne 1 -a -d "$source/Mk" ]; then mkdir -p "$MERGEDST/Mk" for file in `ls -1 "$source"/Mk/*.mk`; do cp "$file" "$MERGEDST/Mk" done fi # Merge categories and ports. count=0 for category in `find "$source" -depth 1 -type d`; do category="`/usr/bin/basename "$category"`" if [ "$category" = ".svn" ]; then continue fi echo -n "." for port in `ls -1 "$source/$category"`; do if [ "$port" = ".svn" -o \ ! -f "$source/$category/$port/Makefile" ]; then continue fi count="$(($count + 1))" if [ "$no_execute" -eq 1 ]; then continue fi # Remove the working directory and every file. mkdir -p "$MERGEDST/$category" if [ -d "$MERGEDST/$category/$port" ]; then rm -f -r "$MERGEDST/$category/$port/work" if [ "$keep_cvs" -eq 1 ]; then find "$MERGEDST/$category/$port" \ \! -path "*/.svn/*" \ \! -path "*/CVS/*" -type f | xargs rm -f else find "$MERGEDST/$category/$port" \ \! -path "*/.svn/*" -type f | xargs rm -f fi fi cd "$source/$category" tar -c --exclude "*/.svn*" -f - "$port" | tar -x -C "$MERGEDST/$category" -f - done done echo " $count ports" done echo if [ "$no_execute" -eq 1 ]; then echo "This was just a simulation: to actually merge the ports, remove the -n flag from the command line." | /usr/bin/fmt 70 else echo "You can now run \`portmaster -a\` or \`portupgrade -a\` to upgrade your ports. Please, read $MERGEDST/UPDATING-area51 before you upgrade. We suggest that you backup your ~/.kde4 configuration directory and start with a clean one." | /usr/bin/fmt 70 fi