From 246236307770bb01b2c9d7f1fe21027b93f3f5a6 Mon Sep 17 00:00:00 2001 From: Harvie Date: Tue, 24 Aug 2010 04:22:24 +0200 Subject: [PATCH 1/1] New answerscript that implements few new features (numbered scripts, parallel processing, random delay emulating human factor, documentation...) --- purple/answerscripts.sh | 45 ++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/purple/answerscripts.sh b/purple/answerscripts.sh index 7cd2864..dbcb548 100755 --- a/purple/answerscripts.sh +++ b/purple/answerscripts.sh @@ -9,7 +9,7 @@ # - WARNING: You should mind security (don't let attackers to execute their messages/nicks!) # - Each line of output is sent as reply to that message # - You can try to rewrite this script in PERL or C for better performance (or different platform) -# - This script have .exe suffix as i hope it can be eventualy replaced by some binary on windows +# - On M$ Windows answerscripts.exe from libpurple directory will be called instead of this script # # Basic example can look like this: # [ "$ANSW_STATUS" != 'available' ] && echo "<$ANSW_FROM> $ANSW_MSG" && echo "My status: $ANSW_STATUS_MSG"; @@ -28,17 +28,48 @@ # # Maybe you will want to add more hooks for receiving messages, so i've made following script # - It just executes all +x files in answerscripts.d directory so you should do your magic there -# - To disable some of those scripts just use chmod -x script +# - To disable some of those scripts simply use: chmod -x ./script +# - There is some basic structure, which means that all scripts should start their names with two-digit number +# - Files are executed in order specified by those numbers and some numbers have special meanings: +# - AB?!_ scripts without numbers are NOT executed! +# - 00 executed immediately, zero or single line output (parallel async processing) +# - 01-48 executed immediately, multiline output (serial processing) +# - 49 delay script (adds random delay to emulate human factor) +# - 50 executed after delay, zero or single line output (parallel async processing) +# - 51-79 executed after delay, multiline output (serial processing) +# - 80-99 reserved for future #legacy support, please do NOT use PURPLE_* variables in new scripts, #this will be removed in future releases: export PURPLE_FROM="$ANSW_FROM" export PURPLE_MSG="$ANSW_MSG" -#this should be modified to use run-parts in future: -dir="$(dirname "$0")"/answerscripts.d +#this may be modified to use run-parts from coreutils in future (can't get it to work): + +dir="$(dirname "$0")"; cd "$dir" #chdir to ~/.purple/ or similar +dir="${dir}/answerscripts.d" if test -d "$dir"; then - for script in "$dir"/*; do - test -x "$script" && "$script" - done + for i in {00..99}; do + + #sleep at 49 (this can be replaced by 49-delay.sh, but this should be faster) + [ $i -eq 49 ] && { + sleep $[ 2 + ($RANDOM % 8) ]; #2-9 seconds of sleep + continue; + } + + #execute scripts + ls -1 "$dir/$i"* 2>/dev/null | while read script; do + test -x "$script" && { + #determine wheter execute on background or foreground + if [ $i -eq 00 ] || [ $i -eq 50 ]; then + "$script" & + else + "$script" + fi; + } + done; + + wait; #wait for processes on background + + done; fi -- 2.30.2