Update using-fswatch.md to use CHIBISAFE_WATCH_DIR#6
Open
John-Paul-R wants to merge 1 commit intochibisafe:mainfrom
Open
Update using-fswatch.md to use CHIBISAFE_WATCH_DIR#6John-Paul-R wants to merge 1 commit intochibisafe:mainfrom
John-Paul-R wants to merge 1 commit intochibisafe:mainfrom
Conversation
Author
|
I actually also have this set of modifications to the script to make it work on my linux machine, if wanted I can add to the changeset: #!/usr/bin/env sh
setup_environment() {
script_dir="$(dirname "$0")"
script_dir="$(realpath "${script_dir}")"
env_file="${script_dir}/chibisafe_watcher.env"
if [ -f "${env_file}" ]; then
source "${env_file}"
else
echo "No environment file found."
exit 1
fi
}
upload() {
filename=$1
dump_file="$(mktemp --suffix=-chibisafe.dump)"
echo "${filename}" >"${dump_file}"
stat --format="%m" "${filename}" >>"${dump_file}"
curl -D "${dump_file}" \
-H "x-api-key: ${CHIBISAFE_API_KEY}" \
-H "albumuuid: ${CHIBISAFE_ALBUM_UUID}" \
-F "file[]=@${filename}" \
-s "${CHIBISAFE_REQUEST_URL}"
rm "$dump_file"
printf '\n'
}
start_watch() {
echo "Watching directory: ${CHIBISAFE_WATCH_DIR}"
fswatch -0 -x "${CHIBISAFE_WATCH_DIR}" | while read -d "" event_line; do
path=$(echo "${event_line}" | cut -d' ' -f1)
event_types=$(echo "${event_line}" | cut -d' ' -f2-)
#echo "general event: ${path} ${event_types}"
if [[ "${event_types}" == *"MovedTo"* || "${event_types}" == *"Created"* ]]; then
# If event is on the directory itself (for moves/renames)
if [ "${path}" = "${CHIBISAFE_WATCH_DIR}" ]; then
find "${CHIBISAFE_WATCH_DIR}" -type f -cmin -0.1 | while read -r new_file; do
echo "Potential File Move: ${new_file}"
upload "${new_file}"
done
# If event is on a specific file
elif [ -f "${path}" ]; then
echo "Simple File Create: ${path} (${event_types})"
upload "${path}"
fi
fi
done
}
setup_environment
start_watch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.