10 #mkdirhier="echo mkdirhier"
12 export mydir olddir yourdir
cp mkdirhier
14 rm -f conflicts.log added.log
16 # First try to merge all the changes from olddir to yourdir into mydir
17 # that means that only the files which are both in mydir, yourdir and olddir have to be processed
19 find $mydir -type f
-exec sh
-c \
20 'cur="`echo "{}" | cut -d/ -f2-`"; \
21 if [ -e $olddir/"$cur" ] && [ -e $yourdir/"$cur" ]; then \
22 echo processing "$cur"; \
23 merge -p $mydir/"$cur" $olddir/"$cur" $yourdir/"$cur" >merge.tmp; \
24 if [ $? -gt 0 ]; then \
25 echo "$cur" >> conflicts.log; \
27 if ! cmp $mydir/"$cur" merge.tmp >/dev/null; then \
28 $cp merge.tmp $mydir/"$cur"; \
29 echo "$cur" has been updated; \
34 # Then copy all the files which are new into mydir. A file is "new" when it and all of its ancestors are
35 # not present in olddir nor in mydir. If a file is present in olddir but not in mydir it means that it's
36 # been removed and therefore doesn't have to be copied; if it's present both in mydir and olddir it means
37 # that if it needed to be modified it's already been modified by the previous part, therefore doesn't need to
38 # be copied either. All that means that if a file is present both in yourdir and olddir it doesn't need to be
41 find $yourdir -type f
-exec sh
-c \
42 'cur="`echo "{}" | cut -d/ -f2-`"; \
43 if ! [ -e $olddir/"$cur" ] && ! [ -e $mydir/"$cur" ] && \
48 cur2=`echo "$cur" | cut -d/ -f-$count`; \
49 if [ "$oldcur2" == "$cur2" ]; then \
52 if [ -e $olddir/"$cur2" ] && ! [ -e $mydir/"$cur2" ]; then \
56 count=$[$count + 1]; \
60 dirname=`dirname "$cur"`; \
61 $mkdirhier $mydir/"$dirname"; \
62 $cp $yourdir/"$cur" $mydir/"$dirname"; \
63 echo "$cur" >> added.log; \
67 echo Operation finished.
69 if [ -e conflicts.log
]; then \
70 echo There were
`wc -l conflicts.log` conflicts. Have a
look at conflicts.log to see
in which files.
; \
72 echo There were no conflicts
; \
75 if [ -e added.log
]; then \
76 echo `wc -l added.log` files have been added. Have a
look at added.log to see
which ones.
; \
78 echo No new files have been added
; \