<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>By Programmer For Programmer &#187; supose</title>
	<atom:link href="http://byprogrammerforprogrammer.com/tag/supose/feed/" rel="self" type="application/rss+xml" />
	<link>http://byprogrammerforprogrammer.com</link>
	<description>Here I lay down the useful tips, tricks and utilities for programmers like myself.</description>
	<lastBuildDate>Fri, 02 Apr 2010 16:58:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SupoSE Bash Update Script (cron)</title>
		<link>http://byprogrammerforprogrammer.com/2009/10/supose-bash-update-script-cron/</link>
		<comments>http://byprogrammerforprogrammer.com/2009/10/supose-bash-update-script-cron/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 03:54:52 +0000</pubDate>
		<dc:creator>Sean Adkinson</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[supose]]></category>

		<guid isPermaLink="false">http://byprogrammerforprogrammer.com/?p=24</guid>
		<description><![CDATA[Script that can be used to update a Subversion index created with SupoSE, designed to be run via cron.]]></description>
			<content:encoded><![CDATA[<p>Hey everyone,</p>
<p>I created a bash script to update an index created by SupoSE, keeping track of what revision was last successfully updated.  I liked this better than their built-in scheduler because it has to continuously be running, and if for some reason our servers had to be restarted, it wouldn&#8217;t automatically start up again.  Thus, I made a script to set up in cron to run hourly.</p>
<p>To use this script:</p>
<ul>
<li>Create an index normally with SupoSE</li>
<li>Create a file to hold the last successfully indexed revision, and put this number in the file as the only text</li>
<li>Set the variables in the script below for your environment</li>
<li>Use bash 3.0 or higher, since I&#8217;m using regular expressions.  If this isn&#8217;t an option, you may just need to rewrite the parsing of &#8220;svn info&#8221; to get the HEAD revision.</li>
</ul>
<p>Enjoy!</p>
<pre>
#!/bin/sh

# Variables
SUPOSE_EXE="supose"
SUPOSE_LOC="/usr/local/supose/bin"
SVN_INDEX="/var/lib/supose/index/myindex"
SVN_URL="http://subversionurl/repo"
SVN_USER="username"
SVN_PASS="password"
LASTREV_FILE="/var/lib/supose/index/last.rev"

# Get the last successfully indexed revision
LASTREV=""
read -r LASTREV &lt; "$LASTREV_FILE"
if [ "$LASTREV" = "" ]; then
        echo "Please specify the last successfully indexed revision in $LASTREV_FILE"
        exit 1;
fi

# Get the "to" revision
TOREV=""
SVNINFO_CMD="svn info $SVN_URL"
SVNINFO=`$SVNINFO_CMD`
if [[ "$SVNINFO" =~ 'Revision: ([0-9]+)' ]]; then
        TOREV=${BASH_REMATCH[1]}
fi
if [ "$TOREV" = "" ]; then
        echo "**** ERROR ****"
        echo "Could not read the HEAD revision number from command: $SVNINFO_CMD"
        echo "Has subversion been updated with a different format?"
        echo "Output from command:"
        echo $SVNINFO
        exit 1;
fi

# Print some output
echo "Updating subversion: $SVN_URL"
echo "Last successful revision: $LASTREV"
echo "HEAD revision: $TOREV"
echo "Index location: $SVN_INDEX"
echo "..."

if [ "$LASTREV" -ge "$TOREV" ]; then
        echo "No revisions to update... skipping process"
        exit 0;
fi

# Add one to to get the FROM revision
let FROMREV=$LASTREV+1
if [ "$FROMREV" = "" ]; then
        echo "Error adding one to last successfully indexed revision: $LASTREV"
        exit 1;
fi

# Run the SupoSE command
SUPOSE_CMD="./$SUPOSE_EXE scan \
                --url $SVN_URL \
                --username $SVN_USER \
                --password $SVN_PASS \
                --fromrev $FROMREV \
                --torev $TOREV \
                --index $SVN_INDEX"
pushd $SUPOSE_LOC
echo "Running $SUPOSE_CMD"
$SUPOSE_CMD
popd

# Was there an error running SupoSE?
SUPOSE_STATUS="$?"
if [ "$SUPOSE_STATUS" -gt "0" ]; then
        echo "**** Error ****"
        echo "$SUPOSE_EXE returned status code: $SUPOSE_STATUS (not successful)"
        echo "File $LASTREV_FILE will not be updated with latest revision"
        echo "Command that was run:"
        echo $SUPOSE_CMD
        exit $SUPOSE_STATUS;
fi

# If no error, update last.rev file
echo "**** Operation completed successfully ****"
echo "Updating $LASTREV_FILE with revision: $TOREV"
echo "$TOREV" > "$LASTREV_FILE"
exit 0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://byprogrammerforprogrammer.com/2009/10/supose-bash-update-script-cron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
