|
@ -5,35 +5,89 @@ |
|
|
if [[ "$UID" == "0" ]]; then |
|
|
if [[ "$UID" == "0" ]]; then |
|
|
NTFY_CONFIG_FILE="/etc/ntfy/ntfy.conf" |
|
|
NTFY_CONFIG_FILE="/etc/ntfy/ntfy.conf" |
|
|
else |
|
|
else |
|
|
NTFY_CONFIG_FILE="$HOME/.config/ntfy/ntfy.conf" |
|
|
|
|
|
|
|
|
NTFY_CONFIG_FILE=~/.config/ntfy/ntfy.conf |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
SERVER="https://ntfy.0k.io/" |
|
|
|
|
|
|
|
|
if ! [ -e "$NTFY_CONFIG_FILE" ]; then |
|
|
if ! [ -e "$NTFY_CONFIG_FILE" ]; then |
|
|
mkdir -p "${NTFY_CONFIG_FILE%/*}" |
|
|
mkdir -p "${NTFY_CONFIG_FILE%/*}" |
|
|
## default option to change if needed |
|
|
## default option to change if needed |
|
|
echo 'SERVER="https://ntfy.0k.io/"' > "$NTFY_CONFIG_FILE" |
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
echo "SERVER=$SERVER" > "$NTFY_CONFIG_FILE" |
|
|
|
|
|
elif ! grep -q "^SERVER=" "$NTFY_CONFIG_FILE"; then |
|
|
|
|
|
echo "SERVER=$SERVER" >> "$NTFY_CONFIG_FILE" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
source "$NTFY_CONFIG_FILE" |
|
|
source "$NTFY_CONFIG_FILE" |
|
|
|
|
|
|
|
|
for var in TOKEN SERVER; do |
|
|
|
|
|
|
|
|
for var in SERVER LOGIN PASSWORD; do |
|
|
if ! [ -v "$var" ]; then |
|
|
if ! [ -v "$var" ]; then |
|
|
echo "Error: missing $var in $NTFY_CONFIG_FILE" |
|
|
echo "Error: missing $var in $NTFY_CONFIG_FILE" |
|
|
exit 1 |
|
|
exit 1 |
|
|
fi |
|
|
fi |
|
|
done |
|
|
done |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exname=${0##*/} |
|
|
exname=${0##*/} |
|
|
usage="Usage: $exname CHANNEL MESSAGE" |
|
|
|
|
|
|
|
|
channel="main" |
|
|
|
|
|
|
|
|
|
|
|
usage="Usage: $exname [-c CHANNEL] [-t TITLE ] MESSAGE |
|
|
|
|
|
---------------------------------------------- |
|
|
|
|
|
--- Send MESSAGE with TITLE to the specified CHANNEL. --- |
|
|
|
|
|
---------------------------------------------- |
|
|
|
|
|
If no CHANNEL is provided, the message will be sent to the default channel |
|
|
|
|
|
Default CHANNEL is format as follow : ConfiguredLOGIN_${default_channel} |
|
|
|
|
|
If no TITLE is provided, the message will be sent with the hostname as title." |
|
|
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then |
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do |
|
|
|
|
|
arg="$1" |
|
|
|
|
|
shift |
|
|
|
|
|
case "$arg" in |
|
|
|
|
|
-h|--help) |
|
|
|
|
|
echo "$usage" |
|
|
|
|
|
exit 0 |
|
|
|
|
|
;; |
|
|
|
|
|
-c|--channel) |
|
|
|
|
|
channel="$1" |
|
|
|
|
|
[ -z "$channel" ] || { |
|
|
|
|
|
echo "Error: no argument for channel option." >&2 |
|
|
echo "$usage" >&2 |
|
|
echo "$usage" >&2 |
|
|
exit 1 |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
shift |
|
|
|
|
|
;; |
|
|
|
|
|
-t|--title) |
|
|
|
|
|
title="$1" |
|
|
|
|
|
[ -z "$title" ] || { |
|
|
|
|
|
echo "Error: no argument for title option." >&2 |
|
|
|
|
|
echo "$usage" >&2 |
|
|
|
|
|
exit 1 |
|
|
|
|
|
} |
|
|
|
|
|
shift |
|
|
|
|
|
;; |
|
|
|
|
|
*) |
|
|
|
|
|
[ -z "$message" ] && { message="$arg"; continue; } |
|
|
|
|
|
echo "Error : Unexpected positional argument '$arg'." >&2 |
|
|
|
|
|
echo "$usage" >&2 |
|
|
|
|
|
exit 1 |
|
|
|
|
|
;; |
|
|
|
|
|
esac |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
channel="$1" |
|
|
|
|
|
message="$2" |
|
|
|
|
|
|
|
|
[ -n "$message" ] || { |
|
|
|
|
|
echo "Error: missing message." >&2 |
|
|
|
|
|
echo "$usage" >&2 |
|
|
|
|
|
exit 1 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
curl -s -H "Authorization: Bearer $TOKEN" \ |
|
|
|
|
|
-d "$message" "$SERVER/$channel" > /dev/null |
|
|
|
|
|
|
|
|
curl_opts=( |
|
|
|
|
|
-s |
|
|
|
|
|
-u "$LOGIN:$PASSWORD" |
|
|
|
|
|
-d "$message" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$title" ]; then |
|
|
|
|
|
curl_opts+=(-H "Title: [$(hostname)] $title") |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
curl "${curl_opts[@]}" "$SERVER/${LOGIN}_$channel" > /dev/null |