diff --git a/cntfy.nu b/cntfy.nu index eb9f5a4..f820a53 100755 --- a/cntfy.nu +++ b/cntfy.nu @@ -33,7 +33,7 @@ def subcommands [] { # Publishes a message export def `main publish` [ topic: string - message: string + body: any --title: string --priority: string --tags: string @@ -45,7 +45,7 @@ export def `main publish` [ ) let cfg = ( get_config ) - http post -u $cfg.username -p $cfg.password -H $headers ( build_url $topic ) $message + http put -u $cfg.username -p $cfg.password -H $headers ( build_url $topic ) $body } def get_config [] { diff --git a/pacman-update-check.nu b/pacman-update-check.nu new file mode 100755 index 0000000..8e126bf --- /dev/null +++ b/pacman-update-check.nu @@ -0,0 +1,40 @@ +#!/bin/env nu + +use cntfy.nu + +# Checks for package updates +def main [ + --ntfy: bool +] { + if is-admin == false { + let span = (metadata main).span; + err make { + msg: "This script needs to be run as root" + label: { + text: "Run as root" + start: $label.start + end: $label.end + } + } + } + let updates = ( checkupdates | split row "\n" ) + let update_count = ( $updates | length ) + + if $update_count > 0 { + echo $"($update_count) package[s] need to be updated" + + if $ntfy { + mut update_msg = ""; + + if $update_count > 20 { + $update_msg = ( $updates + | first 19 + | append $"... And ($update_count - 19) more" + | str join "\n" ) + } else { + $update_msg = ( $updates | str join "\n" ) + } + cntfy main publish --title $"($update_count) package[s] need to be updated" updates $update_msg + } + } +} \ No newline at end of file