Browse Source
new: [send] add send cmd, request auth on install and update, add vps check backup function and cron
new: [send] add send cmd, request auth on install and update, add vps check backup function and cron
Boris Gallet
11 months ago
6 changed files with 277 additions and 2 deletions
-
53bin/myc-install
-
56bin/myc-update
-
93bin/send
-
69bin/vps
-
4etc/cron.d/check-backup
-
BINetc/ssh/ntfy-key
@ -0,0 +1,93 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
## Send a notification with NTFY and check if the config file is complete |
||||
|
|
||||
|
if [[ "$UID" == "0" ]]; then |
||||
|
NTFY_CONFIG_FILE="/etc/ntfy/ntfy.conf" |
||||
|
else |
||||
|
NTFY_CONFIG_FILE=~/.config/ntfy/ntfy.conf |
||||
|
fi |
||||
|
|
||||
|
SERVER="https://ntfy.0k.io/" |
||||
|
|
||||
|
if ! [ -e "$NTFY_CONFIG_FILE" ]; then |
||||
|
mkdir -p "${NTFY_CONFIG_FILE%/*}" |
||||
|
## default option to change if needed |
||||
|
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" |
||||
|
|
||||
|
for var in SERVER LOGIN PASSWORD; do |
||||
|
if ! [ -v "$var" ]; then |
||||
|
echo "Error: missing $var in $NTFY_CONFIG_FILE" |
||||
|
exit 1 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
|
||||
|
exname=${0##*/} |
||||
|
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." |
||||
|
|
||||
|
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 |
||||
|
exit 1 |
||||
|
} |
||||
|
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 |
||||
|
|
||||
|
[ -n "$message" ] || { |
||||
|
echo "Error: missing message." >&2 |
||||
|
echo "$usage" >&2 |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
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 |
@ -0,0 +1,4 @@ |
|||||
|
SHELL=/bin/bash |
||||
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
||||
|
|
||||
|
12 * * * * root vps check backup -n 2>&1 | logger -t stats |
Write
Preview
Loading…
Cancel
Save
Reference in new issue