| 1 | #!/bin/sh |
| 2 | # |
| 3 | # This file is called for every message received by libpurple clients (pidgin,finch,...) |
| 4 | # - You can try to rewrite this script in PERL or C for better performance (or different platform) - let me know |
| 5 | # - On M$ Windows answerscripts.exe from libpurple directory will be called instead of this script |
| 6 | # |
| 7 | # Maybe you will want to add more hooks for receiving messages, so i've made following script |
| 8 | # - It just executes all +x files in answerscripts.d directory so you should do your magic there |
| 9 | # - To disable some of those scripts simply use: chmod -x ./script |
| 10 | # - There is some basic structure, which means that all scripts should start their names with two-digit number |
| 11 | # - Files are executed in order specified by those numbers and some numbers have special meanings: |
| 12 | # - AB?!_ scripts without numbers are NOT executed! |
| 13 | # - 00 executed immediately, zero or single line output (parallel async processing) |
| 14 | # - 01-48 executed immediately, multiline output (serial processing) |
| 15 | # - 49 delay script (adds random delay to emulate human factor) |
| 16 | # - 50 executed after delay, zero or single line output (parallel async processing) |
| 17 | # - 51-79 executed after delay, multiline output (serial processing) |
| 18 | # - 80-99 reserved for future |
| 19 | |
| 20 | #legacy support, please do NOT use PURPLE_* variables in new scripts, |
| 21 | #this will be removed in future releases: |
| 22 | export PURPLE_FROM="$ANSW_FROM" |
| 23 | export PURPLE_MSG="$ANSW_MSG" |
| 24 | |
| 25 | #this may be modified to use run-parts from coreutils in future (can't get it to work): |
| 26 | |
| 27 | dir="$(dirname "$0")"; cd "$dir" #chdir to ~/.purple/ or similar |
| 28 | dir="${dir}/answerscripts.d" |
| 29 | if test -d "$dir"; then |
| 30 | for i in {00..99}; do |
| 31 | |
| 32 | #sleep at 49 (this can be replaced by 49-delay.sh, but this should be faster) |
| 33 | [ $i -eq 49 ] && { |
| 34 | sleep $[ 2 + ($RANDOM % 8) ]; #2-9 seconds of sleep |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | #execute scripts |
| 39 | ls -1 "$dir/$i"* 2>/dev/null | while read script; do |
| 40 | test -x "$script" && { |
| 41 | #determine wheter execute on background or foreground |
| 42 | if [ $i -eq 00 ] || [ $i -eq 50 ]; then |
| 43 | "$script" & |
| 44 | else |
| 45 | "$script" |
| 46 | fi; |
| 47 | } |
| 48 | done; |
| 49 | |
| 50 | wait; #wait for processes on background |
| 51 | |
| 52 | done; |
| 53 | fi |