b33276e965c8855bba5d319ba84aa5ea6eb2ca8c
[infrastructure.git] / scripts / all-modules.sh
1 #!/bin/bash
2
3 # reviewed in dec. 2010
4 # moving back to running on the EU side
5
6 # this script is a wrapper around the module-tools (version and diff)
7 # it is invoked cyclically
8 # prior to that, the following directories will have been svn updated :
9 # ~/git-build
10
11 # avoid running several instances of this script
12 # when the svn server has problems, this can very well last quite a while
13
14 COMMAND=$(basename $0)
15
16 # running as root on liquid
17 OUTPUT=/build/modules
18 LOCK=~/all-modules.run
19 # make sure the cyclic tasks do not interfere with manual usage
20 # (i.e. do not use ~/modules)
21 WORKDIR_GIT=${HOME}/all-modules-git
22 ########## sample config running on liquid
23 #svnpath=http://svn.planet-lab.org/svn/
24 #gitserver=git.onelab.eu
25 #gituser=root
26 #build=build
27 #username=not-needed-as-we-dont-write
28 #email=not-needed-as-we-dont-write
29 ##########
30
31 function do_update() {
32     build_dir=$1; shift
33     if [ -f $build_dir/auto-update.sh ] ; then
34         $build_dir/auto-update.sh
35     elif [ -d $build_dir/.git ] ; then
36         ( cd $build_dir; git pull > .update.log 2>&1 )
37     else
38         ( cd $build_dir; svn update > .update.log 2>&1 )
39     fi
40 }
41
42 # usage: do_version dir workdir wwwname 
43 function do_version () {
44     build_dir=$1; shift
45     workdir=$1; shift
46     wwwname=$1; shift
47
48     out_dir=$OUTPUT/$wwwname
49     out_file=$out_dir/version.html
50     out_tmp=$out_dir/.version.html
51     
52     mkdir -p $out_dir
53     $build_dir/module-version $VERBOSE -w $workdir --www $wwwname -a &> $out_tmp
54     mv -f $out_tmp $out_file
55 }
56
57 # usage: do_version dir workdir wwwname 
58 function do_diff () {
59     build_dir=$1; shift
60     workdir=$1; shift
61     wwwname=$1; shift
62
63     out_dir=$OUTPUT/$wwwname
64     out_file=$out_dir/diff.html
65     out_tmp=$out_dir/.diff.html
66     
67     mkdir -p $out_dir
68     $build_dir/module-diff $VERBOSE -w $workdir --www $wwwname -a &> $out_tmp
69     mv -f $out_tmp $out_file
70
71 }
72
73 function usage () {
74     echo "Usage: $COMMAND [-v] [-f] [-i]"
75 }
76
77 function main () {
78
79     while [[ -n "$@" ]] ; do
80         case "$1" in 
81             -f) rm -f $LOCK ;;
82             -i) ls -l $LOCK ; exit 0 ;;
83             -v) set -x ; VERBOSE=-v ;;
84             *) usage; exit 1;;
85         esac
86         shift
87     done
88
89     [ -f $LOCK ] && exit 1
90     
91     echo $$ > $LOCK
92
93     do_update  ~/git-build
94     do_version ~/git-build     $WORKDIR_GIT 5.0 
95     do_diff    ~/git-build     $WORKDIR_GIT 5.0
96
97     rm $LOCK
98
99 }
100
101 main "$@"
102
103 ########################################
104 # this applied to the older version that was running at princeton
105 # NOTE
106 # as the svn diff operations from a remote location are so sssssslllllllooooooooowwwwww...
107 # what we do:
108 # maintain codebase in onelab.eu for historical reasons
109 # (1) push scripts on princeton (manually run all-modules-update.sh)
110 # (2) run the scripts cyclically over there through cron
111 # and push the results on build.onelab.eu with all-modules.push.sh (as part of the cron job)
112 #