Support -b argument to override default bottokenfile
Support -c argument to override default chatidfile
This commit is contained in:
parent
74ef28e62a
commit
b6bb6e00f6
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
TOKENFILE=${HOME}/.telegram/bottoken
|
DEFAULT_TOKENFILE=${HOME}/.telegram/bottoken
|
||||||
CHATFILE=${HOME}/.telegram/chatid
|
DEFAULT_CHATFILE=${HOME}/.telegram/chatid
|
||||||
|
TOKENFILE=${DEFAULT_TOKENFILE}
|
||||||
|
CHATFILE=${DEFAULT_CHATFILE}
|
||||||
|
|
||||||
function die() {
|
function die() {
|
||||||
echo "FATAL: $*" >&2
|
echo "FATAL: $*" >&2
|
||||||
|
@ -8,16 +10,42 @@ function die() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "usage: $0 \"text to send\""
|
echo "usage: $0 [OPTIONS] \"text to send\""
|
||||||
echo
|
echo
|
||||||
echo "Instructs telegram bot to send the supplied message to a chat."
|
echo "Instructs telegram bot to send the supplied message to a chat."
|
||||||
echo
|
echo
|
||||||
|
echo "OPTIONS"
|
||||||
|
echo " -b filename Override default bot token file (${DEFAULT_TOKENFILE})"
|
||||||
|
echo " -c filename Override default chat id token file (${DEFAULT_CHATFILE})"
|
||||||
|
echo
|
||||||
echo "Needs these files to work:"
|
echo "Needs these files to work:"
|
||||||
echo "File with telegram bot token: ${TOKENFILE}"
|
echo " File with telegram bot token: ${DEFAULT_TOKENFILE}"
|
||||||
echo "File with telegram chat id: ${CHATFILE}"
|
echo " File with telegram chat id: ${DEFAULT_CHATFILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $1 == "-h" || $# -ne 1 ]]; then
|
ARGS="b:c:h"
|
||||||
|
while getopts "$ARGS" i; do
|
||||||
|
case "$i" in
|
||||||
|
b)
|
||||||
|
TOKENFILE=$OPTARG
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
CHATFILE=$OPTARG
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
usage;
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage;
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $# -ne 1 ]]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue