5 export CPATH="$CPATH:/usr/lib/jvm/default-java/include:/usr/lib/jvm/default-java/include/linux"
10 REF_OUTDIR="out/output/ref"
11 SHA_OUTDIR="out/output/sha1"
16 # clean up temp files from aborted runs of below symlinking; all tmp
18 find "$REF_OUTDIR" -mindepth 1 -maxdepth 1 -name '*.tmp' -print0 \
19 | xargs -0 --no-run-if-empty rm -f --
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/^\./_/')"
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_}"
35 # echo "ref $SAFE_REF $SHA"
37 if [ -L "$REF_OUTDIR/$SAFE_REF" ]; then
39 touch --no-dereference "$REF_OUTDIR/$SAFE_REF"
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"
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"
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 \
60 ref=`echo $old | sed 's/.*\///'`
61 echo "removing old ref $ref"
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 --
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
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 --