fix push pics script

This commit is contained in:
2026-07-08 11:05:38 -07:00
parent 48ab1db956
commit ff6fcfc721
2 changed files with 28 additions and 18 deletions

View File

@@ -1,35 +1,37 @@
#!/bin/bash
#
# sync-newer-images — For each top-level image in SRC, find any matching
# filename recursively under DEST and copy over it if SRC is newer.
# sync-newer-images — For each top-level image in SRC, copy it to DEST
# if it doesn't already exist anywhere under DEST.
# Works on Linux and macOS (bash 3.2+ compatible).
usage() {
cat <<'EOF'
Usage: sync-newer-images [options] <destination> <source>
For each top-level image in source, find any matching filename recursively
under destination and copy over it if the source file is newer.
Arguments:
destination Path to copy TO
source Path to copy FROM
For each top-level image in source, copy it into destination if no
file with the same name exists anywhere under destination.
Options:
-u, --update If a matching file already exists under destination,
copy over it only if the content differs (uses cmp).
-h, --help Show this help message and exit
EOF
exit 0
}
for arg in "$@"; do
case "$arg" in
update_mode=0
while [ $# -gt 0 ]; do
case "$1" in
-h|--help) usage ;;
-u|--update) update_mode=1; shift ;;
*) break ;;
esac
done
if [ $# -lt 2 ]; then
echo "Error: destination and source are required" >&2
echo "Usage: sync-newer-images <destination> <source>" >&2
echo "Usage: sync-newer-images [options] <destination> <source>" >&2
exit 1
fi
@@ -46,6 +48,9 @@ if [ ! -d "$SRC" ]; then
exit 1
fi
# Build deduplicated, newline-separated list of all basenames under DEST.
basenames=$(find "$DEST" -type f 2>/dev/null | sed 's|.*/||' | sort -u)
copied=0
for srcfile in "$SRC"/*; do
@@ -58,12 +63,17 @@ for srcfile in "$SRC"/*; do
esac
filename="${srcfile##*/}"
while IFS= read -r destfile; do
if [ -f "$destfile" ] && [ "$srcfile" -nt "$destfile" ]; then
if ! printf '%s\n' "$basenames" | grep -qxF "$filename"; then
cp -v "$srcfile" "$DEST/"
copied=$((copied + 1))
elif [ "$update_mode" -eq 1 ]; then
destfile=$(find "$DEST" -type f -name "$filename" 2>/dev/null | head -1)
if [ -n "$destfile" ] && ! cmp -s "$srcfile" "$destfile"; then
cp -v "$srcfile" "$destfile"
copied=$((copied + 1))
fi
done < <(find "$DEST" -type f -name "$filename" 2>/dev/null)
fi
done
echo "Copied ${copied} newer image(s) from ${SRC} into ${DEST}"
echo "Copied ${copied} image(s) from ${SRC} into ${DEST}"