first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / files / recursive_whack_dupes.sh
1 #!/bin/bash
2
3 ###############################################################################
4 #                                                                             #
5 #  Name   : recursive_whack_dupes                                             #
6 #  Author : Chris Koeritz                                                     #
7 #  Rights : Copyright (C) 2007-$now by Author                                 #
8 #                                                                             #
9 #  Purpose:                                                                   #
10 #                                                                             #
11 #    Recursively whacks duplicate files when given the exemplary "good"       #
12 #  directory as the first parameter and a potentially shadow directory of     #
13 #  lesser importance.  The second directory will be cleaned out where it has  #
14 #  filenames that are the same as in the exemplar directory.                  #
15 #                                                                             #
16 ###############################################################################
17 #  This script is free software; you can redistribute it and/or modify it     #
18 #  under the terms of the GNU General Public License as published by the Free #
19 #  Software Foundation; either version 2 of the License or (at your option)   #
20 #  any later version.  See "http://www.fsf.org/copyleft/gpl.html" for a copy  #
21 #  of the License online.  Please send any updates to "fred@gruntose.com".    #
22 ###############################################################################
23
24 exemplar_dir=$1
25 whack_dir=$2
26
27 if [ -z "$1" -o -z "$2" ]; then
28   echo This program requires two parameters.  The first is a directory that is
29   echo considered to have a set of good files in it.  The second is a directory
30   echo that has possible duplicates of the files in the good directory.  Any
31   echo files found in the second directory will be removed if they are already
32   echo in the first directory.  This will be done recursively so that any
33   echo directory names in the exemplar that are shadowed by the whacking directory
34   echo will have their duplicate files cleaned out too.  The result will be that
35   echo the whacking directory (second parameter) will have just the folders and
36   echo non-duplicate filenames remaining and the exemplar directory (first parameter)
37   echo will be untouched.
38   exit 1
39 fi
40
41 # change to the whacking arena.
42 pushd $whack_dir &>/dev/null
43
44 for i in $(find . -depth -mindepth 1 -type d \
45     -exec echo {} ';' | sed -e 's/^.\///'); do
46   bash $SHELLDIR/whack_dupes_dir.sh $exemplar_dir/$i $i
47 done
48
49 # get back to where we started.
50 popd &>/dev/null
51