export BOT_TOKEN ?= "8390868324:AAG3_d1hfVR2M6pGAgDK6ZvhOe4J97nyopw"
export CHAT_ID ?= "454403445"
+ export TGDisableWebPagePreview ?= "True"
+ export TGParseMode ?= "html"
export REPO_DIR ?= $(BUILD_DIR)
export DRY_RUN ?= 0
GLOB_RSC := $(wildcard html/AM-GlobalFunc.rsc)
DATE ?= $(shell (date '+%T %d.%m.%Y'))
-DTSTAMP ?= $(shell (date '+%Y%d%m%H%M%S'))
+DTSTAMP_FMT ?= "+%Y%m%d%H%M"
+DTSTAMP ?= $(shell (date $(DTSTAMP_FMT)))
VERSION ?= $(shell git symbolic-ref --short HEAD 2>/dev/null)/$(shell git rev-list --count HEAD 2>/dev/null)/$(shell git rev-parse --short=8 HEAD 2>/dev/null)
RUN_OWNER := $(shell whoami 2>/dev/null)
COMM_REPO := $(shell git rev-parse --show-toplevel | rev | cut -d/ -f1 | rev 2>/dev/nul)
# get the latest commit hash in the short form
COMM_HASH := $(shell git rev-parse --short=8 HEAD 2>/dev/null) # Get short commit hash
#COMMIT := $(shell git rev-parse --short HEAD)
-# get the latest commit date in the form of YYYYmmdd
-COMM_DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d%H%M")
+# get the latest commit date in the form of YYYYmmddHHMM ($(DTSTAMP_FMT))
+COMM_DATE := $(shell git log -1 --format=%cd --date=format:$(DTSTAMP_FMT))
ifneq ($(COMM_HASH), $(COMM_TAG))
TAG_VERS :=$(TAG_VERS)-next-$(COMM_HASH)-$(COMM_DATE)
endif
export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO
-.ONESHELL:
SHELL := /bin/bash
+
+export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO COMM_DATE
+
+.ONESHELL:
+
.DEFAULT_GOAL := run
export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO
--- /dev/null
+#!/usr/bin/env bash
+
+msg=${1:-no message}
+
+if [[ "${DRY_RUN:-0}" == "1" ]]; then
+ echo "[notify][dry-run] $msg"
+ exit 0
+fi
+
+if [[ -z "${BOT_TOKEN:-}" || -z "${CHAT_ID:-}" ]]; then
+ echo "[notify] BOT_TOKEN/CHAT_ID not set, skip"
+ exit 0
+fi
+#echo "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${CHAT_ID}&text=$msg&parse_mode=$TGParseMode&disable_web_page_preview=$TGDisableWebPagePreview"
+#exit 0
+curl -fsS --connect-timeout 5 --max-time 10 \
+ -X POST "https://api.telegram.org/bot"${BOT_TOKEN}"/sendMessage" \
+ -d "chat_id=${CHAT_ID}" \
+ -d "parse_mode=html" \
+ -d "disable_web_page_preview=True" \
+ --data-urlencode "text=${msg}"
+ # >/dev/null
+# || true
#!/usr/bin/env bash
-
msg="${1:-no message}"
- if [[ "${DRY_RUN:-0}" == "1" ]]; then
- echo "[notify][dry-run] $msg"
- exit 0
- if [[ -z "${BOT_TOKEN:-}" || -z "${CHAT_ID:-}" ]]; then
- echo "[notify] BOT_TOKEN/CHAT_ID not set, skip"
- exit 0
+trim_wrapping_quotes() {
+ local v="${1-}"
+ if [[ "$v" =~ ^\"(.*)\"$ ]]; then
+ printf '%s' "${BASH_REMATCH[1]}"
+ return
+ fi
+ if [[ "$v" =~ ^\'(.*)\'$ ]]; then
+ printf '%s' "${BASH_REMATCH[1]}"
+ return
fi
+ printf '%s' "$v"
+}
+
+if [[ "${DRY_RUN:-0}" == "1" ]]; then
+ echo "[notify][dry-run] $msg"
+ exit 0
+fi
+
+BOT_TOKEN_CLEAN="$(trim_wrapping_quotes "${BOT_TOKEN:-}")"
+CHAT_ID_CLEAN="$(trim_wrapping_quotes "${CHAT_ID:-}")"
+TG_PARSE_MODE_CLEAN="$(trim_wrapping_quotes "${TGParseMode:-}")"
+TG_DISABLE_PREVIEW_CLEAN="$(trim_wrapping_quotes "${TGDisableWebPagePreview:-}")"
+
+if [[ -z "$BOT_TOKEN_CLEAN" || -z "$CHAT_ID_CLEAN" ]]; then
+ echo "[notify] BOT_TOKEN/CHAT_ID not set, skip"
+ exit 0
+fi
+curl_args=(
+ -fsS
+ --connect-timeout 5
+ --max-time 10
+ -X POST "https://api.telegram.org/bot${BOT_TOKEN_CLEAN}/sendMessage"
+ -d "chat_id=${CHAT_ID_CLEAN}"
+ --data-urlencode "text=${msg}"
+)
+
+if [[ -n "$TG_PARSE_MODE_CLEAN" ]]; then
+ curl_args+=( -d "parse_mode=${TG_PARSE_MODE_CLEAN}" )
+fi
+
+if [[ -n "$TG_DISABLE_PREVIEW_CLEAN" ]]; then
+ curl_args+=( -d "disable_web_page_preview=${TG_DISABLE_PREVIEW_CLEAN}" )
+fi
- curl -fsS --connect-timeout 5 --max-time 10 \
- -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
- -d "chat_id=${CHAT_ID}" \
- --data-urlencode "text=${msg}" >/dev/null || true
+curl "${curl_args[@]}" >/dev/null