X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Ffiles%2Fzip_directories.sh;h=5a603b4dd6dcdc147975e2e518f3df3e93c7e037;hb=aab3d5746e13a49520cb5fb698e873f89d5666c2;hp=1b5e5d014a592dc4b6519fdafc6fda67a5c0fad4;hpb=f53716a32c2c1626ab565b1c42bacc67bc18e969;p=feisty_meow.git diff --git a/scripts/files/zip_directories.sh b/scripts/files/zip_directories.sh index 1b5e5d01..5a603b4d 100644 --- a/scripts/files/zip_directories.sh +++ b/scripts/files/zip_directories.sh @@ -5,7 +5,39 @@ source $FEISTY_MEOW_SCRIPTS/core/functions.sh -#hmmm: take a dir to go to for this. -dir=. +dirs=() + +# snag the command line arguments into an array of names. +for i in "$@"; do dirs+=("$i"); done + +# if there were no arguments, use the current directories list of directories. +if [ ${#dirs[@]} -eq 0 ]; then + # using a temp file is clumsy but after a lot of different methods being tried, this one + # worked and wasn't super ugly. + tempfile="$(mktemp /tmp/dirlist.XXXXXX)" + find $dir -mindepth 1 -maxdepth 1 -type d -exec echo "dirs+=(\"{}\");" ';' >$tempfile + source "$tempfile" +#echo dirs default to: ${dirs[@]} + \rm -f $tempfile +fi + +# takes a directory name as an argument and sucks the directory +# into a timestamped zip file. +function flattenizer() +{ + for dirname in "$@"; do + while [[ $dirname =~ .*/$ ]]; do + dirname="${dirname:0:((${#dirname}-1))}" + done + if [ ! -z "$dirname" -a -d "$dirname" ]; then + echo "flattening '$dirname'..." + zip -rm "${dirname}_$(date_stringer).zip" "$dirname" &>/dev/null + fi + done +} + +for ((i=0; i < ${#dirs[@]}; i++)); do + dir="${dirs[i]}" + flattenizer "$dir" +done -for i in $(find $dir -mindepth 1 -maxdepth 1 -type d) ; do zip -rm "${i}_$(date_stringer)" "$i"; done