1 | #!/bin/ksh |
---|
2 | #set -xv |
---|
3 | # |
---|
4 | # Use this script to propagated modifcations done to files in one configuration |
---|
5 | # into the all other configurations in the same directory. Files will be copied |
---|
6 | # only where they already exist. |
---|
7 | # |
---|
8 | # Syntax : |
---|
9 | # ./propagate_master_config MyConfig |
---|
10 | # Modifcations in MyConfig will be copied to the other configurations. |
---|
11 | |
---|
12 | # Josefine Ghattas IPSL |
---|
13 | |
---|
14 | if [ $# == 0 ] ; then |
---|
15 | echo "You need to specify the configuration from which the modifications will be propagted" |
---|
16 | echo "./propagate_master_config MyConfig" |
---|
17 | exit |
---|
18 | fi |
---|
19 | |
---|
20 | MasterConfig=$1 |
---|
21 | verbose=yes |
---|
22 | BaseDir=`pwd` |
---|
23 | ConfigFamily=$( echo $MasterConfig | awk -F"_" '{print $2}' ) |
---|
24 | ConfigList=`ls |grep ${ConfigFamily} |grep -v out |grep -v $MasterConfig` |
---|
25 | |
---|
26 | echo All modifications in configuration $MasterConfig will copied to the other configurations $ConfigList |
---|
27 | |
---|
28 | cd $BaseDir/$MasterConfig |
---|
29 | FileList=`ls -d GENERAL/DRIVER/* GENERAL/PARAM/* GENERAL/POST/* EXPERIMENTS/*/*/* EXPERIMENTS/*/*/*/*` |
---|
30 | |
---|
31 | cpfile=$BaseDir/cpfile |
---|
32 | |
---|
33 | echo "" > $cpfile |
---|
34 | cd $BaseDir |
---|
35 | |
---|
36 | for conf in $ConfigList ; do |
---|
37 | for file in $FileList ; do |
---|
38 | if [ -f ${conf}/${file} ] ; then |
---|
39 | cmp -s ${MasterConfig}/${file} ${conf}/${file} |
---|
40 | if [ $? -ne 0 ] ; then |
---|
41 | # Files are differents |
---|
42 | echo "cp ${MasterConfig}/${file} ${conf}/${file}" >> $cpfile |
---|
43 | if [ $verbose == yes ] ; then |
---|
44 | diff --brief ${MasterConfig}/${file} ${conf}/${file} |
---|
45 | diff ${MasterConfig}/${file} ${conf}/${file} |
---|
46 | fi |
---|
47 | fi |
---|
48 | fi |
---|
49 | done |
---|
50 | echo "" >> $cpfile |
---|
51 | done |
---|
52 | |
---|
53 | # Test if there is nothing to copy |
---|
54 | if [ $( grep cp $cpfile |wc -l ) -eq 0 ] ; then |
---|
55 | echo "Noting to be done. All files are the same." |
---|
56 | rm $cpfile |
---|
57 | exit |
---|
58 | fi |
---|
59 | |
---|
60 | # List files to copy and ask for permission to copy |
---|
61 | echo "" |
---|
62 | cat $cpfile |
---|
63 | |
---|
64 | echo "Would you like to do the actions listed above, answer yes/no ?" |
---|
65 | echo -n " Your answer : " |
---|
66 | read answer |
---|
67 | |
---|
68 | case ${answer} in |
---|
69 | yes|y) |
---|
70 | chmod +x $cpfile |
---|
71 | $cpfile |
---|
72 | echo "Copy has now been done." |
---|
73 | ;; |
---|
74 | no|n) |
---|
75 | echo "Nothing will be done" |
---|
76 | ;; |
---|
77 | *) |
---|
78 | echo "Bad answer. Nothing will be dnoe" |
---|
79 | ;; |
---|
80 | esac |
---|
81 | rm $cpfile |
---|
82 | |
---|
83 | exit |
---|