Created
December 27, 2012 03:28
-
-
Save tota/4385235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# util_diff | |
# port(1) helper script to generate a diff or a shar file | |
# | |
# $Id: util_diff.in,v 1.4 2009/09/09 19:58:30 skolobov Exp $ | |
# | |
# Check if this script is run via port(1) | |
if [ "${PORTTOOLS}" = "" ] | |
then | |
echo "This script should be run via port(1) front-end" | |
exit 1 | |
fi | |
# Determine if this is a new port | |
if [ "${MODE}" = "" ] | |
then | |
[ "`grep '\$FreeBSD: ' Makefile`" ] || MODE="new" | |
fi | |
# Create a temporary dir for generated files (patch/shar, PR form) | |
TEMPROOT="`mktemp -d -t port`" || exit 1 | |
if [ "${MODE}" = "new" ] | |
then | |
# Generate shar file with new port | |
echo "===> Creating shar file" | |
PATCH="${TEMPROOT}/${PKGNAME}.shar" | |
SAVE_CWD="`pwd`" | |
DIR="`basename ${SAVE_CWD}`" | |
cd .. | |
shar `find ${DIR}` > ${PATCH} | |
if [ $? -ne 0 ] | |
then | |
echo "Error generating patch" | |
rm -rf ${TEMPROOT} | |
exit 1 | |
fi | |
cd ${SAVE_CWD} | |
else | |
# Determine the default diff mode | |
if [ "${DIFF_MODE}" = "" ] | |
then | |
if [ -d CVS ] | |
then | |
if grep -iq ":pserver:anoncvs@anoncvs.fr.FreeBSD.org:" CVS/Root | |
then | |
DIFF_MODE="CVSauto" | |
else | |
DIFF_MODE="CVS" | |
fi | |
else | |
DIFF_MODE="/usr/ports" | |
fi | |
echo "Default diff mode is ${DIFF_MODE}" | |
elif [ "${DIFF_MODE}" = "CVS" -o "${DIFF_MODE}" = "CVSauto" ] | |
then | |
# If there is no CVS subdirectory then | |
# fallback to diffing against /usr/ports tree | |
if [ ! -d CVS ] | |
then | |
echo "Diff mode was set to ${DIFF_MODE}, but there's no CVS subdirectory" | |
echo -n "Trying /usr/ports ... " | |
if [ -d /usr/ports ] | |
then | |
DIFF_MODE="/usr/ports" | |
echo "found" | |
else | |
echo "not found - please choose an approriate diff mode" | |
rm -rf ${TEMPROOT} | |
exit 1 | |
fi | |
fi | |
fi | |
if [ "${DIFF_MODE}" = "CVS" -o "${DIFF_MODE}" = "CVSauto" ] | |
then | |
DIFF_TYPE=${DIFF_MODE} | |
# Test for ~/.cvspass and create if necessary | |
test -f ${HOME}/.cvspass || touch ${HOME}/.cvspass | |
# Run 'cvs update' first | |
echo "===> Updating from CVS" | |
if [ "${DIFF_MODE}" = "CVSauto" ] | |
then | |
cvs -R update -Pd 2> ${TEMPROOT}/.cvs.err > ${TEMPROOT}/.cvs.out | |
status=$? | |
cat ${TEMPROOT}/.cvs.err ${TEMPROOT}/.cvs.out | |
else | |
cvs -R update -Pd | |
status=$? | |
fi | |
if [ $status -ne 0 ] | |
then | |
echo "Error updating CVS" | |
rm -rf ${TEMPROOT} | |
exit 1 | |
fi | |
PORTBASENAME=`sed -E -e 's%.*/([^/]+)$%\1%' CVS/Repository` | |
if [ "${DIFF_MODE}" = "CVSauto" ] | |
then | |
sort -k 2,666 ${TEMPROOT}/.cvs.out | \ | |
sed -nE -e 's/^[?A] (.*)$/echo "diff -uN \1.orig \1" \&\& diff -uN "\1.orig" "\1" /p' \ | |
-e 's/^U (.*)$/mv "\1" "\1.orig" \&\& echo "diff -uN \1.orig \1" \&\& diff -uN "\1.orig" "\1" ; rm "\1.orig"/p' \ | |
-e 's/^R (.*)$/cvs -R -q update -p "\1" > "\1.orig" \&\& echo "diff -uN \1.orig \1" \&\& diff -uN "\1.orig" "\1" ; rm "\1.orig"/p' \ | |
-e 's/^M (.*)$/cvs -R diff -u "\1"/p' \ | |
> ${TEMPROOT}/.cvs.diff_cmd | |
DIFF_CMD="sh -x ${TEMPROOT}/.cvs.diff_cmd" | |
else | |
DIFF_CMD="cvs -R diff -uN" | |
fi | |
else | |
# Non-CVS modes | |
DIRBASENAME=`basename \`pwd\`` | |
PORTBASENAME_HEADER=`sed -n -E -e '1,/^($|[^#].*$)|\\$FreeBSD\:/s%^#.*\\$FreeBSD\:[[:space:]]*([^/]+/)*([^/]+)/Makefile.*\\$%\2%p' Makefile` | |
if [ "${DIRBASENAME}" != "${PORTBASENAME_HEADER}" ] | |
then | |
echo "Warning: current directory name differs from Makefile header:" | |
echo " ${DIRBASENAME}" != "${PORTBASENAME_HEADER}" | |
fi | |
PYTHON_SUFFIX="`make -V PYTHON_SUFFIX`" | |
RUBY_SUFFIX="`make -V RUBY_SUFFIX`" | |
PKGNAMEPREFIX="`make -V PKGNAMEPREFIX | sed -E "s,py${PYTHON_SUFFIX}-,py-," | sed -E "s,ruby${RUBY_SUFFIX}-,ruby-,"`" | |
PKGNAMESUFFIX="`make -V PKGNAMESUFFIX`" | |
PORTNAME="${PKGNAMEPREFIX}`make -V PORTNAME`${PKGNAMESUFFIX}" | |
if [ -d ${DIFF_MODE} ] | |
then | |
# -d <dir> have been specified | |
# it should be Ports tree location | |
DIFF_TYPE="ports" | |
CATEGORY="`make -V CATEGORIES | sed -E 's/^([^ ]+).*$/\1/'`" | |
ORIG_DIR="${DIFF_MODE}/${CATEGORY}/${PORTNAME}" | |
if [ ! -d ${ORIG_DIR} ] | |
then | |
echo "Original version does not exist at ${ORIG_DIR}" | |
if [ -d "${DIFF_MODE}/${CATEGORY}/${DIRBASENAME}" ] | |
then | |
PORTBASENAME=${DIRBASENAME} | |
ORIG_DIR="${DIFF_MODE}/${CATEGORY}/${PORTBASENAME}" | |
elif [ -d "${DIFF_MODE}/${CATEGORY}/${PORTBASENAME_HEADER}" ] | |
then | |
PORTBASENAME=${PORTBASENAME_HEADER} | |
ORIG_DIR="${DIFF_MODE}/${CATEGORY}/${PORTBASENAME}" | |
fi | |
[ -d ${ORIG_DIR} ] && echo "Using ${ORIG_DIR} instead" | |
fi | |
else | |
# -d <pattern> have been specified | |
# <pattern> is used to determine original port location | |
DIFF_TYPE="suffix" | |
ORIG_DIR="../${DIRBASENAME}${DIFF_MODE}" | |
if [ "${DIRBASENAME}" != "${PORTNAME}" -a "${DIRBASENAME}" = "${PORTBASENAME_HEADER}" ] | |
then | |
PORTBASENAME=${DIRBASENAME} | |
echo "Using ${PORTBASENAME} instead of ${PORTNAME} as the port's directory name" | |
fi | |
fi | |
# Check to see if the original version of port exist | |
if [ ! -d ${ORIG_DIR} ] | |
then | |
echo "Original version does not exist at ${ORIG_DIR}" | |
rm -rf ${TEMPROOT} | |
exit 1 | |
fi | |
DIFF_CMD="diff -ruN --exclude=CVS ${ORIG_DIR} ." | |
fi | |
# Generate patch | |
echo "===> Generating patch" | |
PKGNAME="`make -V PKGNAME`" | |
PATCH="${TEMPROOT}/${PKGNAME}.patch" | |
${DIFF_CMD} > ${PATCH} | |
#if [ $? -ne 0 ] | |
#then | |
# echo "Error generating patch" | |
# exit 1 | |
#fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment