]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
filesystem-cleanup: Add parameter to show changes
authorDaniel Weismüller <whytea@ipfire.org>
Fri, 10 Jan 2020 15:06:00 +0000 (16:06 +0100)
committerArne Fitzenreiter <arne_f@ipfire.org>
Mon, 13 Jan 2020 21:36:06 +0000 (21:36 +0000)
Use --dry-run to only show files that would be deleted, but do
not actually delete them.

Signed-off-by: Daniel Weismüller <daniel.weismueller@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
src/scripts/filesystem-cleanup

index d4cdfe8d3e464d6f71fad31f8e399475d9b3ea0f..7e7accc7a2fb27f920fb3f0012aca3229774cdfd 100644 (file)
@@ -27,6 +27,22 @@ PATHS=(
 )
 
 main() {
 )
 
 main() {
+       local dry_run="false"
+
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --dry-run)
+                               dry_run="true"
+                               ;;
+
+                       *)
+                               echo "${0}: Invalid argument: ${1}" >&2
+                               return 2
+                               ;;
+               esac
+               shift
+       done
+
        # Update the runtime linker cache (this may fix any broken symlinks)
        ldconfig
 
        # Update the runtime linker cache (this may fix any broken symlinks)
        ldconfig
 
@@ -65,7 +81,12 @@ main() {
                                                ;;
 
                                        *)
                                                ;;
 
                                        *)
-                                               unlink "${file}"
+                                               echo "Removing ${file}..."
+
+                                               # Actually remove the file (maybe)
+                                               if [ "${dry_run}" = "false" ]; then
+                                                       unlink "${file}"
+                                               fi
                                                ;;
                                esac
                        done
                                                ;;
                                esac
                        done