|
@@ -0,0 +1,61 @@
|
|
|
+#! /bin/bash
|
|
|
+
|
|
|
+GDRIVE=/opt/midjourney/gdrive
|
|
|
+LOGFILE=/scratch/midjourney-sort-and-upload.log
|
|
|
+MIDJOURNEYDIR=/midjourney/
|
|
|
+
|
|
|
+echo ""
|
|
|
+echo "Starting midjourney sync and upload - $(date)" 2>&1 | tee -a ${LOGFILE}
|
|
|
+
|
|
|
+if [[ ! -v ${SMALL} ]]; then
|
|
|
+ echo "ERROR: No gdrive key for SMALL" 2>&1 | tee -a ${LOGFILE}
|
|
|
+ exit -1
|
|
|
+fi
|
|
|
+
|
|
|
+if [[ ! -v ${MEDIUM} ]]; then
|
|
|
+ echo "ERROR: No gdrive key for MEDIUM" 2>&1 | tee -a ${LOGFILE}
|
|
|
+ exit -1
|
|
|
+fi
|
|
|
+
|
|
|
+if [[ ! -v ${LARGE} ]]; then
|
|
|
+ echo "ERROR: No gdrive key for LARGE" 2>&1 | tee -a ${LOGFILE}
|
|
|
+ exit -1
|
|
|
+fi
|
|
|
+
|
|
|
+SAVEIFS=$IFS
|
|
|
+IFS=$(echo -en "\n\b")
|
|
|
+
|
|
|
+if compgen -G "/shared/midjourney/images/*.png" > /dev/null; then
|
|
|
+ echo New files. Sorting. 2>&1 | tee -a ${LOGFILE}
|
|
|
+ for i in ${MIDJOURNEYDIR}/images/*.png; do
|
|
|
+ maxdim=$(file "$i" | awk '{ print ($6 > $8)? $6 : $8 }' | sed 's/,$//')
|
|
|
+ if [ $maxdim -lt 1024 ]; then
|
|
|
+ echo SMALL: "$i" 2>&1 | tee -a ${LOGFILE}
|
|
|
+ rsync $i ${MIDJOURNEYDIR}/images.small/ 2>&1 | tee -a ${LOGFILE}
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ mv $i ${MIDJOURNEYDIR}/images.filtered/ 2>&1 | tee -a ${LOGFILE}
|
|
|
+ fi
|
|
|
+ elif [ $maxdim -lt 1281 ]; then
|
|
|
+ echo MEDIUM: "$i" 2>&1 | tee -a ${LOGFILE}
|
|
|
+ rsync $i ${MIDJOURNEYDIR}/images.medium/ 2>&1 | tee -a ${LOGFILE}
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ mv $i ${MIDJOURNEYDIR}/images.filtered/ 2>&1 | tee -a ${LOGFILE}
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ echo LARGE: "$i" 2>&1 | tee -a ${LOGFILE}
|
|
|
+ rsync $i ${MIDJOURNEYDIR}/images.large/ 2>&1 | tee -a ${LOGFILE}
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ mv $i ${MIDJOURNEYDIR}/images.filtered/ 2>&1 | tee -a ${LOGFILE}
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+ done
|
|
|
+else
|
|
|
+ echo No new files. No need to sort. 2>&1 | tee -a ${LOGFILE}
|
|
|
+fi
|
|
|
+
|
|
|
+echo Syncing Small 2>&1 | tee -a ${LOGFILE}
|
|
|
+$GDRIVE sync upload --keep-largest /shared/midjourney/images.small/ $SMALL 2>&1 | tee -a ${LOGFILE}
|
|
|
+echo Syncing Medium 2>&1 | tee -a ${LOGFILE}
|
|
|
+$GDRIVE sync upload --keep-largest /shared/midjourney/images.medium/ $MEDIUM 2>&1 | tee -a ${LOGFILE}
|
|
|
+echo Syncing Large 2>&1 | tee -a ${LOGFILE}
|
|
|
+$GDRIVE sync upload --keep-largest /shared/midjourney/images.large/ $LARGE 2>&1 | tee -a ${LOGFILE}
|