forked from EDmodel/ED2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
diff_version.sh
executable file
·110 lines (96 loc) · 5.48 KB
/
diff_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
#------------------------------------------------------------------------------------------#
# This is how it works: you give two directories with EDBRAMS. It will go through #
# all files and check whether the files exists on both locations. #
# 1. If they do and are exactly the same, nothing happens; #
# 2. If they do and they are different, the editor will open three files, two of them are #
# the source code at the locations, and a third with the result of "diff -ib". Look #
# at the file, when you are done, close all the three files so it continues. #
# 3. If the file exists in only one location, a message will appear on screen. #
#------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------#
# Settings. #
#------------------------------------------------------------------------------------------#
#------ Extensions. -----------------------------------------------------------------------#
exts=".c .f90 .F90 .r .txt"
#------ Sub-directories to be compared. ---------------------------------------------------#
subdirs="ED BRAMS Ramspost R-utils"
#------ Editor to use (I've only tested with nedit, use others at your own risk). ---------#
editor="nedit"
#------ Two paths with EDBRAMS (full path). -----------------------------------------------#
here="/n/home00/mlongo/EDBRAMS"
there="/n/home00/mlongo/.backupscripts/.model_backup/EDBRAMS"
#------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------#
# Remove any comparison file that may exist. #
#------------------------------------------------------------------------------------------#
/bin/rm -f notthesame.txt
#------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------#
# Loop over the sub-directories. #
#------------------------------------------------------------------------------------------#
for subdir in ${subdirs}
do
#---------------------------------------------------------------------------------------#
# Loop over the extensions. #
#---------------------------------------------------------------------------------------#
for ext in ${exts}
do
if [ ${subdir} == "R-utils" ] && [ ${ext} == ".txt" ]
then
srchere="${here}/${subdir}/samap"
srcthere="${there}/${subdir}/samap"
elif [ ${subdir} == "R-utils" ]
then
srchere="${here}/${subdir}"
srcthere="${there}/${subdir}"
else
srchere="${here}/${subdir}/src"
srcthere="${there}/${subdir}/src"
fi
#-------------------------------------------------------------------------------------#
#-------------------------------------------------------------------------------------#
# Look for files that were changed or were removed in the remote test. #
#-------------------------------------------------------------------------------------#
lookuptable=$(find ${srchere} -name "*${ext}")
for filehere in ${lookuptable}
do
file=$(basename ${filehere})
newpath=$(dirname ${filehere} | sed s@${here}@${there}@g)
filethere="${newpath}/${file}"
if [ -s ${filethere} ]
then
ldif=$(diff -ib ${filethere} ${filehere} | wc -l)
if [ ${ldif} -gt 0 ]
then
woroot=$(echo ${filehere} | sed s@"${srchere}/"@""@g)
echo "${woroot} has changed..."
diff -ib ${filehere} ${filethere} > notthesame.txt
${editor} ${filehere} ${filethere} notthesame.txt 1> /dev/null 2> /dev/null
fi
else
woroot=$(echo ${filehere} | sed s@"${srchere}/"@""@g)
echo "${woroot} is exclusive to ${here} version..."
fi #if [ -s ${filethere} ]
done #for filehere in ${lookuptable}
#-------------------------------------------------------------------------------------#
#-------------------------------------------------------------------------------------#
# Look for files that were changed or were removed in the remote test. #
#-------------------------------------------------------------------------------------#
lookuptable=$(find ${srcthere} -name "*${ext}")
for filethere in ${lookuptable}
do
file=$(basename ${filethere})
newpath=$(dirname ${filethere} | sed s@${there}@${here}@g)
filehere="${newpath}/${file}"
if [ ! -s ${filehere} ]
then
woroot=$(echo ${filethere} | sed s@"${srcthere}/"@""@g)
echo "${woroot} is exclusive to ${there} version..."
fi #if [ -s ${filethere} ]
done #for filehere in ${lookuptable}
#-------------------------------------------------------------------------------------#
done #for ext in ${exts}
#---------------------------------------------------------------------------------------#
done #for subdir in ${subdirs}
#------------------------------------------------------------------------------------------#