clean_samba_trash.sh: ommit action if given directory is empty.

This commit is contained in:
Christoph 2018-10-18 04:21:27 +02:00
parent 6520c62b9c
commit be8d9d0b3a

View File

@ -14,6 +14,7 @@ clean_up() {
# Perform program exit housekeeping # Perform program exit housekeeping
rm -rf "$LOCK_DIR" rm -rf "$LOCK_DIR"
blank_line
exit $1 exit $1
} }
@ -74,17 +75,22 @@ info (){
echo_done() { echo_done() {
if $terminal ; then if $terminal ; then
echo -e "\033[75G[ \033[32mdone\033[m ]" echo -e "\033[85G[ \033[32mdone\033[m ]"
fi fi
} }
echo_failed(){ echo_failed(){
if $terminal && $LOGGING ; then if $terminal && $LOGGING ; then
echo -e "\033[75G[ \033[1;31mfailed\033[m ]" echo -e "\033[85G[ \033[1;31mfailed\033[m ]"
fi fi
} }
echo_skipped() { echo_skipped() {
if $terminal && $LOGGING ; then if $terminal && $LOGGING ; then
echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" echo -e "\033[85G[ \033[90mskipped\033[m ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[85G[ \033[5m\033[1m...\033[m ]"
fi fi
} }
@ -94,6 +100,11 @@ trim() {
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var" echo -n "$var"
} }
blank_line() {
if $terminal ; then
echo ""
fi
}
# ------------- # -------------
@ -160,19 +171,37 @@ traverse() {
} }
blank_line
for dir in $trash_dirs ; do for dir in $trash_dirs ; do
info "Delete files from trash directory \033[1m${dir}\033[m older than \033[1m${days}\033[m days .." #info "Delete files from trash directory \033[1m${dir}\033[m older than \033[1m${days}\033[m days .."
traverse "$dir" echononl " Delete files from trash directory \033[1m${dir}\033[m older than \033[1m${days}\033[m days .."
if [[ -d "$dir" ]]; then
echo_wait
traverse "$dir"
echo_done
else
echo_skipped
fi
done done
# - Delete empty sub-directories # - Delete empty sub-directories
# - # -
if $terminal ; then if $terminal ; then
echo ""
echo -e "\033[32m\033[1m-----\033[m" echo -e "\033[32m\033[1m-----\033[m"
echo ""
fi fi
for dir in $trash_dirs ; do for dir in $trash_dirs ; do
info "Cleanup trash directory \033[1m${dir}\033[m from empty directories .." #info "Cleanup trash directory \033[1m${dir}\033[m from empty directories .."
find $dir -depth -mindepth 1 -type d -empty -delete echononl " Cleanup trash directory \033[1m${dir}\033[m from empty directories .."
if [[ -d "$dir" ]]; then
echo_wait
find $dir -depth -mindepth 1 -type d -empty -delete
echo_done
else
echo_skipped
fi
done done
clean_up 0 clean_up 0