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:
+1
-1
@@ -21,7 +21,7 @@ do
|
|||||||
# Get file size before resizing
|
# Get file size before resizing
|
||||||
SIZE_BEFORE=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
|
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
|
# Get file size after resizing
|
||||||
SIZE_AFTER=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
|
SIZE_AFTER=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
SEARCH_DIR="${1:-.}"
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
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
|
do
|
||||||
if pushd "$f" > /dev/null; then
|
if pushd "$f" > /dev/null; then
|
||||||
"$SCRIPT_DIR/images_resize.sh"
|
"$SCRIPT_DIR/images_resize.sh"
|
||||||
|
|||||||
@@ -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" '{}' \;
|
|
||||||
@@ -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" '{}' \;
|
|
||||||
Executable
+21
@@ -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
|
||||||
@@ -20,11 +20,11 @@ if [ "$#" -ne 0 ]; then
|
|||||||
directoryTree="${1} - ${directoryTree}"
|
directoryTree="${1} - ${directoryTree}"
|
||||||
fi
|
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}"
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ if [ $# -eq 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
echo "Resizing large JPGs in ZIPs"
|
echo "Resizing large JPGs in ZIPs"
|
||||||
|
|
||||||
# Use RAM disk for temporary files.
|
# Use RAM disk for temporary files.
|
||||||
@@ -64,7 +66,6 @@ for INFILE in "$@"; do
|
|||||||
cleanup_temp
|
cleanup_temp
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
"$SCRIPT_DIR/images_resize.sh"
|
"$SCRIPT_DIR/images_resize.sh"
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ for INFILE in "$@"; do
|
|||||||
if [ ! -s "$OUTFILE" ]; then
|
if [ ! -s "$OUTFILE" ]; then
|
||||||
echo "Error: Output file is empty or does not exist. Keeping original file."
|
echo "Error: Output file is empty or does not exist. Keeping original file."
|
||||||
cleanup_temp
|
cleanup_temp
|
||||||
exit 1
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm "$INFILE"
|
rm "$INFILE"
|
||||||
|
|||||||
@@ -1,4 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user