diff --git a/Endurain/auto-upload/watcher.sh b/Endurain/auto-upload/watcher.sh new file mode 100644 index 0000000..7e9d53f --- /dev/null +++ b/Endurain/auto-upload/watcher.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +source ~/cycling/.config + +ACCESS_TOKEN=$(./login.sh) + +inotifywait -m ~/cycling/inbox -e create | +while read path action file; do + + FULLFILE="$path$file" + + echo "Uploading: $FULLFILE" + + RESPONSE=$(./upload.sh "$ACCESS_TOKEN" "$FULLFILE") + + if echo "$RESPONSE" | jq -e '.id' >/dev/null; then + echo "OK" + mv "$FULLFILE" ~/cycling/uploaded/ + else + echo "FAIL" + mv "$FULLFILE" ~/cycling/failed/ + fi + +done \ No newline at end of file