[23256] branches/release_1_4/base/portmgr/IndexRegen.sh

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 27 23:37:37 PDT 2007


Revision: 23256
          http://trac.macosforge.org/projects/macports/changeset/23256
Author:   jmpp at macports.org
Date:     2007-03-27 23:37:37 -0700 (Tue, 27 Mar 2007)

Log Message:
-----------

What was supposed to be a small commit to the InexRegen.sh script turned into a somewhat major rewrite!
Changelog, in order of relevance:

 * First and foremost: We now commit the index even if any number of ports fail parsing (I figure that at least
   an incomplete index is better than no index what-so-ever for a full 12 hour period);
 * Indexing failures, if any, are grep'd for from the runtime log and appended to the commit messsage;
 * Renaming the TREE variable to SRCTREE for clarity;
 * The ${SRCTREE}/dports and ${SRCTREE}/base trees are now checked out if non-existent, updated otherwise (we now
   don't cowardly bail out if they don't exist)
 * Introduced a bail() function that handles mailing the runtime log upon failure and, namely, bailing out;
 * Removed the now unnecessary FAILED variable and all the chekcs for its value;
 * Introduced a cleanup() function that takes care of deleting the runtime log, commit message file and lock;
 * Innocuous DP --> MP move;
 * Somewhat improved error reporting;
 * And, last but certainly not least, syntax re-tabbing! (Sorry guys, couldn't help it!!)

I tested this new script with an environment as close to reality as possible and it seems to be working dandy,
but some fresh eyes on it other than mine and real life testing are surely necessary before putting it to work.
Daniel, here's where you come in! ;-)


-jmpp

PS: Lets work on this file on the release_1_4 branch, as that version is the one pulling the base sources we
are currently indexing with in real life. Once it's done I'll merge all of its commits (if more than one) back
into trunk.

Modified Paths:
--------------
    branches/release_1_4/base/portmgr/IndexRegen.sh

Modified: branches/release_1_4/base/portmgr/IndexRegen.sh
===================================================================
--- branches/release_1_4/base/portmgr/IndexRegen.sh	2007-03-28 06:28:18 UTC (rev 23255)
+++ branches/release_1_4/base/portmgr/IndexRegen.sh	2007-03-28 06:37:37 UTC (rev 23256)
@@ -11,12 +11,12 @@
 
 # Configuration
 LOCKFILE=/tmp/.mp_svn_index_regen.lock
-# ROOT directory, where everything is. This must exist.
+# ROOT directory, where everything is.
 ROOT=/Users/dluke/Projects/mp_svn_index_regen
-# DP user.
-DP_USER=dluke
-# DP group.
-DP_GROUP=staff
+# MP user.
+MP_USER=dluke
+# MP group.
+MP_GROUP=staff
 # e-mail address to spam in case of failure.
 SPAM_LOVERS=macports-mgr at lists.macosforge.org,dluke at geeklair.net
 
@@ -25,7 +25,7 @@
 SVN_BASE_URL=http://svn.macports.org/repository/macports/branches/release_1_4/base
 SVN_CONFIG_DIR=${ROOT}/svnconfig
 # Where to checkout the source code. This gets created.
-TREE=${ROOT}/source
+SRCTREE=${ROOT}/source
 # Where DP will install its world. This gets created.
 PREFIX=${ROOT}/opt/local
 # Where DP installs darwinports1.0. This gets created.
@@ -34,102 +34,89 @@
 PATH=${PREFIX}/bin:/bin:/usr/bin:/opt/local/bin
 # Log for the e-mail in case of failure.
 FAILURE_LOG=${ROOT}/failure.log
-# Something went wrong.
-FAILED=0
 # Commit message.
 COMMIT_MSG=${ROOT}/commit.msg
 # The date.
 DATE=$(date +'%A %Y-%m-%d at %H:%M:%S')
 
+
+# Function to spam people in charge if something goes wrong during indexing.
+bail () {
+    mail -s "AutoIndex Failure on ${DATE}" $SPAM_LOVERS < $FAILURE_LOG
+    cleanup; exit 1
+}
+
+# Cleanup fuction for runtime files.
+cleanup () {
+    rm -f $COMMIT_MSG $FAILURE_LOG
+    rm -f $LOCKFILE
+}
+
+
 if [ ! -e $LOCKFILE ]; then
-	touch $LOCKFILE
+    touch $LOCKFILE
 else
-	echo "Index Regen lockfile found, is another index regen running?"
-	exit 1
+    echo "Index Regen lockfile found, is another index regen running?"
+    exit 1
 fi
 
-# checkout if required, update otherwise.
-if [ ! -d ${TREE}/dports ]; then
-		{ echo "SVN update failed, please check out a copy of DP into ${TREE}" >> $FAILURE_LOG ; FAILED=1 ; }
+# Checkout both the ports tree and base sources if required, update otherwise.
+mkdir -p ${SRCTREE}
+if [ ! -d ${SRCTREE}/dports ]; then
+    cd ${SRCTREE} && \
+	svn -q --non-interactive --config-dir $SVN_CONFIG_DIR co $SVN_DPORTS_URL dports > $FAILURE_LOG 2>&1 \
+	|| { echo "Checking out the ports tree from $SVN_DPORTS_URL failed" >> $FAILURE_LOG ; bail ; }
 else
-	cd ${TREE}/dports && \
+    cd ${SRCTREE}/dports && \
 	svn -q --non-interactive --config-dir $SVN_CONFIG_DIR update > $FAILURE_LOG 2>&1 \
-		|| { echo "SVN update failed" >> $FAILURE_LOG ; FAILED=1 ; }
+	|| { echo "Updating the ports tree from $SVN_DPORTS_URL failed" >> $FAILURE_LOG ; bail ; }
 fi
-
-if [ ! -d ${TREE}/base ]; then
-        { echo "SVN update failed, please check out a copy of DP into ${TREE}" >> $FAILURE_LOG ; FAILED=1 ; }
+if [ ! -d ${SRCTREE}/base ]; then
+    cd ${SRCTREE} && \
+	svn -q --non-interactive --config-dir $SVN_CONFIG_DIR co $SVN_BASE_URL base > $FAILURE_LOG 2>&1 \
+	|| { echo "Checking out the base sources from $SVN_BASE_URL failed" >> $FAILURE_LOG ; bail ; }
 else
-    cd ${TREE}/base && \
-    svn -q --non-interactive --config-dir $SVN_CONFIG_DIR update > $FAILURE_LOG 2>&1 \
-        || { echo "SVN update failed" >> $FAILURE_LOG ; FAILED=1 ; }
+    cd ${SRCTREE}/base && \
+	svn -q --non-interactive --config-dir $SVN_CONFIG_DIR update > $FAILURE_LOG 2>&1 \
+       || { echo "Updating the base sources from $SVN_BASE_URL failed" >> $FAILURE_LOG ; bail ; }
 fi
 
 
 # (re)configure.
-if [ $FAILED -eq 0 ]; then
-	cd ${TREE}/base/ && \
-	mkdir -p ${TCLPKG} && \
-	./configure \
-		--prefix=${PREFIX} \
-		--with-tclpackage=${TCLPKG} \
-		--with-install-user=${DP_USER} \
-		--with-install-group=${DP_GROUP} > $FAILURE_LOG 2>&1 \
-		|| { echo "./configure failed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
+cd ${SRCTREE}/base/ && \
+    mkdir -p ${TCLPKG} && \
+    ./configure \
+    --prefix=${PREFIX} \
+    --with-tclpackage=${TCLPKG} \
+    --with-install-user=${MP_USER} \
+    --with-install-group=${MP_GROUP} > $FAILURE_LOG 2>&1 \
+    || { echo "./configure failed" >> $FAILURE_LOG ; bail ; }
 
 # clean
 # (cleaning is useful because we don't want the indexing to fail because dependencies aren't properly computed).
-if [ $FAILED -eq 0 ]; then
-	{ cd ${TREE}/base/ && \
-	make clean > $FAILURE_LOG 2>&1 ; } \
-		|| { echo "make clean failed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
+{ cd ${SRCTREE}/base/ && make clean > $FAILURE_LOG 2>&1 ; } \
+    || { echo "make clean failed" >> $FAILURE_LOG ; bail ; }
 
 # (re)build
-if [ $FAILED -eq 0 ]; then
-	{ cd ${TREE}/base/ && \
-	make > $FAILURE_LOG 2>&1 ; } \
-		|| { echo "make failed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
+{ cd ${SRCTREE}/base/ && make > $FAILURE_LOG 2>&1 ; } \
+    || { echo "make failed" >> $FAILURE_LOG ; bail ; }
 
 # (re)install
-if [ $FAILED -eq 0 ]; then
-	{ cd ${TREE}/base/ && \
-	make install > $FAILURE_LOG 2>&1 ; } \
-		|| { echo "make install failed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
+{ cd ${SRCTREE}/base/ && make install > $FAILURE_LOG 2>&1 ; } \
+    || { echo "make install failed" >> $FAILURE_LOG ; bail ; }
 
 # (re)index
-if [ $FAILED -eq 0 ]; then
-	{ cd ${TREE}/dports/ && \
-	${PREFIX}/bin/portindex > $FAILURE_LOG 2>&1 ; } \
-		|| { echo "portindex failed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
+{ cd ${SRCTREE}/dports/ && ${PREFIX}/bin/portindex > $FAILURE_LOG 2>&1 ; } \
+    || { echo "portindex failed" >> $FAILURE_LOG ; bail ; }
 
-# check all ports were indexed.
-if [ $FAILED -eq 0 ]; then
-	grep Failed $FAILURE_LOG \
-		&& { echo "some ports couldn\'t be indexed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
+# Commit the new index using the last 5 lines of the log for the commit message,
+tail -n 5 $FAILURE_LOG > $COMMIT_MSG
+# plus parsing failures, if any.
+echo "" >> $COMMIT_MSG
+grep Failed $FAILURE_LOG >> $COMMIT_MSG
+{ cd ${SRCTREE}/dports/ && \
+    svn --config-dir $SVN_CONFIG_DIR commit -F $COMMIT_MSG PortIndex > $FAILURE_LOG 2>&1 ; } \
+    || { echo "SVN commit failed" >> $FAILURE_LOG ; bail ; }
 
-# commit the file if and only if all ports were successfully indexed.
-if [ $FAILED -eq 0 ]; then
-	# Use the last 5 lines of the log for the commit message.
-	tail -n 5 $FAILURE_LOG > $COMMIT_MSG
-	
-	# Actually commit the file.
-	{ cd ${TREE}/dports/ && \
-	svn --config-dir $SVN_CONFIG_DIR commit -F $COMMIT_MSG PortIndex > $FAILURE_LOG 2>&1 ; } \
-		|| { echo "SVN commit failed" >> $FAILURE_LOG ; FAILED=1 ; }
-fi
-
-# spam if something went wrong.
-if [ $FAILED -ne 0 ]; then
-	mail -s "AutoIndex Failure on ${DATE}" $SPAM_LOVERS < $FAILURE_LOG
-else
-	# trash log files
-	rm -f $COMMIT_MSG $FAILURE_LOG
-fi
-
-rm -f $LOCKFILE
+# At this point the index was committed successfuly, so we cleanup before we exit.
+cleanup

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070327/c8213bc7/attachment.html


More information about the macports-changes mailing list