Fixed typo in README
[mirrors/libpurple-core-answerscripts.git] / purple / answerscripts.sh
1 #!/bin/bash
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, no user scripts at this level!)
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 #this may be modified to use run-parts from coreutils in future (can't get it to work):
21
22 dir="$(dirname "$0")"; cd "$dir" #chdir to ~/.purple/ or similar
23 dir="${dir}/answerscripts.d"
24 if test -d "$dir"; then
25 for i in {00..99}; do
26
27 #sleep at 49 (this can be replaced by 49-delay.sh, but this should be faster)
28 [ $i -eq 49 ] && {
29 find "$dir"/[5-9][0-9]-* -executable | grep . >/dev/null && #check if it's worth waiting
30 sleep $(( 2 + ($RANDOM % 8) )); #2-9 seconds of sleep
31 continue;
32 }
33
34 #execute scripts
35 ls -1 "$dir/$i"* 2>/dev/null | while read script; do
36 test -x "$script" && {
37 #determine wheter execute on background or foreground
38 if [ $i -eq 00 ] || [ $i -eq 50 ]; then
39 "$script" &
40 else
41 "$script"
42 fi;
43 }
44 done;
45
46 wait; #wait for processes on background
47
48 done;
49 fi
This page took 0.263515 seconds and 4 git commands to generate.