diff --git a/files/archive-subfolders b/files/archive-subfolders index 352020e..52c1977 100755 --- a/files/archive-subfolders +++ b/files/archive-subfolders @@ -6,8 +6,9 @@ function helpexit() { BS=$( basename "$0" ) echo "Archive the subfolders of the current directory, version: $VERSION" echo "Usage: $BS [-z/-n] [folder name(s)]" - echo " -z Compress. If not given, will ask action after archiving" - echo " -n No compression. Exit after TARchive" + echo " -z Compress. If not given, will ask action after archiving" + echo " -n No compression. Exit after TARchive" + echo " --rm Remove source folders after archival" echo " folder name: If given, archive only the named folder(s)." echo " If not, for loop over all folders in the current directory." @@ -33,11 +34,13 @@ function exitokay() { DEPTH=1 FOLDERS=( ) +REMOVE=0 for ((i=1; i<=${#@}; i++)) { [[ "${!i}" = "-h" ]] && helpexit [[ "${!i}" = "--help" ]] && helpexit [[ "${!i}" = "-n" ]] && { NOCOMPRESSION=1; continue; } [[ "${!i}" = "-z" ]] && { COMPRESSION=1; continue; } + [[ "${!i}" = "--rm" ]] && { REMOVE=1; continue; } [[ "${!i}" = "-"* ]] && helpexit FOLDERS+=( "${!i%/}" ) DEPTH=0 @@ -77,6 +80,14 @@ listfolders "${FOLDERS[@]}" | while read -r -d "" d; do fsize "$d.tar" "$DU" kill -0 "$DUPID" &>/dev/null || kill "$DUPID" &>/dev/null echo '' + if wait $PID; then + # tar exists okay + [[ "$REMOVE" -eq 1 ]] && { + echo Removing folder $d + which rm-progress &> /dev/null && rm-progress -f "$d" + [[ -d "$d" ]] && rm -r "$d" + } + fi done trap - 9 15 [[ "$NOCOMPRESSION" -eq 1 ]] && { diff --git a/files/rm-progress b/files/rm-progress index 897bae0..096eef7 100755 --- a/files/rm-progress +++ b/files/rm-progress @@ -51,7 +51,7 @@ function deletefolders() { percent=$((200*$i/$folders % 2 + 100*$i/$folders)) printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \ $(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders $percent "$line" - rm -rf "$line" + rm -r "$line" done < <(find "$@" -depth -type d -print0) printf "\n" }