Mostly networking
[progcomp2013.git] / qchess / update.sh
1 #!/bin/bash
2
3 # I still can't believe I am doing this
4
5 # (This can't be done with gnu make, because of circular dependency issues)
6
7 target=qchess.py
8 components="piece.py board.py player.py network.py thread_util.py game.py graphics.py main.py"
9 # The below seems nicer, but doesn't work because things need to be imported in the right order :(
10 #components=$(ls *.py | tr '\t' '\n' | grep -v $target)
11
12 header="#!/usr/bin/python -u"
13 footer="# EOF - created from update.sh on $(date)"
14
15
16
17 # If the target was modified more recently than any of the components, update the component file
18 target_mod=$(stat -c %Y $target 2>/dev/null)
19
20 if [ $? -ne 0 ]; then
21         merge_required=true
22 else
23         merge_required=true
24
25
26         echo "
27         for f in $components; do
28                 
29                 component_mod=$(stat -c %Y $f 2>/dev/null)
30                 if [ $? -ne 0 ]; then
31                         update_required=true
32                 elif [ $component_mod -lt $target_mod ]; then
33                         update_required=true
34                 else
35                         update_required=false
36                 fi
37
38                 if $update_required; then
39                         echo "$0 - update $f from $target"
40                         sanity=$(egrep "(+++ $f +++)|(--- $f ---)" $target | wc -l)
41                         if [ $sanity -ne 2 ]; then
42                                 $(echo "$0 - $target does not have markers for $f in it!") 1>&2
43                                 exit 1
44                         fi
45                         cp $f $f~
46                         new_contents=$(nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---")
47                         
48                         echo "$new_contents" > $f
49                 else
50                         echo "$0 - $f is newer than $target"
51                         merge_required=true
52                 fi
53         done
54         " > /dev/null
55
56 fi
57
58 # If any components were modified more recently than the target, merge the components into the target
59 if $merge_required; then
60         echo $header > $target
61         for f in $components; do
62                 echo "$0 - merge $f into $target"
63                 echo "# +++ $f +++ #" >> $target
64                 cat $f >> $target
65                 echo "# --- $f --- #" >> $target
66         done
67
68         echo $footer >> $target
69         chmod u+x $target
70 fi

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