diff --git a/telegram-send.sh b/telegram-send.sh index 60e4399..5562c6a 100755 --- a/telegram-send.sh +++ b/telegram-send.sh @@ -1,6 +1,8 @@ #!/bin/bash -TOKENFILE=${HOME}/.telegram/bottoken -CHATFILE=${HOME}/.telegram/chatid +DEFAULT_TOKENFILE=${HOME}/.telegram/bottoken +DEFAULT_CHATFILE=${HOME}/.telegram/chatid +TOKENFILE=${DEFAULT_TOKENFILE} +CHATFILE=${DEFAULT_CHATFILE} function die() { echo "FATAL: $*" >&2 @@ -8,16 +10,42 @@ function die() { } function usage() { - echo "usage: $0 \"text to send\"" + echo "usage: $0 [OPTIONS] \"text to send\"" echo echo "Instructs telegram bot to send the supplied message to a chat." 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 "File with telegram bot token: ${TOKENFILE}" - echo "File with telegram chat id: ${CHATFILE}" + echo " File with telegram bot token: ${DEFAULT_TOKENFILE}" + 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 exit 1 fi