diff --git a/README.html b/README.html index b4ffb7e..6736995 100644 --- a/README.html +++ b/README.html @@ -102,12 +102,12 @@
  • no need to install or learn a new programming language, library or framework
  • no database, not event driven, not OO …
  • -

    Can I have the single bashbot.sh file back?

    +

    Can I have the single bashbot.sh file back?

    At the beginning bashbot was simply the file bashbot.sh you can copy everywhere and run the bot. Now we have ‘commands.sh’, ‘mycommands.sh’, ’modules/*.sh’ and much more.

    Hey no Problem, if you are finished with your cool bot run dev/make-standalone.sh to create a stripped down Version of your bot containing only ‘bashbot.sh’ and ‘commands.sh’! For more information see Create a stripped down Version of your Bot

    @Gnadelwartz

    That’s it!

    If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

    -


    VERSION
    v0.80-pre-8-gf1ebdbb

    +


    VERSION
    v0.80-pre-11-g8669cfb

    diff --git a/README.md b/README.md index 221f69a..5298fba 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from - no need to install or learn a new programming language, library or framework - no database, not event driven, not OO ... -#### Can I have the single bashbot.sh file back? +### Can I have the single bashbot.sh file back? At the beginning bashbot was simply the file ```bashbot.sh``` you can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. Hey no Problem, if you are finished with your cool bot run ```dev/make-standalone.sh``` to create a stripped down Version of your bot containing only @@ -109,4 +109,4 @@ Hey no Problem, if you are finished with your cool bot run ```dev/make-standalon If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-pre-8-gf1ebdbb +#### $$VERSION$$ v0.80-pre-11-g8669cfb diff --git a/README.txt b/README.txt index 2ab117c..1a0d429 100644 --- a/README.txt +++ b/README.txt @@ -139,7 +139,7 @@ health status - no need to install or learn a new programming language, library or framework - no database, not event driven, not OO ... -#### Can I have the single bashbot.sh file back? +### Can I have the single bashbot.sh file back? At the beginning bashbot was simply the file ```bashbot.sh``` you can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. @@ -158,4 +158,4 @@ down Version of your Bot](doc/7_develop.md) If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-pre-8-gf1ebdbb +#### $$VERSION$$ v0.80-pre-11-g8669cfb diff --git a/bashbot.sh b/bashbot.sh index 59ce360..ffc76a8 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-pre-9-g8dfdf2e +#### $$VERSION$$ v0.80-pre-11-g8669cfb # # Exit Codes: # - 0 sucess (hopefully) @@ -147,12 +147,27 @@ procname(){ printf '%s\n' "$2${ME}_$1" } -# $1 proc name +# $1 sting to search for proramm incl. parameters +# retruns a list of PIDs of all current bot proceeses matching $1 proclist() { # shellcheck disable=SC2009 - ps -fu "${UID}" | grep -v grep| grep "$1" | sed 's/\s\+/\t/g' | cut -f 2 + ps -fu "${UID}" | grep -F "$1" | grep -v ' grep'| grep -F "${ME}" | sed 's/\s\+/\t/g' | cut -f 2 } +# $1 sting to search for proramm to kill +killallproc() { + local procid; procid="$(proclist "$1")" + if [ "${procid}" != "" ] ; then + # shellcheck disable=SC2046 + kill $(proclist "$1") + sleep 1 + procid="$(proclist "$1")" + # shellcheck disable=SC2046 + [ "${procid}" != "" ] && kill $(proclist -9 "$1") + fi +} + + # returns true if command exist _exists() { diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index fc65af3..1db1fa2 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -2,7 +2,7 @@ # file: make-distribution.sh # creates files and arcchives to dirtribute bashbot # -#### $$VERSION$$ v0.80-pre-0-gdd7c66d +#### $$VERSION$$ v0.80-pre-11-g8669cfb # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -38,7 +38,7 @@ cd "${DISTDIR}" || exit 1 # additional stuff mv "bashbot.rc" "bashbot.rc.dist" -mv "commands.sh" "commands.sh.dist" +# mv "commands.sh" "commands.sh.dist" # will be overwritten from v0.80 on mv "mycommands.sh" "mycommands.sh.dist" JSONSHFILE="JSON.sh/JSON.sh" diff --git a/doc/6_reference.md b/doc/6_reference.md index 63923b2..1d2d8ba 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -589,11 +589,49 @@ Returns PrefixBotname_Postfix *usage:* procname postfix prefix +*example:* +```bash +# returns botname, if already set +procname +# returns unique identifier for everthing related to chat +procname "${CHAT[ID]}" +# returns unique identifier for job, regardless of chat +procname "" "back-jobname-" +# returns unique identifier for a job related to a chat +# e.g. fifo, cmd and logfile name +procname "${CHAT[ID]}" "back-jobname-" +``` + ##### proclist -Returns process IDs from ps -ef containing procname +Returns process IDs of current bot processes containing string 'pattern' in name or argument. -*usage:* proclist procname +*usage:* proclist pattern +*example:* +```bash +# list PIDs of all background processes +proclist "back-" +# list PIDs of all processes of a job +proclist "back-jobname-" +# list PIDs of all processes for a chat +proclist "_${CHAT[ID]}" +# list PIDs of all bot processes +proclist +``` +##### killallproc +kill all current bot processes containing string 'pattern' in name or argument + +*usage:* killallproc pattern + +*example:* +```bash +# kill all background processes +killallproc "back-" +# kill all processes for a chat +killallproc "_${CHAT[ID]}" +# kill all bot processes, including YOURSELF! +killallproc +``` ##### get_file *usage:* url="$(get_file "${CHAT[ID]}" "message")" @@ -643,5 +681,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.80-pre-5-ge5f7b2d +#### $$VERSION$$ v0.80-pre-11-g8669cfb diff --git a/modules/background.sh b/modules/background.sh index 38f2889..cc05810 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-pre-10-gfd7ca77 +#### $$VERSION$$ v0.80-pre-11-g8669cfb # source from commands.sh if you want ro use interactive or background jobs @@ -110,7 +110,7 @@ inproc() { # suspendb* # resumeb* job_control() { - local content proc CHAT job fifo + local content proc CHAT job fifo killall="" for FILE in "${TMPDIR:-.}/"*-back.cmd; do [ "${FILE}" = "${TMPDIR:-.}/*-back.cmd" ] && echo -e "${RED}No background processes.${NC}" && break content="$(< "${FILE}")" @@ -126,13 +126,17 @@ job_control() { ;; "suspendb"*) echo "Suspend Job: ${proc} ${fifo}" - kill_proc "${CHAT}" "${proc}" "${job}" + kill_proc "${CHAT}" "${job}" + killall="y" ;; "killb"*) echo "Kill Job: ${proc} ${fifo}" - kill_proc "${CHAT}" "${proc}" "${job}" + kill_proc "${CHAT}" "${job}" rm -f "${FILE}" # remove job + killall="y" ;; esac done + # kill all requestet. kill ALL background jobs, even not listed in data-bot-bash + [ "${killall}" = "y" ] && killallproc "back-" }