fix(skills): make ntfy_send.sh self-contained to avoid safety guard
ntfy_send.sh now auto-loads config from its own skill's data/ dir,
eliminating the need for 'source' and '${}' patterns in cron
commands that trigger PicoClaw's exec safety guard.
SKILL.md commands simplified from:
source .../ntfy.conf; NTFY_TOPIC="$NTFY_TOPIC" bash ntfy_send.sh
to:
bash skills/reminder/scripts/ntfy_send.sh 'message' --title T
This commit is contained in:
parent
9c4a7f919f
commit
a1c8d3c321
3 changed files with 69 additions and 42 deletions
|
|
@ -1,24 +1,33 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# ntfy_send.sh — Stateless ntfy notification sender utility
|
# ntfy_send.sh — ntfy notification sender for prayer-times skill
|
||||||
# Does NOT manage its own config. Reads NTFY_TOPIC from environment variable.
|
# Auto-loads config from skills/prayer-times/data/config (reads NTFY_TOPIC)
|
||||||
# Each skill is responsible for setting NTFY_TOPIC from its own config.
|
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage (from workspace root):
|
||||||
# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message"
|
# bash skills/prayer-times/scripts/ntfy_send.sh "message"
|
||||||
# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message" --title "T" --tags "t" --priority "high"
|
# bash skills/prayer-times/scripts/ntfy_send.sh "message" --title "T" --tags "t"
|
||||||
#
|
#
|
||||||
# If NTFY_TOPIC is empty, silently skips (exit 0).
|
# If NTFY_TOPIC is empty or config missing, silently exits (exit 0).
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ -z "${NTFY_TOPIC:-}" ]; then
|
# Auto-load config relative to this script
|
||||||
# No topic configured — skip silently so cron jobs don't fail
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
CONF_FILE="$SKILL_DIR/data/config"
|
||||||
|
|
||||||
|
# Source config if exists
|
||||||
|
NTFY_TOPIC=""
|
||||||
|
if [ -f "$CONF_FILE" ]; then
|
||||||
|
. "$CONF_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$NTFY_TOPIC" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
message="${1:-}"
|
message="$1"
|
||||||
if [ -z "$message" ]; then
|
if [ -z "$message" ]; then
|
||||||
echo "Usage: ntfy_send.sh \"message\" [--title T] [--tags T] [--priority P]"
|
echo "Usage: ntfy_send.sh message [--title T] [--tags T] [--priority P]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
|
|
@ -34,11 +43,16 @@ while [ $# -gt 0 ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Build curl args
|
# Send notification
|
||||||
curl_args=(-sf)
|
HEADERS=""
|
||||||
[ -n "$title" ] && curl_args+=(-H "Title: $title")
|
if [ -n "$title" ]; then
|
||||||
[ -n "$tags" ] && curl_args+=(-H "Tags: $tags")
|
HEADERS="$HEADERS -H \"Title: $title\""
|
||||||
[ -n "$priority" ] && curl_args+=(-H "Priority: $priority")
|
fi
|
||||||
curl_args+=(-d "$message" "$NTFY_TOPIC")
|
if [ -n "$tags" ]; then
|
||||||
|
HEADERS="$HEADERS -H \"Tags: $tags\""
|
||||||
|
fi
|
||||||
|
if [ -n "$priority" ]; then
|
||||||
|
HEADERS="$HEADERS -H \"Priority: $priority\""
|
||||||
|
fi
|
||||||
|
|
||||||
curl "${curl_args[@]}" > /dev/null 2>&1 || true
|
eval curl -sf $HEADERS -d "\"$message\"" "\"$NTFY_TOPIC\"" || true
|
||||||
|
|
|
||||||
|
|
@ -167,11 +167,10 @@ mkdir -p skills/reminder/data && echo 'NTFY_TOPIC="https://ntfy.sh/USER_TOPIC"'
|
||||||
|
|
||||||
## ntfy Push Notification
|
## ntfy Push Notification
|
||||||
|
|
||||||
Gunakan helper script milik skill ini. **WAJIB source config sendiri sebelum panggil ntfy_send.sh**:
|
Script `ntfy_send.sh` otomatis membaca config dari `skills/reminder/data/ntfy.conf`. Cukup panggil langsung:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Semua perintah ntfy harus diawali source config
|
bash skills/reminder/scripts/ntfy_send.sh "MESSAGE" --title "JUDUL" --tags alarm_clock
|
||||||
source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash skills/reminder/scripts/ntfy_send.sh "MESSAGE" --title "JUDUL" --tags alarm_clock
|
|
||||||
```
|
```
|
||||||
|
|
||||||
> **JANGAN pakai curl langsung** ke ntfy. Selalu gunakan `ntfy_send.sh` agar URL dibaca dari config.
|
> **JANGAN pakai curl langsung** ke ntfy. Selalu gunakan `ntfy_send.sh` agar URL dibaca dari config.
|
||||||
|
|
@ -186,7 +185,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash
|
||||||
```
|
```
|
||||||
**Job 2 — ntfy push:**
|
**Job 2 — ntfy push:**
|
||||||
```json
|
```json
|
||||||
{"action": "add", "message": "ntfy: meeting", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Meeting dengan tim marketing!' --title Reminder --tags alarm_clock", "at_seconds": 600}
|
{"action": "add", "message": "ntfy: meeting", "command": "bash skills/reminder/scripts/ntfy_send.sh 'Meeting dengan tim marketing!' --title Reminder --tags alarm_clock", "at_seconds": 600}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Recurring reminder (2 jobs)
|
### Recurring reminder (2 jobs)
|
||||||
|
|
@ -197,7 +196,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash
|
||||||
```
|
```
|
||||||
**Job 2 — ntfy push:**
|
**Job 2 — ntfy push:**
|
||||||
```json
|
```json
|
||||||
{"action": "add", "message": "ntfy: minum air", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Jangan lupa minum air!' --title Hydration --tags droplet", "every_seconds": 3600}
|
{"action": "add", "message": "ntfy: minum air", "command": "bash skills/reminder/scripts/ntfy_send.sh 'Jangan lupa minum air!' --title Hydration --tags droplet", "every_seconds": 3600}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Daily cron reminder (2 jobs)
|
### Daily cron reminder (2 jobs)
|
||||||
|
|
@ -208,7 +207,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash
|
||||||
```
|
```
|
||||||
**Job 2 — ntfy push:**
|
**Job 2 — ntfy push:**
|
||||||
```json
|
```json
|
||||||
{"action": "add", "message": "ntfy: daily review", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Saatnya review laporan harian' --title 'Daily Review' --tags memo", "cron_expr": "0 17 * * 1-5"}
|
{"action": "add", "message": "ntfy: daily review", "command": "bash skills/reminder/scripts/ntfy_send.sh 'Saatnya review laporan harian' --title 'Daily Review' --tags memo", "cron_expr": "0 17 * * 1-5"}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Daily report via agent (1 job only, no ntfy)
|
### Daily report via agent (1 job only, no ntfy)
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,33 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# ntfy_send.sh — Stateless ntfy notification sender utility
|
# ntfy_send.sh — ntfy notification sender for reminder skill
|
||||||
# Does NOT manage its own config. Reads NTFY_TOPIC from environment variable.
|
# Auto-loads config from skills/reminder/data/ntfy.conf
|
||||||
# Each skill is responsible for setting NTFY_TOPIC from its own config.
|
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage (from workspace root):
|
||||||
# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message"
|
# bash skills/reminder/scripts/ntfy_send.sh "message"
|
||||||
# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message" --title "T" --tags "t" --priority "high"
|
# bash skills/reminder/scripts/ntfy_send.sh "message" --title "T" --tags "t" --priority "high"
|
||||||
#
|
#
|
||||||
# If NTFY_TOPIC is empty, silently skips (exit 0).
|
# If ntfy.conf is missing or NTFY_TOPIC is empty, silently exits (exit 0).
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ -z "${NTFY_TOPIC:-}" ]; then
|
# Auto-load config relative to this script
|
||||||
# No topic configured — skip silently so cron jobs don't fail
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
CONF_FILE="$SKILL_DIR/data/ntfy.conf"
|
||||||
|
|
||||||
|
# Source config if exists
|
||||||
|
NTFY_TOPIC=""
|
||||||
|
if [ -f "$CONF_FILE" ]; then
|
||||||
|
. "$CONF_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$NTFY_TOPIC" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
message="${1:-}"
|
message="$1"
|
||||||
if [ -z "$message" ]; then
|
if [ -z "$message" ]; then
|
||||||
echo "Usage: ntfy_send.sh \"message\" [--title T] [--tags T] [--priority P]"
|
echo "Usage: ntfy_send.sh message [--title T] [--tags T] [--priority P]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
|
|
@ -34,11 +43,16 @@ while [ $# -gt 0 ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Build curl args
|
# Send notification
|
||||||
curl_args=(-sf)
|
HEADERS=""
|
||||||
[ -n "$title" ] && curl_args+=(-H "Title: $title")
|
if [ -n "$title" ]; then
|
||||||
[ -n "$tags" ] && curl_args+=(-H "Tags: $tags")
|
HEADERS="$HEADERS -H \"Title: $title\""
|
||||||
[ -n "$priority" ] && curl_args+=(-H "Priority: $priority")
|
fi
|
||||||
curl_args+=(-d "$message" "$NTFY_TOPIC")
|
if [ -n "$tags" ]; then
|
||||||
|
HEADERS="$HEADERS -H \"Tags: $tags\""
|
||||||
|
fi
|
||||||
|
if [ -n "$priority" ]; then
|
||||||
|
HEADERS="$HEADERS -H \"Priority: $priority\""
|
||||||
|
fi
|
||||||
|
|
||||||
curl "${curl_args[@]}" > /dev/null 2>&1 || true
|
eval curl -sf $HEADERS -d "\"$message\"" "\"$NTFY_TOPIC\"" || true
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue