add bin/bashbot_env.inc.sh

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-12-18 14:53:44 +01:00
parent 0db0215d9b
commit bd155f8cb5
3 changed files with 55 additions and 33 deletions

33
bin/bashbot_env.inc.sh Normal file
View File

@ -0,0 +1,33 @@
#!/bin/bash
#===============================================================================
#
# FILE: bashbor_env.inc.sh
#
# DESCRIPTION: set bashbot environment for all scripts in this directory
#
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 18.12.2020 12:27
#
#### $$VERSION$$ v1.2-dev2-38-g0db0215
#===============================================================================
# set where your bashbot lives
# default: one dir up
BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../"
#####
# if files are not readable, eviroment is wrong or bashbot is not initialized
# check for botconfig.jssh readable
if [ ! -r "${BASHBOT_HOME}/botconfig.jssh" ]; then
echo "Bashbot config file in \"${BASHBOT_HOME}\" does not exist or is not readable."
exit 3
fi
# check for count.jssh readable
if [ ! -r "${BASHBOT_HOME}/count.jssh" ]; then
echo "Bashbot count file in \"${BASHBOT_HOME}\" does not exist or is not readable"
exit 3
fi

View File

@ -1,4 +1,4 @@
#!/bin/bash -
#!/bin/bash
#===============================================================================
#
# FILE: broadcast_message.sh
@ -21,37 +21,30 @@
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 16:14:57
# CREATED: 16.12.2020 16:14
#
#### $$VERSION$$ v1.2-dev2-34-gc356143
#### $$VERSION$$ v1.2-dev2-38-g0db0215
#===============================================================================
# set where your bashbot lives
BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../"
# check for botconfig.jssh
if [ ! -r "${BASHBOT_HOME}/botconfig.jssh" ]; then
echo "No bashbot config file in ${BASHBOT_HOME}"
exit 3
fi
# check for count.jssh
if [ ! -r "${BASHBOT_HOME}/count.jssh" ]; then
echo "No bashbot count file in ${BASHBOT_HOME}"
exit 3
fi
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh"
####
# broadcast is dangerous, without --doit we do a dry run ...
if [ "$1" == "--doit" ]; then
DOIT="yes"
shift
fi
####
# send to users by default, --group sends to groups also
if [ "$1" == "--groups" ]; then
GROUPSALSO=" and groups"
shift
fi
####
# parse args -----------------
SEND="send_message"
case "$1" in

View File

@ -1,4 +1,4 @@
#!/bin/bash -
#!/bin/bash
#===============================================================================
#
# FILE: send_message.sh
@ -19,20 +19,16 @@
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 11:34:27
# CREATED: 16.12.2020 11:34
#
#### $$VERSION$$ v1.2-dev2-34-gc356143
#### $$VERSION$$ v1.2-dev2-38-g0db0215
#===============================================================================
# set where your bashbot lives
BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../"
# check for botconfig.jssh
if [ ! -r "${BASHBOT_HOME}/botconfig.jssh" ]; then
echo "No bashbot config file in ${BASHBOT_HOME}"
exit 3
fi
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh"
####
# parse args
SEND="send_message"
case "$1" in
@ -61,16 +57,16 @@ case "$1" in
;;
esac
if [[ "$1" == *[!0-9-]* ]]; then
echo "CHAT[ID] is not a number! use: $0 -h for help"
exit 2
fi
# source bashbot and send message
# shellcheck disable=SC1090
source "${BASHBOT_HOME}/bashbot.sh" source "$3"
####
# ready, do stuff here -----
# send message in selected format
"${SEND}" "$1" "$2"
# output result
# output send message result
jssh_printDB "BOTSENT" | sort -r