Make scripts generic and fix several bugs

- Add optional directory argument to images_resize_recursive.sh,
  zip_images_resize_recursive.sh, and new rar2zip_recursive.sh
- Remove hardcoded-path wrappers rar2zip_images.sh and rar2zip_incomplete.sh
- Fix zip_images_resize.sh: move SCRIPT_DIR to top, change exit 1 to
  continue on bad output file so remaining files still process
- Use MAX_PIXELS variable in images_resize.sh resize argument
- Fix zip_images_recursive.sh: replace case-sensitive 7z globs with
  find -iregex piped via xargs
This commit is contained in:
2026-05-01 21:58:31 -04:00
parent 651cccc21c
commit fff8e346ad
8 changed files with 53 additions and 16 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ do
# Get file size before resizing
SIZE_BEFORE=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
~/Applications/magick "$f" -resize 8000000@@\> -sampling-factor 4:2:0 -strip -quality 85% "$f"
~/Applications/magick "$f" -resize "${MAX_PIXELS}@@\>" -sampling-factor 4:2:0 -strip -quality 85% "$f"
# Get file size after resizing
SIZE_AFTER=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
+9 -1
View File
@@ -1,8 +1,16 @@
#!/bin/bash
SEARCH_DIR="${1:-.}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
find . -mindepth 1 -type d -print0 | while IFS= read -r -d '' f
if [ ! -d "$SEARCH_DIR" ]; then
echo "Error: '$SEARCH_DIR' is not a directory"
exit 1
fi
echo "Resizing images recursively in $SEARCH_DIR"
find "$SEARCH_DIR" -mindepth 1 -type d -print0 | while IFS= read -r -d '' f
do
if pushd "$f" > /dev/null; then
"$SCRIPT_DIR/images_resize.sh"
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
find /media/rewt/media/images/ -name '*.rar' -exec "$SCRIPT_DIR/rar2zip.sh" '{}' \;
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
find /media/rewt/media/incomplete/ -name '*.rar' -exec "$SCRIPT_DIR/rar2zip.sh" '{}' \;
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
#
# Recursively find all RAR files in a directory and convert them to ZIP.
#
# Usage: rar2zip_recursive.sh [directory]
# directory Directory to search (default: current directory)
SEARCH_DIR="${1:-.}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ ! -d "$SEARCH_DIR" ]; then
echo "Error: '$SEARCH_DIR' is not a directory"
exit 1
fi
echo "Converting RARs to ZIPs in $SEARCH_DIR"
find "$SEARCH_DIR" -name '*.rar' -print0 | while IFS= read -r -d '' f
do
"$SCRIPT_DIR/rar2zip.sh" "$f"
done
+3 -3
View File
@@ -20,11 +20,11 @@ if [ "$#" -ne 0 ]; then
directoryTree="${1} - ${directoryTree}"
fi
jpgs=$(find . -maxdepth 1 -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$")
mapfile -d '' jpgs < <(find . -maxdepth 1 -regextype posix-egrep -iregex ".*\.(jpg|jpeg)$" -print0)
if [ -n "$jpgs" ]; then
if [ ${#jpgs[@]} -gt 0 ]; then
echo "Zipping JPGs in ${directoryTree}"
7z a -tzip -mx=0 "$directoryTree.zip" "*.jpg" -i!*.jpeg -i!*.JPG -i!*.JPEG
printf '%s\0' "${jpgs[@]}" | xargs -0 7z a -tzip -mx=0 "$directoryTree.zip"
fi
+3 -2
View File
@@ -10,6 +10,8 @@ if [ $# -eq 0 ]; then
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Resizing large JPGs in ZIPs"
# Use RAM disk for temporary files.
@@ -64,7 +66,6 @@ for INFILE in "$@"; do
cleanup_temp
continue
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
"$SCRIPT_DIR/images_resize.sh"
popd > /dev/null
@@ -88,7 +89,7 @@ for INFILE in "$@"; do
if [ ! -s "$OUTFILE" ]; then
echo "Error: Output file is empty or does not exist. Keeping original file."
cleanup_temp
exit 1
continue
fi
rm "$INFILE"
+15 -2
View File
@@ -1,4 +1,17 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
find . -iname '*.zip' -exec "$SCRIPT_DIR/zip_images_resize.sh" '{}' \;
SEARCH_DIR="${1:-.}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ ! -d "$SEARCH_DIR" ]; then
echo "Error: '$SEARCH_DIR' is not a directory"
exit 1
fi
echo "Resizing images in ZIPs recursively in $SEARCH_DIR"
find "$SEARCH_DIR" -iname '*.zip' -print0 | while IFS= read -r -d '' f
do
"$SCRIPT_DIR/zip_images_resize.sh" "$f"
done