Merge pull request #82 from ceph/wip-rm-blkin
[autobuild-ceph.git] / run-real
1 #!/bin/sh
2 set -e
3
4 # use sun-java6
5 export CPATH="$CPATH:/usr/lib/jvm/default-java/include:/usr/lib/jvm/default-java/include/linux"
6
7
8 ./autobuilder.sh
9
10 REF_OUTDIR="out/output/ref"
11 SHA_OUTDIR="out/output/sha1"
12
13 mkdir -p $REF_OUTDIR
14 mkdir -p $SHA_OUTDIR
15
16 # clean up temp files from aborted runs of below symlinking; all tmp
17 # files are stale
18 find "$REF_OUTDIR" -mindepth 1 -maxdepth 1 -name '*.tmp' -print0 \
19 | xargs -0 --no-run-if-empty rm -f --
20
21 # update symlinks that make branch point to the latest successful
22 # output dir for that branch
23 install -d -m0755 -- "$REF_OUTDIR"
24 ( ./branches.sh -v ) \
25 | while read SHA REF; do
26     # mangle unsafe characters in branch names, just in case (slashes
27     # and leading periods); gitbuilder hanging on to "origin/" here
28     # makes the typical result a bit ugly
29     SAFE_REF="$(printf '%s' "$REF"|tr -c 'a-zA-Z0-9_.-' '_'|sed 's/^\./_/')"
30
31     # strip out the leading origin_ prefix on branches; this might cause
32     # collisions, but we're gonna ignore that for now
33     SAFE_REF="${SAFE_REF#origin_}"
34
35     # echo "ref $SAFE_REF $SHA"
36
37     if [ -L "$REF_OUTDIR/$SAFE_REF" ]; then
38         # keep symlink fresh
39         touch --no-dereference "$REF_OUTDIR/$SAFE_REF"
40     else
41         if [ -e "out/pass/$SHA" ]; then
42             # we did a successful build; make a new symlink.  this only
43             # happens if we aborted somewhere before, though; the pass.sh
44             # really should have done this!
45             ln -s -- "../sha1/$SHA" "$REF_OUTDIR/$SAFE_REF.tmp"
46             mv --no-target-directory -- "$REF_OUTDIR/$SAFE_REF.tmp" "$REF_OUTDIR/$SAFE_REF"
47         fi
48     fi
49 done
50
51 target=`cat ../rsync-target`
52 target_host=`cat ../rsync-target | sed 's/:.*//'`
53 target_dir=`cat ../rsync-target | sed 's/.*://'`
54 echo "rsync target host $target_host dir $target_dir"
55
56 # remove refs symlinks that haven't been touched in 48 hours; as the
57 # above will always touch everything, they are guaranteed fresh
58 find "$REF_OUTDIR" -mindepth 1 -maxdepth 1 -mtime +1  \
59 | while read old ; do
60     ref=`echo $old | sed 's/.*\///'`
61     echo "removing old ref $ref"
62     rm $old
63 done
64
65 # clean temp output dirs; since there cannot be a build running in
66 # parallel with us, all tmp files are stale
67 find "$SHA_OUTDIR" -mindepth 1 -maxdepth 1 -name '*.tmp' -print0 \
68 | xargs -0 --no-run-if-empty rm -rf --
69
70 # rsync --delete on the refs, so that stale refs on the target are
71 # removed.  remove remote sha1 dirs that are stale.
72 if [ -n "$target" ]; then
73     echo "removing old refs"
74     rsync -auv --delete -e "ssh -i ../rsync-key -o StrictHostKeyChecking=no" \
75         "$REF_OUTDIR/" $target/ref
76
77     # touch any active sha1 dirs, and remove any older than 4 days.
78     echo "removing old builds"
79     ssh -i ../rsync-key -o StrictHostKeyChecking=no $target_host \
80         touch $target_dir/ref/\*/. \; \
81         find $target_dir/sha1 -mindepth 1 -maxdepth 1 -mtime +7 \| \
82         xargs --no-run-if-empty -- rm -rfv --
83 fi