Homey alert!
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
{...}: {
|
||||||
|
config.flake.modules.homeManager.homey-alert = {
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
options.azos.homey-alert.enable = lib.mkOption {
|
||||||
|
default = false;
|
||||||
|
example = true;
|
||||||
|
type = lib.types.bool;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf config.azos.homey-alert.enable {
|
||||||
|
home.packages = [
|
||||||
|
(pkgs.writeShellApplication {
|
||||||
|
name = "homey-alert";
|
||||||
|
runtimeInputs = with pkgs; [curl pass];
|
||||||
|
text = ''
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: homey-alert [OPTIONS] [MESSAGE]
|
||||||
|
|
||||||
|
Send a notification to the homey ntfy server (ntfy.zakobar.com/alerts).
|
||||||
|
MESSAGE can be given as a positional argument or piped via stdin.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-t, --title TITLE notification title
|
||||||
|
-p, --priority PRIO priority: min|low|default|high|urgent (default: default)
|
||||||
|
-T, --tags TAGS comma-separated emoji shortcodes (e.g. warning,rotating_light)
|
||||||
|
-h, --help show this help
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
homey-alert "Backup complete"
|
||||||
|
homey-alert -t "Backup" -p high -T white_check_mark "restic finished"
|
||||||
|
echo "done" | homey-alert -t "Job finished"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
TITLE=""
|
||||||
|
PRIORITY="default"
|
||||||
|
TAGS=""
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-t|--title) TITLE="$2"; shift 2 ;;
|
||||||
|
-p|--priority) PRIORITY="$2"; shift 2 ;;
|
||||||
|
-T|--tags) TAGS="$2"; shift 2 ;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
--) shift; break ;;
|
||||||
|
-*) echo "Unknown option: $1" >&2; usage >&2; exit 1 ;;
|
||||||
|
*) break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
MESSAGE="$*"
|
||||||
|
elif [[ ! -t 0 ]]; then
|
||||||
|
MESSAGE="$(cat)"
|
||||||
|
else
|
||||||
|
echo "homey-alert: no message provided" >&2
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TOKEN="$(pass zakobar-homecenter/ntfy-token)"
|
||||||
|
|
||||||
|
HEADERS=(
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
-H "Priority: $PRIORITY"
|
||||||
|
)
|
||||||
|
|
||||||
|
[[ -n "$TITLE" ]] && HEADERS+=(-H "Title: $TITLE")
|
||||||
|
[[ -n "$TAGS" ]] && HEADERS+=(-H "Tags: $TAGS")
|
||||||
|
|
||||||
|
curl -sf "''${HEADERS[@]}" \
|
||||||
|
-d "$MESSAGE" \
|
||||||
|
https://ntfy.zakobar.com/alerts
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
suiteModules.homeManager.roam-backup
|
suiteModules.homeManager.roam-backup
|
||||||
suiteModules.homeManager.ytdl
|
suiteModules.homeManager.ytdl
|
||||||
suiteModules.homeManager.chess
|
suiteModules.homeManager.chess
|
||||||
|
suiteModules.homeManager.homey-alert
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.home-manager.enable = true;
|
programs.home-manager.enable = true;
|
||||||
@@ -59,6 +60,7 @@
|
|||||||
|
|
||||||
];
|
];
|
||||||
azos.roam-backup.enable = true;
|
azos.roam-backup.enable = true;
|
||||||
|
azos.homey-alert.enable = true;
|
||||||
|
|
||||||
home = {
|
home = {
|
||||||
username = "aner";
|
username = "aner";
|
||||||
|
|||||||
Reference in New Issue
Block a user