1 | #!/bin/ksh |
---|
2 | |
---|
3 | #************************************************************** |
---|
4 | # Author: Martial Mancip |
---|
5 | # Contact: Martial.Mancip__at__ipsl.jussieu.fr |
---|
6 | # $Revision:: $ Revision of last commit |
---|
7 | # $Author:: $ Author of last commit |
---|
8 | # $Date:: $ Date of last commit |
---|
9 | # IPSL (2006) |
---|
10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
11 | # |
---|
12 | #************************************************************** |
---|
13 | |
---|
14 | # Documentation : |
---|
15 | # This script may be used to create a tree of last configuration downloaded by modipsl/util/model command. |
---|
16 | # |
---|
17 | # It checks the control version used for each components of the configuration and saves the diff |
---|
18 | # between the revision downloaded (or updated) and the modifications of the developper. |
---|
19 | # It saves those diff in the component directory in the copy tree. |
---|
20 | # It saves also new source files. See SUFFIXES definition below for the list of extension to detect source files. |
---|
21 | # |
---|
22 | # It also gives a Last_log file in the root of the save tree with all informations needed to download the same |
---|
23 | # configuration precisely. It has the list of new and modified files and give the date (in an non human format) |
---|
24 | # of each modifications. |
---|
25 | # |
---|
26 | # It may be used in modipsl directory : |
---|
27 | # modipsl_path> util/script_diff_model |
---|
28 | # |
---|
29 | # After this use, you will have a modipsl_path/modipsl_save_diff_$( date +%F_%H%M%S ) tree that |
---|
30 | # you can tar and save with the executable you have build with this modified configuration. |
---|
31 | # |
---|
32 | # Note : |
---|
33 | # Be aware to modify AA_make files in your model source code tree (and not only Makefiles) if you use modipsl |
---|
34 | # ins_make script and portable Makefile build. In this case, Makefiles won't be versionning and modifications |
---|
35 | # won't be saves. |
---|
36 | # |
---|
37 | # You can use ___ script_recup_model ___ script to download the same configuration and make change |
---|
38 | # with new files and modified source files. |
---|
39 | |
---|
40 | |
---|
41 | # env must know MODIPSL path variable ! |
---|
42 | MODIPSL=${MODIPSL:=$(pwd)} |
---|
43 | |
---|
44 | DEBUG_mode=false |
---|
45 | |
---|
46 | function printDebugArray { |
---|
47 | if ( ${DEBUG_mode} ); then |
---|
48 | typeset nb_line i |
---|
49 | eval nb_line=\${#$1[@]} |
---|
50 | eval echo "$1 : " ${nb_line} |
---|
51 | (( i = 0 )) |
---|
52 | while [ $i -lt $nb_line ] ; do |
---|
53 | eval echo \${$1[$i]} |
---|
54 | (( i = i + 1 )) |
---|
55 | done |
---|
56 | fi |
---|
57 | } |
---|
58 | |
---|
59 | typeset tag thedate save_diff_file pathComp pathexist i filecomp filedate file SpathComp SUFFIXES NbNewFiles NbModifFiles Maxfiledate |
---|
60 | |
---|
61 | # Analyse log file: get last model command |
---|
62 | . ${MODIPSL}/util/script_log_analyse |
---|
63 | |
---|
64 | # Code source suffixe for new file detection |
---|
65 | SUFFIXES='\(f90\|F90\|f\|F\|h\|h90\|hh\|c\|cc\|inc\|fcm\|path\|cfg\|card\|driver\|def\|def_.*\|txt\|xml\|ksh\|tex\)' |
---|
66 | |
---|
67 | MODIPSL_SAVE_NAME=modipsl_save_diff_$( date +%F_%H%M%S ) |
---|
68 | echo "out directory in " ${MODIPSL_SAVE_NAME} |
---|
69 | MODIPSL_SAVE=${MODIPSL}/${MODIPSL_SAVE_NAME} |
---|
70 | printDebugArray MODIPSL_SAVE |
---|
71 | |
---|
72 | set +A ListRep -- $( find ${MODIPSL} -mindepth 1 -type d \ |
---|
73 | \( -not -path '*.svn*' -a -not -path '*CVS*' -a -not -path "${MODIPSL}/modipsl_save*" \ |
---|
74 | -a -not -path "${MODIPSL}/bin" -a -not -path "${MODIPSL}/lib" -a -not -path "${MODIPSL}/util" \ |
---|
75 | -a -not -path "${MODIPSL}/tmp" \) \ |
---|
76 | -exec bash -c " echo "'{}'" | sed -e 's&"${MODIPSL}"/&&' | tee -a >( sed -e 's&\(.*\)&"${MODIPSL_SAVE}"/\1&' | xargs mkdir -p >> out_mkdir 2>&1 ) " \; ) |
---|
77 | rm out_mkdir |
---|
78 | #echo ${ListRep[0]} | tee $(ls > toto) $(ls -la > tata) |
---|
79 | #mkdir -Rp ${MODIPSL_SAVE}/ |
---|
80 | printDebugArray ListRep |
---|
81 | |
---|
82 | |
---|
83 | echo "Last Model in log : " ${ListModelCommands[$ModelNul]} | sed -e 's&::& &g' > ${MODIPSL_SAVE}/Last_log |
---|
84 | echo "${NbComponents} components : " >> ${MODIPSL_SAVE}/Last_log |
---|
85 | echo ${ModelComponents[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
86 | echo ${ModelTags[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
87 | echo ${ModelSystems[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
88 | echo ${ModelServers[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
89 | echo ${ModelDirectories[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
90 | echo ${ModelLocalDirs[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
91 | |
---|
92 | thedate=$( echo ${ListModelDates[${ModelNum}]} | sed -e "s&_& &g" | sed -e "s&-&/&g") |
---|
93 | |
---|
94 | |
---|
95 | (( NbNewFiles = 0 )) |
---|
96 | (( NbModifFiles = 0 )) |
---|
97 | (( Maxfiledate = 0 )) |
---|
98 | (( i = 0 )) |
---|
99 | for comp in ${ModelComponents[@]}; do |
---|
100 | tag=${ModelTags[$i]} |
---|
101 | echo $i $comp " : " $tag |
---|
102 | |
---|
103 | case ${ModelLocalDirs[$i]} in |
---|
104 | [a-z]*) |
---|
105 | if [ X${ModelDirectories[$i]} = X. ] ; then |
---|
106 | pathComp=${ModelLocalDirs[i]}/${ModelComponents[$i]} |
---|
107 | if [ -f ${pathComp} ] ; then |
---|
108 | filecomp=$( basename ${pathComp} ) |
---|
109 | ListPathFile[$i]=${filecomp} |
---|
110 | pathComp=$( dirname ${pathComp} ) |
---|
111 | pathexist=true |
---|
112 | elif [ -d ${pathComp} ] ; then |
---|
113 | filecomp="" |
---|
114 | ListPathFile[$i]=_empty_ |
---|
115 | pathexist=true |
---|
116 | elif [ -d ${ModelLocalDirs[i]}/$( basename ${ModelComponents[$i]} ) ] ; then |
---|
117 | pathComp=${ModelLocalDirs[i]}/$( basename ${ModelComponents[$i]} ) |
---|
118 | filecomp="" |
---|
119 | ListPathFile[$i]=_empty_ |
---|
120 | pathexist=true |
---|
121 | else |
---|
122 | echo "error for component : ${comp} !!" |
---|
123 | echo " ${pathComp} does not exist." |
---|
124 | pathexist=false |
---|
125 | fi |
---|
126 | else |
---|
127 | pathComp=${ModelLocalDirs[i]}/${ModelDirectories[$i]} |
---|
128 | if [ -f ${pathComp} ] ; then |
---|
129 | filecomp=$( basename ${pathComp} ) |
---|
130 | ListPathFile[$i]=${filecomp} |
---|
131 | pathComp=$( dirname ${pathComp} ) |
---|
132 | pathexist=true |
---|
133 | elif [ -d ${pathComp} ] ; then |
---|
134 | filecomp="" |
---|
135 | ListPathFile[$i]=_empty_ |
---|
136 | pathexist=true |
---|
137 | else |
---|
138 | echo "error for component : ${comp} !!" |
---|
139 | echo " ${pathComp} does not exist." |
---|
140 | pathexist=false |
---|
141 | fi |
---|
142 | fi |
---|
143 | ;; |
---|
144 | \.) |
---|
145 | pathComp=${ModelDirectories[$i]} |
---|
146 | if [ -f ${pathComp} ] ; then |
---|
147 | filecomp=$( basename ${pathComp} ) |
---|
148 | ListPathFile[$i]=${filecomp} |
---|
149 | pathComp=$( dirname ${pathComp} ) |
---|
150 | pathexist=true |
---|
151 | elif [ -d ${pathComp} ] ; then |
---|
152 | filecomp="" |
---|
153 | ListPathFile[$i]=_empty_ |
---|
154 | pathexist=true |
---|
155 | else |
---|
156 | echo "error for component : ${comp} !!" |
---|
157 | echo " ${pathComp} does not exist." |
---|
158 | pathexist=false |
---|
159 | fi |
---|
160 | ;; |
---|
161 | *) |
---|
162 | echo "error ${ModelLocalDirs[$i]} is not recognized as a valid path in modipsl." |
---|
163 | exit 1 |
---|
164 | ;; |
---|
165 | esac |
---|
166 | |
---|
167 | if ( ${pathexist} ) ; then |
---|
168 | echo "real local path = " ${pathComp} |
---|
169 | ListPathComp[$i]=${pathComp} |
---|
170 | |
---|
171 | |
---|
172 | cd ${pathComp} |
---|
173 | SpathComp=${MODIPSL_SAVE}/${pathComp} |
---|
174 | |
---|
175 | save_diff_file=$( echo ${comp} | sed -e 's&/&:&g' ) |
---|
176 | |
---|
177 | case ${ModelSystems[$i]} in |
---|
178 | svn) |
---|
179 | ListPathRev[$i]=$( svn info ${filecomp} | grep "R.vision *:" | gawk -F ' ' '{print $2}' ) |
---|
180 | ListPathBranch[$i]=${comp} |
---|
181 | |
---|
182 | svn diff ${filecomp} > ${MODIPSL}/svn_diff_${save_diff_file} |
---|
183 | RET=$? |
---|
184 | if [ $RET -gt 0 ] ; then |
---|
185 | ListPathComp[$i]="error" |
---|
186 | ListPathFile[$i]="error" |
---|
187 | ListPathRev[$i]="error" |
---|
188 | ListPathBranch[$i]="error" |
---|
189 | else |
---|
190 | svn status ${filecomp} > ${MODIPSL}/svn_status_${save_diff_file} |
---|
191 | set -A NewFiles -- $( grep "^? *\(.*\.${SUFFIXES}\|AA_.*\|BB_.*\)$" ${MODIPSL}/svn_status_${save_diff_file} | sed -e "s&? *&&" ) |
---|
192 | printDebugArray NewFiles |
---|
193 | for file in ${NewFiles[@]} ; do |
---|
194 | echo "New file : " $file |
---|
195 | cp -p $file ${SpathComp}/$( dirname $file ) |
---|
196 | ListNewFiles[$NbNewFiles]=${pathComp}/${file} |
---|
197 | (( NbNewFiles = NbNewFiles + 1 )) |
---|
198 | done |
---|
199 | |
---|
200 | set -A ModifiedFiles -- $( grep "^M *" ${MODIPSL}/svn_status_${save_diff_file} | sed -e "s&M *&&" ) |
---|
201 | printDebugArray ModifiedFiles |
---|
202 | for file in ${ModifiedFiles[@]} ; do |
---|
203 | echo "Modified file : " $file |
---|
204 | filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F ' ' '{print $6}' ) |
---|
205 | Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate )) |
---|
206 | ListModifFiles[$NbModifFiles]=${pathComp}/${file} |
---|
207 | ListModifFilesDate[$NbModifFiles]=${filedate} |
---|
208 | (( NbModifFiles = NbModifFiles + 1 )) |
---|
209 | done |
---|
210 | |
---|
211 | if ( ${DEBUG_mode} ); then |
---|
212 | cp ${MODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff |
---|
213 | else |
---|
214 | rm ${MODIPSL}/svn_status_${save_diff_file} |
---|
215 | mv ${MODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff |
---|
216 | fi |
---|
217 | RET=$? |
---|
218 | if [ $RET -gt 0 ] ; then |
---|
219 | ListPathComp[$i]="error" |
---|
220 | ListPathFile[$i]="error" |
---|
221 | ListPathRev[$i]="error" |
---|
222 | ListPathBranch[$i]="error" |
---|
223 | fi |
---|
224 | fi |
---|
225 | |
---|
226 | ;; |
---|
227 | cvs) |
---|
228 | ListPathRev[$i]=${tag}:\"${thedate}\" |
---|
229 | ListPathBranch[$i]=${tag} |
---|
230 | |
---|
231 | cvs diff -U 2 ${filecomp} > ${MODIPSL}/cvs_diff_${save_diff_file}_00 |
---|
232 | #eval cvs diff -U 2 -r "${ListPathRev[$i]}" ${filecomp} > ${MODIPSL}/cvs_diff_${save_diff_file}_00 |
---|
233 | RET=$? |
---|
234 | if [ $RET -gt 1 ] ; then |
---|
235 | ListPathComp[$i]="error" |
---|
236 | ListPathFile[$i]="error" |
---|
237 | ListPathRev[$i]="error" |
---|
238 | ListPathBranch[$i]="error" |
---|
239 | else |
---|
240 | set -A NewFiles -- $( grep "^? .*\.${SUFFIXES}$" ${MODIPSL}/cvs_diff_${save_diff_file}_00 | sed -e "s&? *&&" ) |
---|
241 | printDebugArray NewFiles |
---|
242 | for file in ${NewFiles[@]} ; do |
---|
243 | echo "New file : " $file |
---|
244 | cp -p $file ${SpathComp}/$( dirname $file ) |
---|
245 | ListNewFiles[$NbNewFiles]=${pathComp}/${file} |
---|
246 | (( NbNewFiles = NbNewFiles + 1 )) |
---|
247 | done |
---|
248 | |
---|
249 | set -A ModifiedFiles -- $( grep "^M .*\.${SUFFIXES}$" ${MODIPSL}/cvs_diff_${save_diff_file}_00 | sed -e "s&M *&&" ) |
---|
250 | printDebugArray ModifiedFiles |
---|
251 | for file in ${ModifiedFiles[@]} ; do |
---|
252 | echo "Modified file : " $file |
---|
253 | filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F ' ' '{print $6}' ) |
---|
254 | Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate )) |
---|
255 | ListModifFiles[$NbModifFiles]=${pathComp}/${file} |
---|
256 | ListModifFilesDate[$NbModifFiles]=${filedate} |
---|
257 | (( NbModifFiles = NbModifFiles + 1 )) |
---|
258 | done |
---|
259 | |
---|
260 | ${MODIPSL}/util/correct-cvs-diff.awk ${MODIPSL}/cvs_diff_${save_diff_file}_00 > ${MODIPSL}/cvs_diff_${save_diff_file}_01 |
---|
261 | RET=$? |
---|
262 | if ( ${DEBUG_mode} ); then |
---|
263 | cp ${MODIPSL}/cvs_diff_${save_diff_file}_01 ${SpathComp}/cvs_diff |
---|
264 | else |
---|
265 | mv ${MODIPSL}/cvs_diff_${save_diff_file}_01 ${SpathComp}/cvs_diff |
---|
266 | rm ${MODIPSL}/cvs_diff_${save_diff_file}_00 |
---|
267 | fi |
---|
268 | RET1=$? |
---|
269 | (( RET = RET + RET1 )) |
---|
270 | if [ $RET -gt 0 ] ; then |
---|
271 | ListPathComp[$i]="error" |
---|
272 | ListPathFile[$i]="error" |
---|
273 | ListPathRev[$i]="error" |
---|
274 | ListPathBranch[$i]="error" |
---|
275 | fi |
---|
276 | fi |
---|
277 | ;; |
---|
278 | *) |
---|
279 | echo "error ${ModelSystems[$i]} is not recognized as a valid control version system for $0." |
---|
280 | exit 1 |
---|
281 | ;; |
---|
282 | esac |
---|
283 | else |
---|
284 | ListPathComp[$i]="error" |
---|
285 | ListPathFile[$i]="error" |
---|
286 | ListPathRev[$i]="error" |
---|
287 | ListPathBranch[$i]="error" |
---|
288 | fi |
---|
289 | (( i = i + 1 )) |
---|
290 | echo |
---|
291 | cd ${MODIPSL} |
---|
292 | |
---|
293 | done |
---|
294 | printDebugArray ListPathComp |
---|
295 | printDebugArray ListPathFile |
---|
296 | printDebugArray ListPathRev |
---|
297 | printDebugArray ListPathBranch |
---|
298 | printDebugArray ListNewFiles |
---|
299 | |
---|
300 | echo ${ListPathComp[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
301 | echo ${ListPathFile[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
302 | echo ${ListPathRev[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
303 | echo ${ListPathBranch[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
304 | echo ${ListNewFiles[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
305 | echo ${ListModifFiles[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
306 | echo ${ListModifFilesDate[@]} >> ${MODIPSL_SAVE}/Last_log |
---|
307 | echo ${Maxfiledate} >> ${MODIPSL_SAVE}/Last_log |
---|
308 | |
---|
309 | |
---|
310 | echo "out directory in " ${MODIPSL_SAVE} |
---|