0edb377391c5d9c6c8e1fcb89475b30574f6a34c
[progcomp2013.git] / qchess / update.sh
1 #!/bin/bash
2
3 # I still can't believe I am doing this
4
5 target=qchess.py
6 components="piece.py board.py player.py thread_util.py game.py graphics.py main.py"
7 # The below seems nicer, but doesn't work because things need to be imported in the right order :(
8 #components=$(ls *.py | tr '\t' '\n' | grep -v $target)
9
10 header="#!/usr/bin/python -u"
11 footer="# EOF - created from update.sh on $(date)"
12
13
14
15 # If the target was modified more recently than any of the components, update the component file
16 target_mod=$(stat -c %Y $target)
17
18 merge_required=false
19
20 for f in $components; do
21         if [ $(stat -c %Y $f) -lt $target_mod ]; then
22                 nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---" > $f
23         else
24                 merge_required=true
25 done
26
27 if $merge_required; then
28         echo $header > $target
29         for f in $components; do
30                 cat $components >> $target
31         done
32
33         echo $footer > $target
34 fi

UCC git Repository :: git.ucc.asn.au