3 # Watching the `trigger_folder`, which is a Dropbox-syncing folder.
4 # Once the remote svn updated, a text file will be added to this folder via
5 # an IFTTT recipe (14339724).
6 # When `fswatch` get that change (a new file synced down), the handler will be
7 # called to fetch remote changes and merge into local repository and then push
9 # If the fetch-and-merge process fails with any error, a log file will be saved
10 # to another Dropbox-syncing folder `log_folder`. Another IFTTT recipe
11 # (14395025) will send an email to my GMail inbox to notify me.
13 bin_folder
=$
(dirname `readlink -f "$0"`)
15 trigger_folder
=/Users
/zhouji
/Dropbox
/IFTTT
/Feed
/autoproxy-gfwlist-svn
16 log_folder
=/Users
/zhouji
/Dropbox
/IFTTT
/GfwList
17 handler
=$bin_folder/fetch_and_merge.sh
19 function handle_trigger
() {
21 echo "----- ----- ----- ----- ----- ----- ----- -----"
22 echo "handling trigger $trigger_file"
24 if [ -f "$trigger_file" ]; then
25 local tmp_file
=`mktemp`
26 "$handler" "$@" 2>&1 |
tee "$tmp_file"
27 local ret
=${PIPESTATUS[0]}
28 if [ $ret -eq 0 ]; then
29 echo "$trigger_file process succeed"
32 local log_file
="$log_folder/failure_$(date '+%Y%m%d_%H%M%S').txt"
33 echo "$trigger_file process failed, logged to $log_file"
34 mv "$tmp_file" "$log_file"
37 echo "$trigger_file not exists, ignored"
40 echo "===== ===== ===== ===== ===== ===== ===== ====="
43 #fswatch -0 "$trigger_folder" | xargs -0 -n 1 -I file handle_trigger file
44 fswatch
-0 "$trigger_folder" |
while read -d $
'\0' file; do
45 handle_trigger
"$file"