[1691] | 1 | #!/bin/ksh |
---|
[1743] | 2 | #set -xv |
---|
[1691] | 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` |
---|
[2106] | 23 | ConfigFamily=$( echo $MasterConfig | awk -F"_" '{print $2}' | awk -F"." '{print $1}' ) |
---|
| 24 | echo ConfigFamily=$ConfigFamily |
---|
[1691] | 25 | |
---|
[2106] | 26 | # ConfigListOther : all configurations except MasterConfig. The configurations must contain ConfigFamily in the name |
---|
| 27 | ConfigListOther=`ls |grep ${ConfigFamily} |grep -v out |grep -vx $MasterConfig` |
---|
[2052] | 28 | |
---|
[2106] | 29 | echo All modifications in configuration $MasterConfig will copied to the other configurations : |
---|
| 30 | echo $ConfigListOther |
---|
[1691] | 31 | |
---|
| 32 | cd $BaseDir/$MasterConfig |
---|
[1742] | 33 | FileList=`ls -d GENERAL/DRIVER/* GENERAL/PARAM/* GENERAL/POST/* EXPERIMENTS/*/*/* EXPERIMENTS/*/*/*/*` |
---|
[1691] | 34 | |
---|
| 35 | cpfile=$BaseDir/cpfile |
---|
| 36 | |
---|
| 37 | echo "" > $cpfile |
---|
| 38 | cd $BaseDir |
---|
[1743] | 39 | |
---|
[2106] | 40 | for conf in $ConfigListOther ; do |
---|
[1691] | 41 | for file in $FileList ; do |
---|
| 42 | if [ -f ${conf}/${file} ] ; then |
---|
| 43 | cmp -s ${MasterConfig}/${file} ${conf}/${file} |
---|
| 44 | if [ $? -ne 0 ] ; then |
---|
| 45 | # Files are differents |
---|
| 46 | echo "cp ${MasterConfig}/${file} ${conf}/${file}" >> $cpfile |
---|
| 47 | if [ $verbose == yes ] ; then |
---|
| 48 | diff --brief ${MasterConfig}/${file} ${conf}/${file} |
---|
| 49 | diff ${MasterConfig}/${file} ${conf}/${file} |
---|
| 50 | fi |
---|
| 51 | fi |
---|
| 52 | fi |
---|
| 53 | done |
---|
| 54 | echo "" >> $cpfile |
---|
| 55 | done |
---|
| 56 | |
---|
| 57 | # Test if there is nothing to copy |
---|
[1698] | 58 | if [ $( grep cp $cpfile |wc -l ) -eq 0 ] ; then |
---|
[1691] | 59 | echo "Noting to be done. All files are the same." |
---|
| 60 | rm $cpfile |
---|
| 61 | exit |
---|
| 62 | fi |
---|
| 63 | |
---|
| 64 | # List files to copy and ask for permission to copy |
---|
| 65 | echo "" |
---|
| 66 | cat $cpfile |
---|
| 67 | |
---|
| 68 | echo "Would you like to do the actions listed above, answer yes/no ?" |
---|
| 69 | echo -n " Your answer : " |
---|
| 70 | read answer |
---|
| 71 | |
---|
| 72 | case ${answer} in |
---|
| 73 | yes|y) |
---|
| 74 | chmod +x $cpfile |
---|
| 75 | $cpfile |
---|
| 76 | echo "Copy has now been done." |
---|
| 77 | ;; |
---|
| 78 | no|n) |
---|
| 79 | echo "Nothing will be done" |
---|
| 80 | ;; |
---|
| 81 | *) |
---|
| 82 | echo "Bad answer. Nothing will be dnoe" |
---|
| 83 | ;; |
---|
| 84 | esac |
---|
| 85 | rm $cpfile |
---|
| 86 | |
---|
| 87 | exit |
---|