citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

commit c7b2641c8b205c2ae3d803e36681aa673d83c6f6
parent bc3ccbd77bdf58060ddf6989d3900db575d89db6
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 21 Nov 2021 13:28:50 -0800

bins

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Abin/b4-am-mbox | 7+++++++
Abin/blocksubmit | 10++++++++++
Abin/btc-fees | 2++
Abin/btc-sendblocks | 19+++++++++++++++++++
Abin/btc-submitblocks | 29+++++++++++++++++++++++++++++
Abin/email-conn-test-fail | 2++
Abin/fuzz-btc-txs | 4++++
Abin/fuzz-notmuch-query-i | 4++++
Abin/git-children-of | 10++++++++++
Mbin/lock | 2+-
Mbin/memstat | 2+-
Abin/nncp-cmd-handler | 7+++++++
Abin/nncp-cmd-runner | 13+++++++++++++
Abin/open-pr | 4++++
Abin/quiver-file | 3+++
Abin/reply-github-pr | 30++++++++++++++++++++++++++++++
Mbin/sedcut | 2+-
Mbin/spotify-service | 2+-
Abin/srht-am | 3+++
Abin/tv | 2++
Abin/view-pr | 3+++
Abin/visual-curl | 6++++++
Abin/walletemail | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 files changed, 216 insertions(+), 4 deletions(-)

diff --git a/bin/b4-am-mbox b/bin/b4-am-mbox @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +mbox=$(mktemp) +curl -sL "$1" > "$mbox" +msgid=$(grep -i ^message-id "$mbox" | head -n1 | sed -E -n 's,.*<([^>]+)>.*,\1,p') +b4 am "$msgid" -m "$mbox" +rm -f "$mbox" diff --git a/bin/blocksubmit b/bin/blocksubmit @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -eou pipefail + +. /home/jb55/.nncpenv + +res=$(xxd -p | tr -d '\n' > /tmp/blocks/$1) + +#if [ $res == "prev-blk-not-found" ]; then +# exit 42 +#fi diff --git a/bin/btc-fees b/bin/btc-fees @@ -0,0 +1 @@ +/home/jb55/src/bash/bitcoin-fees/bitcoin-fees+ \ No newline at end of file diff --git a/bin/btc-sendblocks b/bin/btc-sendblocks @@ -0,0 +1,19 @@ +#/usr/bin/env bash + +HEIGHT=${1:-708720} +DST=${2:-quiver} + +set -eou pipefail + +if [ -z $1 ] +then + printf "usage: btc-sendblocks <from-height> <DSTNODE>\n" + exit 0 +fi + +for i in $(seq $HEIGHT $(btc blocks)) +do + bcli getblock $(bcli getblockhash $i) 0 | + xxd -r -p | + nncp-exec "$DST" block $i +done diff --git a/bin/btc-submitblocks b/bin/btc-submitblocks @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -eou pipefail + +mkdir -p /tmp/blocks + +nncp-toss + +blocks=$(bcli getblockcount) + +cd /tmp/blocks +for block in $(ls -1 | sort -n) +do + printf "submitting block $block ... " >&2 + + res=$(<$block bcli -stdin submitblock) + + printf "$res\n" >&2 + + if [ "$res" = "prev-blk-not-found" ]; then + exit 42 + fi +done + +blocks2=$(bcli getblockcount) + +printf "%d to height %d, processed %d blocks\n" $blocks $blocks2 $(bc <<<"$blocks2 - $blocks") + +rm -rf /tmp/blocks/* diff --git a/bin/email-conn-test-fail b/bin/email-conn-test-fail @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exit 1 diff --git a/bin/fuzz-btc-txs b/bin/fuzz-btc-txs @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +last2=$(btc-txs | fzf --tac | awk '{print $(NF-1), $NF}') + +echo tx $last2 diff --git a/bin/fuzz-notmuch-query-i b/bin/fuzz-notmuch-query-i @@ -0,0 +1,4 @@ + +#!/usr/bin/env bash +export FUZZ_QUERY="$@" +exec fuzz-notmuch-query diff --git a/bin/git-children-of b/bin/git-children-of @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# given a commit, find immediate children of that commit. + +for arg in "$@"; do +for commit in $(git rev-parse $arg^0); do +for child in $(git log --format='%H %P' --all | grep -F " $commit" | cut -f1 -d' '); do + echo $child +done +done +done diff --git a/bin/lock b/bin/lock @@ -1,6 +1,6 @@ #!/usr/bin/env bash -lockmac & +#lockmac & slock & diff --git a/bin/memstat b/bin/memstat @@ -1,6 +1,6 @@ #!/usr/bin/env bash printf "hogs\n\n" -procmem | tail -n10 | nfmt +procmem | tail -n20 | nfmt all=$(procmemall) arc=$(arcsize) total=$(($all + $arc)) diff --git a/bin/nncp-cmd-handler b/bin/nncp-cmd-handler @@ -0,0 +1,7 @@ +#!/bin/sh + +export NNCPCFG=/home/jb55/.nncprc +export HOME=/home/jb55 +export PATH=/home/jb55/.npm/bin:/home/jb55/.local/bin:/home/jb55/bin:/run/wrappers/bin:/home/jb55/.nix-profile/bin:/etc/profiles/per-user/jb55/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/home/jb55/.fzf/bin:/nix/store/qi3kpll3n9k9cjr5l8yyn5h3ydazl612-neovim-ruby-env/bin + +nohup nncp-cmd-runner "$@" diff --git a/bin/nncp-cmd-runner b/bin/nncp-cmd-runner @@ -0,0 +1,13 @@ +#!/bin/sh + +. /home/jb55/.nncpenv + +out=$(mktemp) +echo "$@" >> /tmp/cmds +$@ &> "$out" + +<"$out" nncp-exec $NNCP_SENDER cat $@ + +echo "finished nncp-cmd $@" | sendalert + +rm -f "$out" diff --git a/bin/open-pr b/bin/open-pr @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +repo=$(git remote -v | grep origin | sedcut ':([^/]+/[^ ]+)' | head -n1) +open "https://github.com/$repo/pull/$1" diff --git a/bin/quiver-file b/bin/quiver-file @@ -0,0 +1,3 @@ +#!/bin/sh + +nncp-file "$1" quiver: diff --git a/bin/reply-github-pr b/bin/reply-github-pr @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -eou pipefail + +tmp=$(mktemp) +reply="$(mktemp).eml" + +function cleanup() { + rm -f "$tmp" +} + +trap cleanup EXIT + +cat > "$tmp" + +replyto=$(grep -i ^reply-to "$tmp" | head -n1 | sed -E -n 's,^reply-to: (.*)$,\1,pI') +printf "reply-to %s\n" "$replyto" >&2 +link=$(<"$tmp" sed -E -n 's,.*(https://github.com/[^/]+/[^/]+/pull/[0-9]+).*,\1.patch,p' | head -n1 | grep .) + +printf "fetching patch %s\n" "$link" >&2 +curl -sL "$link" | notmuch insert +insertedreply + +id=$(notmuch search --output=messages tag:insertedreply | head -n1 | grep .) + +notmuch reply "$id" | sed "/^To:/a Cc: $replyto" > "$reply" +notmuch search --output=files "$id" | xargs rm -f +notmuch new &>/dev/null + +$EDITOR "$reply" +printf "%s\n" "$reply" diff --git a/bin/sedcut b/bin/sedcut @@ -1,2 +1,2 @@ #!/bin/sh -exec sed -n 's,.*'"$1"'.*,\1,p' +exec sed -E -n 's,.*'"$1"'.*,\1,p' diff --git a/bin/spotify-service b/bin/spotify-service @@ -1,6 +1,6 @@ #!/usr/bin/env bash options=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames \ | grep spotify \ - | sedcut '"\([^"]\+\)"') + | sedcut '"([^"]+)"') grep 'spotify$' <<<"$options" || grep -v 'spotify$' <<<"$options" diff --git a/bin/srht-am b/bin/srht-am @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + + diff --git a/bin/tv b/bin/tv @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +xset -display :0 dpms force "$1" diff --git a/bin/view-pr b/bin/view-pr @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +gh pr view --comments "$1" diff --git a/bin/visual-curl b/bin/visual-curl @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +tmpfile=$(mktemp) +curl -sL "$@" > "$tmpfile" +urxvtc -e less $tmpfile +rm -f "$tmpfile" diff --git a/bin/walletemail b/bin/walletemail @@ -0,0 +1,54 @@ +#!${pkgs.bash}/bin/bash + +set -e + +txid="$1" +wallet="$2" + +from="Bitcoin Wallet <bitcoind@monad>" +to="William Casarin <jb55@jb55.com>" +subject="Wallet notification" +keys="-r 0x8860420C3C135662EABEADF96342E010C44A6337 -r 0x5B2B1E4F62216BC74362AC61D4FBA2FC4535A2A9 -r 0xE02D3FD4EB4585A63531C1D0E1BFCB90A1FF7A1C" + +tx="$(bitcoin-cli -rpcwallet=$wallet gettransaction "$txid" true)" +address="$(jq -r '.details[0].address' <<<"$tx")" +details="$(jq -r '.details[] | [.address, .category, .amount, .label] | @csv' <<<"$tx")" +keypath="$(bitcoin-cli -rpcwallet=$wallet getaddressinfo "$address" | jq -r .hdkeypath)" + +amount="$(jq -r '.amount' <<<"$tx")" +confs="$(jq -r '.confirmations' <<<"$tx")" + +time="$(date -d @$(jq -r '.time' <<<"$tx"))" +received="$(date -d @$(jq -r '.timereceived' <<<"$tx"))" + +export GNUPGHOME=/zbig/bitcoin/gpg + +msg="$(printf "txid: %s\n\naddress: %s\n\namount: %s\n\nconfirmations: %d\n\nwallet: %s\n\ntime: %s\n\nreceived: %s\n\nkeypath: %s\n\n%s\n\n\n%s" \ + "$txid" "$address" "$amount" "$confs" "$wallet" "$time" "$received" "$keypath" "$details" "$tx" )" + +enctx="$(printf "Content-Type: text/plain\n\n%s\n" "$msg" | gpg --yes --always-trust --encrypt --armor $keys)" + +{ +cat <<EOF +From: $from +To: $to +Subject: $subject +MIME-Version: 1.0 +Content-Type: multipart/encrypted; boundary="=-=-="; + protocol="application/pgp-encrypted" + +--=-=-= +Content-Type: application/pgp-encrypted + +Version: 1 + +--=-=-= +Content-Type: application/octet-stream + +$enctx +--=-=-=-- +EOF +} | sendmail -oi -t + +printf "sent walletnotify email for %s\n" "$txid" +''