I've been given a script to install on my Unraid fileserver. The purpose of the script is to copy the contents of a USB device onto the array. It all works as it should, but I'm trying to modify it slightly to work better.
This variable is defined early on, the effect is that the script will copy everything inside a directory named DCIM on the source device.
It will also copy the contents of sub-folders, but it does not copy the sub-folders themselves.
So the result is all the files on the destination in a single folder.
The * is my attempt at getting a wildcard working.
Also, it's sitting inside a loop which isn't required, but I'll solve that later.
I've only pasted in what I think are the relevant sections, if you want to see the entire script, just click here :
https://gist.github.com/ljm42/02b54ce9cc36f992515b
VALIDDIRS=("/DCIM/*/")
# loop through all the subdirs in /DCIM looking for dirs defined in VALIDDIRS
for DIR in ${MOUNTPOINT}/DCIM/*; do
if [ -d "${DIR}" ]; then
log_debug "checking ${DIR}"
for element in "${VALIDDIRS[@]}"; do
if [[ ${DIR} =~ ${element} ]]; then
# process this dir
log_local "${MOVEMSG} ${DIR}/ to ${DESTINATION}"
rsync -a ${RSYNCFLAG} "${DIR}/" "${DESTINATION}"
# remove empty directory from memory card
if [ ${MOVE_OR_COPY} == "move" ]; then
rmdir ${DIR}
fi
fi
done
fi
done