mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-08-20 21:33:16 -07:00
Add Telegram support
Add default Telegram variables. Add response. Insert debugging option. Added exit codes. Add Telegram to README.md
This commit is contained in:
parent
f1bec29d62
commit
bd31e29441
2 changed files with 50 additions and 1 deletions
|
@ -51,6 +51,14 @@ There are also a few additional options for the more enterprising user. Setting
|
||||||
NOTE! If you define this, you MUST define DISTRO and BUILD
|
NOTE! If you define this, you MUST define DISTRO and BUILD
|
||||||
- DISTRO and BUILD
|
- DISTRO and BUILD
|
||||||
Override which version to download, use -l option to see what you can select.
|
Override which version to download, use -l option to see what you can select.
|
||||||
|
- TELEGRAM_NOTIFY
|
||||||
|
Enable Telegram notification support. Requires TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID
|
||||||
|
- TELEGRAM_BOT_TOKEN
|
||||||
|
After talking to BotFather and creating a new bot, you can acquire the Bot Token required for the Telegram API.
|
||||||
|
- TELEGRAM_CHAT_ID
|
||||||
|
Ask myidbot for your chat ID, or your group's chat ID, required for the Telegram API.
|
||||||
|
- TELEGRAM_DEBUG
|
||||||
|
Output API messages for debugging.
|
||||||
|
|
||||||
Most of these options can be specified on the command-line as well, this is just a more convenient way of doing it if you're scripting it. Which brings us to...
|
Most of these options can be specified on the command-line as well, this is just a more convenient way of doing it if you're scripting it. Which brings us to...
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,13 @@ REDHAT_INSTALL="yum -y install"
|
||||||
DEBIAN_INSTALL="dpkg -i"
|
DEBIAN_INSTALL="dpkg -i"
|
||||||
DISTRO_INSTALL=""
|
DISTRO_INSTALL=""
|
||||||
|
|
||||||
|
# Telegram notification options
|
||||||
|
TELEGRAM_NOTIFY="no"
|
||||||
|
TELEGRAM_CHAT_ID="no"
|
||||||
|
TELEGRAM_BOT_TOKEN="no"
|
||||||
|
TELEGRAM_MESSAGE=""
|
||||||
|
TELEGRAM_DEBUG=no
|
||||||
|
|
||||||
# Sanity, make sure wget is in our path...
|
# Sanity, make sure wget is in our path...
|
||||||
wget >/dev/null 2>/dev/null
|
wget >/dev/null 2>/dev/null
|
||||||
if [ $? -eq 127 ]; then
|
if [ $? -eq 127 ]; then
|
||||||
|
@ -140,7 +147,7 @@ cronexit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $(basename $0) [-acfhopqsSuU] [config file]"
|
echo "Usage: $(basename $0) [-acfhopqsStuU] [config file]"
|
||||||
echo ""
|
echo ""
|
||||||
echo " config file overrides the default ~/.plexupdate"
|
echo " config file overrides the default ~/.plexupdate"
|
||||||
echo " If used, it must be the LAST option or it will be ignored"
|
echo " If used, it must be the LAST option or it will be ignored"
|
||||||
|
@ -157,6 +164,7 @@ usage() {
|
||||||
echo " -r Print download URL and exit"
|
echo " -r Print download URL and exit"
|
||||||
echo " -s Auto start (needed for some distros)"
|
echo " -s Auto start (needed for some distros)"
|
||||||
echo " -S Silent mode. No text output, only exit codes"
|
echo " -S Silent mode. No text output, only exit codes"
|
||||||
|
echo " -t Send a Telegram notification"
|
||||||
echo " -u Auto update plexupdate.sh before running it (experimental)"
|
echo " -u Auto update plexupdate.sh before running it (experimental)"
|
||||||
echo " -U Do not autoupdate plexupdate.sh (experimental, default)"
|
echo " -U Do not autoupdate plexupdate.sh (experimental, default)"
|
||||||
echo
|
echo
|
||||||
|
@ -181,6 +189,7 @@ do
|
||||||
(-r) PRINT_URL=yes;;
|
(-r) PRINT_URL=yes;;
|
||||||
(-s) AUTOSTART=yes;;
|
(-s) AUTOSTART=yes;;
|
||||||
(-S) SILENT=yes;;
|
(-S) SILENT=yes;;
|
||||||
|
(-t) TELEGRAM_NOTIFY=yes;;
|
||||||
(-u) AUTOUPDATE=yes;;
|
(-u) AUTOUPDATE=yes;;
|
||||||
(-U) AUTOUPDATE=no;;
|
(-U) AUTOUPDATE=no;;
|
||||||
(--) ;;
|
(--) ;;
|
||||||
|
@ -507,4 +516,36 @@ if [ "${AUTOSTART}" == "yes" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "${TELEGRAM_NOTIFY}" == "yes" ]; then
|
||||||
|
# check to see if there is a BOT_TOKEN provided; if not, error out sending notification.
|
||||||
|
if [ "${TELEGRAM_BOT_TOKEN}" == "no" ]; then
|
||||||
|
echo "TELEGRAM_BOT_TOKEN is empty. Get your BOT_TOKEN from @BotFather."
|
||||||
|
cronexit 1
|
||||||
|
fi
|
||||||
|
# check to see if there is a CHAT_ID in which to send the notification; if not, error out sending notification.
|
||||||
|
if [ "${TELEGRAM_CHAT_ID}" = "no" ]; then
|
||||||
|
echo "TELEGRAM_CHAT_ID is empty. Get the Chat ID from @myidbot."
|
||||||
|
cronexit 1
|
||||||
|
fi
|
||||||
|
# check to see if AUTOINSTALL is on; if so, set a successful update notice.
|
||||||
|
if [ "${AUTOINSTALL}" == "yes" ]; then
|
||||||
|
TELEGRAM_MESSAGE="Plex was successfully updated using ${FILENAME}"
|
||||||
|
else
|
||||||
|
TELEGRAM_MESSAGE="Plex downloaded ${FILENAME} to ${DOWNLOADDIR}"
|
||||||
|
fi
|
||||||
|
# send the notification to Telegram's BOT API, output to TELEGRAM_RESPONSE for potential debugging.
|
||||||
|
TELEGRAM_RESPONSE=$(curl -s https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage?chat_id="${TELEGRAM_CHAT_ID}"\&text="${TELEGRAM_MESSAGE}")
|
||||||
|
|
||||||
|
if [ "${TELEGRAM_DEBUG}" == "yes" ]; then
|
||||||
|
echo "######################"
|
||||||
|
echo "### TELEGRAM DEBUG ###"
|
||||||
|
echo $TELEGRAM_RESPONSE
|
||||||
|
echo "######################"
|
||||||
|
else
|
||||||
|
echo "Telegram notification sent."
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
cronexit 0
|
cronexit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue