protect against concurrent runs - redone
authorthierry <thierry@41d37cc5-eb28-0410-a9bf-d37491348ade>
Wed, 11 Jun 2008 08:12:39 +0000 (08:12 +0000)
committerthierry <thierry@41d37cc5-eb28-0410-a9bf-d37491348ade>
Wed, 11 Jun 2008 08:12:39 +0000 (08:12 +0000)
scripts/all-modules.sh

index a43dd8a..0c81374 100755 (executable)
 # when the svn server has problems, this can very well last quite a while
 
 COMMAND=$(basename $0)
-pid=$$
-running=$(pgrep $COMMAND 2> /dev/null | grep -v "^${pid}"'^' )
-# bail out if another instance is already running
-[ -n "$running" ] && exit 1
-
 OUTPUT=/build/modules
+LOCK=/var/run/all-modules.pid
 
 # usage: do_version dir name 
 function do_version () {
@@ -58,7 +54,33 @@ function do_diff () {
     rm -f $out_tmp
 }
 
-do_version /root/svn-build-4.2 4.2 
-do_diff    /root/svn-build-4.2 4.2 
-do_version /root/svn-build     trunk 
-do_diff    /root/svn-build     trunk 
+function usage () {
+    echo "Usage: $COMMAND [-v] [-f] [-i]"
+}
+
+function main () {
+
+    while [[ -n "$@" ]] ; do
+       case "$1" in 
+           -f) rm -f $LOCK ;;
+           -i) ls -l $LOCK ; exit 0 ;;
+           -v) set -x ;;
+           *) usage; exit 1;;
+       esac
+       shift
+    done
+
+    [ -f $LOCK ] && exit 1
+    
+    echo $$ > $LOCK
+
+    do_version /root/svn-build-4.2 4.2 
+    do_diff    /root/svn-build-4.2 4.2 
+    do_version /root/svn-build     trunk 
+    do_diff    /root/svn-build     trunk 
+
+    rm $LOCK
+
+}
+
+main "$@"