From be28d2b80332368098b772ecd491c9cf9087fd6f Mon Sep 17 00:00:00 2001 From: dmotte <37443982+dmotte@users.noreply.github.com> Date: Wed, 22 Nov 2023 03:03:40 +0100 Subject: [PATCH] Replaced tg.py with cURL in example --- example/build/setup/lognot/tg.py | 39 -------------------------------- example/build/setup/lognot/tg.sh | 9 ++++++++ example/build/setup/main.sh | 6 ++--- 3 files changed, 12 insertions(+), 42 deletions(-) delete mode 100644 example/build/setup/lognot/tg.py create mode 100644 example/build/setup/lognot/tg.sh diff --git a/example/build/setup/lognot/tg.py b/example/build/setup/lognot/tg.py deleted file mode 100644 index 17d8623..0000000 --- a/example/build/setup/lognot/tg.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python3 - -import sys - -import requests - - -def main(): - BOT_TOKEN = '{{ lognot_bot_token }}' - CHAT_ID = '{{ lognot_chat_id }}' - - text = sys.stdin.read() - - text = text.strip() - if text == '': - print('Message must be non-empty', file=sys.stderr) - return 1 - - resp = requests.post( - 'https://api.telegram.org/bot%s/sendMessage' % BOT_TOKEN, - json={'chat_id': CHAT_ID, 'text': text}, - ) - - resptext = resp.text - if not resptext.endswith('\n'): - resptext += '\n' - - try: - resp.raise_for_status() - sys.stdout.write(resptext) - except requests.exceptions.HTTPError: - sys.stderr.write(resptext) - raise - - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/example/build/setup/lognot/tg.sh b/example/build/setup/lognot/tg.sh new file mode 100644 index 0000000..791d1a6 --- /dev/null +++ b/example/build/setup/lognot/tg.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +bot_token='{{ lognot_bot_token }}' +chat_id='{{ lognot_chat_id }}' + +curl -sSXPOST "https://api.telegram.org/bot$bot_token/sendMessage" \ + -dchat_id="$chat_id" --data-urlencode text@- --fail-with-body -w'\n' diff --git a/example/build/setup/main.sh b/example/build/setup/main.sh index 598e8cd..f672908 100644 --- a/example/build/setup/main.sh +++ b/example/build/setup/main.sh @@ -40,7 +40,7 @@ chmod 700 /opt/startup-{early,late} # while read -r i; do echo "$HOSTNAME: $i"; done | # /opt/lognot/venv/bin/python3 -um msgbuf \ # -l INFO -i 10 -m 2048 -f /opt/lognot/buffer.txt \ -# /opt/lognot/venv/bin/python3 /opt/lognot/tg.py' +# /bin/bash /opt/lognot/tg.sh' # priority=50 # EOF @@ -48,9 +48,9 @@ install -dm700 /opt/lognot install -m700 /{setup,opt}/lognot/get.sh python3 -m venv /opt/lognot/venv /opt/lognot/venv/bin/pip3 install 'requests==2.*' 'msgbuf==1.*' -install -m600 /{setup,opt}/lognot/tg.py +install -m700 /{setup,opt}/lognot/tg.sh cat << 'EOF' > /opt/startup-late/50-lognot-secrets.sh -sed -i /opt/lognot/tg.py \ +sed -i /opt/lognot/tg.sh \ -e "s/{{ lognot_bot_token }}/$LOGNOT_BOT_TOKEN/" \ -e "s/{{ lognot_chat_id }}/$LOGNOT_CHAT_ID/" unset LOGNOT_{BOT_TOKEN,CHAT_ID}