From de69513cea7b1ce2e300083b775cf8ab372d3b9b Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Tue, 23 Apr 2013 18:01:06 -0400 Subject: [PATCH] much nicer version for recustomize, now actually preserves earlier behavior that would only list files copied when they were different, which had been damaged by new cleanup of unexpected files. now only the unexpected files are removed, so the noise produced is as light as it was before. --- scripts/core/functions.sh | 11 +++++- scripts/files/list_non_dupes.sh | 23 +++++++++++ scripts/files/whack_dupes.sh | 24 ++++++------ scripts/files/whack_non_dupes.sh | 66 ++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 15 deletions(-) create mode 100644 scripts/files/list_non_dupes.sh create mode 100644 scripts/files/whack_non_dupes.sh diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index 60f57629..924266dc 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -291,9 +291,16 @@ if [ -z "$skip_all" ]; then return 1 fi regenerate >/dev/null + pushd "$FEISTY_MEOW_GENERATED/custom" &>/dev/null + local incongruous_files="$(bash "$FEISTY_MEOW_SCRIPTS/files/list_non_dupes.sh" "$FEISTY_MEOW_DIR/customizing/$user" "$FEISTY_MEOW_GENERATED/custom")" + if [ ${#incongruous_files} -ge 1 ]; then + echo "cleaning unknown older overrides..." + perl "$FEISTY_MEOW_SCRIPTS/files/safedel.pl" $incongruous_files + echo + fi + popd &>/dev/null echo "copying custom overrides for $user" - perl "$FEISTY_MEOW_SCRIPTS/files/safedel.pl" "$FEISTY_MEOW_GENERATED/custom" - mkdir "$FEISTY_MEOW_GENERATED/custom" + mkdir "$FEISTY_MEOW_GENERATED/custom" 2>/dev/null perl "$FEISTY_MEOW_SCRIPTS/text/cpdiff.pl" "$FEISTY_MEOW_DIR/customizing/$user" "$FEISTY_MEOW_GENERATED/custom" regenerate } diff --git a/scripts/files/list_non_dupes.sh b/scripts/files/list_non_dupes.sh new file mode 100644 index 00000000..0a3c078f --- /dev/null +++ b/scripts/files/list_non_dupes.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +#header here! + +# lists the files in this (the current) directory that have different names +# than the files in the directory passed as the first (and only) parameter. + +list_dir=$1 +if [ -z "$list_dir" ]; then + echo "list_non_dupes" + echo "" + echo "This program requires a single parameter, which is a directory name." + echo "The files in the current directory will be listed to standard output" + echo "if a file in the user-specified directory exists with the same name." + exit 1; +fi + +for i in *; do + if [ ! -f "$list_dir/$i" ]; then + echo "$i" + fi +done + diff --git a/scripts/files/whack_dupes.sh b/scripts/files/whack_dupes.sh index 5b05965b..ac20b3d9 100644 --- a/scripts/files/whack_dupes.sh +++ b/scripts/files/whack_dupes.sh @@ -2,31 +2,29 @@ # whacks the files in the current directory which are duplicates of the # files in the directory passed as a parameter. -# if there is a second parameter, then it is used as the "current directory". +# if there is a second parameter, then it is used as the "current directory" +# and it will be the target of any deletions. exemplar_dir="$1"; shift whack_dir="$1"; shift # make sure they gave us a good directory to start with. if [ -z "$exemplar_dir" ]; then - echo "whack_dupes" - echo "-----------" - echo "" - echo "This program needs at least one directory parameter. The files in the" - echo "current directory will be removed if a file in the specified directory" - echo "already exists. So... the current directory is the less important one" - echo "and is presumed to have duplicates AND the directory given as parameter" - echo "is considered important and has the best versions of the files." + echo "$(basename $0 .sh): This program needs at least one directory parameter." + echo "The files in the current directory will be removed if a file in the specified directory" + echo "already exists. So... the current directory is the less important one and is presumed" + echo "to have duplicates AND the directory given as parameter is considered important and has" + echo "the best versions of the files." echo "If there is an optional second parameter, then that is used as the" echo "\"current\" directory where we start from; it will be the less important" echo "directory and will have its entries cleaned if they're duplicates." - exit 42; + exit 1 fi # check to make sure they gave us a good directory. if [ ! -z "$whack_dir" -a ! -d "$whack_dir" ]; then echo "the directory $whack_dir does not exist." - exit 3 + exit 1 fi # test the tasty remote location with the better contents. @@ -34,7 +32,7 @@ pushd "$exemplar_dir" &>/dev/null if [ $? -ne 0 ]; then # an error getting to this directory means its no good for us. echo "the directory $exemplar_dir is inaccessible." - exit 2 + exit 1 fi the_good_place="$(pwd)" popd &>/dev/null @@ -51,7 +49,7 @@ current_dir="$(pwd)" if [ "$current_dir" == "$the_good_place" ]; then # this is not good; they're the same location. echo "the request would whack all the files in the current directory; ignoring." - exit 4 + exit 1 fi # do the real work now... diff --git a/scripts/files/whack_non_dupes.sh b/scripts/files/whack_non_dupes.sh new file mode 100644 index 00000000..c5a81a09 --- /dev/null +++ b/scripts/files/whack_non_dupes.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# whacks the files in the current directory which are NOT duplicates of the +# files in the directory passed as a parameter. +# if there is a second parameter, then it is used as the "current directory" +# and it will be the target of any deletions. + +exemplar_dir="$1"; shift +whack_dir="$1"; shift + +# make sure they gave us a good directory to start with. +if [ -z "$exemplar_dir" ]; then + echo "$(basename $0 .sh): This program needs at least one directory parameter." + echo "The files in the current directory will be removed if a file in the specified directory" + echo "does not exist. So... the current directory is the less important one and is presumed" + echo "to have rogue files AND the directory given as parameter is considered important and has" + echo "the best canonical versions of the files." + echo "If there is an optional second parameter, then that is used as the" + echo "\"current\" directory where we start from; it will be the less important" + echo "directory and will have its entries cleaned if they're non-duplicates." + exit 1 +fi + +# check to make sure they gave us a good directory. +if [ ! -z "$whack_dir" -a ! -d "$whack_dir" ]; then + echo "the directory $whack_dir does not exist." + exit 1 +fi + +# test the tasty remote location with the better contents. +pushd "$exemplar_dir" &>/dev/null +if [ $? -ne 0 ]; then + # an error getting to this directory means its no good for us. + echo "the directory $exemplar_dir is inaccessible." + exit 1 +fi +the_good_place="$(pwd)" +popd &>/dev/null + +if [ ! -z "$whack_dir" ]; then + # use the directory as our "current" location. + pushd "$whack_dir" &>/dev/null +fi + +current_dir="$(pwd)" + +#echo "currdir=$current_dir gooddir=$the_good_place" + +if [ "$current_dir" == "$the_good_place" ]; then + # this is not good; they're the same location. + echo "the request would whack all the files in the current directory; ignoring." + exit 1 +fi + +# do the real work now... +for i in *; do + if [ ! -f "$exemplar_dir/$i" ]; then + echo "whacking $i" + rm -f "$i" + fi +done + +if [ ! -z "$whack_dir" ]; then + popd &>/dev/null +fi + -- 2.34.1