This repository has been archived by the owner on Aug 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sacadiff.sh
executable file
·111 lines (94 loc) · 2.1 KB
/
sacadiff.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
111
#!/bin/bash
# Copyright (C) 2011-2012 The SuperTeam Developer Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SCRIPTDIR=`dirname $0`
. $SCRIPTDIR/mensajes.sh
ORIG=$1
DEST=$2
DIFFFILE=$3
BASEDIR=`dirname $DIFFFILE`
A=$BASEDIR/a.txt
B=$BASEDIR/b.txt
AB=$BASEDIR/ab.txt
if [ $# -lt 3 ]
then
msgErr >&2 "Usage: $0 <dir1> <dir2> <file>"
exit 1
fi
if [ ! -d $ORIG ]
then
msgErr >&2 "El directorio $1 no existe"
exit 1
fi
if [ ! -d $DEST ]
then
msgErr >&2 "El directorio $DEST no existe"
exit 1
fi
if [ -f $DIFFFILE ]; then
rm $DIFFFILE
fi
msgStatus "Calculando las diferencias entre los directorios $ORIG y $DEST"
exec diff -qr $ORIG $DEST | sort -o $DIFFFILE
[ -f $A ] && rm $A
[ -f $B ] && rm $B
[ -f $AB ] && rm $AB
mLANG=`echo $LANG | cut -f 2 -d "=" | cut -f 1 -d "."`
if [ $mLANG = "es_ES" ]; then
mFILES="Archivos "
else
mFILES="Files "
fi
while read line; do
if [[ "$line" =~ "$mFILES" ]]
then
accion=copiar
prefile=${line#*$ORIG*}
else
if [[ "$line" =~ "$DEST" ]]
then
accion=borrar
prefile=${line#*$DEST*}
prefile=${prefile/: //}
else
accion=nuevo
prefile=${line#*$ORIG*}
prefile=${prefile/: //}
fi
fi
file=`echo $prefile | cut -d " " -f 1`
if [[ $accion == "copiar" ]]
then
echo $ORIG$file >> $AB
msgWarn $ORIG$file
fi
if [[ $accion == "nuevo" ]]
then
echo $ORIG$file >> $A
msgOK $ORIG$file
fi
if [[ $accion == "borrar" ]]
then
echo $ORIG$file >> $B
msgErr $ORIG$file
fi
done < $DIFFFILE
if [ "$?" -eq 0 ];
then
msgOK "Diferencias obtenidas en el fichero $3"
exit 0
else
msgErr "No se ha podido obtener las diferencias correctamente"
exit 1
fi