From 73af89d935df5a8166114c9257f9f247f29850bf Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Fri, 26 Apr 2024 18:21:56 +0200 Subject: Migrate from stumpwm to sway and from manifests to home-services. --- .bin/chiaki | 21 ++++++++++++++ .bin/oath | 14 ++++++++++ .bin/whois-at-hsp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100755 .bin/chiaki create mode 100755 .bin/oath create mode 100755 .bin/whois-at-hsp (limited to '.bin') diff --git a/.bin/chiaki b/.bin/chiaki new file mode 100755 index 0000000..5fa6547 --- /dev/null +++ b/.bin/chiaki @@ -0,0 +1,21 @@ +#!/bin/sh + +CHIAKI_SHELL=/tmp/.chiaki.nix + +cat < $CHIAKI_SHELL +let + nixgl = import (fetchTarball https://github.com/guibou/nixGL/archive/main.tar.gz) { }; +in +{ nixpkgs ? import {} }: +with nixpkgs; mkShell { + buildInputs = [ + chiaki + nixgl.auto.nixGLDefault + ]; + shellHook = '' + nixGL chiaki && exit; + ''; +} +EOF + +nix-shell $CHIAKI_SHELL diff --git a/.bin/oath b/.bin/oath new file mode 100755 index 0000000..7444993 --- /dev/null +++ b/.bin/oath @@ -0,0 +1,14 @@ +#!/bin/sh + +if [[ $1 ]]; then + PASS=$(oathtool -b --totp $(pass show "oath/$1")) + printf $PASS | wl-copy + echo "pass: $PASS" + echo "Password should be in your clipboard!" +else + echo "Usage: oath " + echo "Available pass:" + pass oath +fi + + diff --git a/.bin/whois-at-hsp b/.bin/whois-at-hsp new file mode 100755 index 0000000..0cd03f7 --- /dev/null +++ b/.bin/whois-at-hsp @@ -0,0 +1,84 @@ +#!/usr/bin/env -S guix shell guile guile-json -- guile --no-auto-compile -e main -s +-*- scheme -*- +!# + +(use-modules (srfi srfi-1) + (ice-9 iconv) + (ice-9 receive) + (web client) + (json)) + +(define whois-at-hsp-endpoint "https://whois.at.hsp.sh/api/now") + +(define (http-get-serialize-json url) + (receive (response data) (http-request url) + (values (json-string->scm (bytevector->string data "UTF-8")) + response))) + +(define (whois-data->users whois-data) + (assoc-ref whois-data "users")) + +(define (whois-data->unknown-devices whois-data) + (assoc-ref whois-data "unknown_devices")) + +(define (whois-data->head-count whois-data) + (assoc-ref whois-data "headcount")) + +(define (whois-data->formated-users whois-data) + (let ((users (vector->list (whois-data->users whois-data)))) + (if (> (length users) 0) + (fold-right + (lambda (a b) (string-append a " " b)) + "" + users) + "No visible users!"))) + +(define (whois-data->summary whois-data) + (string-append + "Unknown devices: " + (number->string (whois-data->unknown-devices whois-data)) + "\nUsers: [" (number->string (whois-data->head-count whois-data)) "] " + (whois-data->formated-users whois-data))) + +(define (notify data) + (system* "notify-send" + "WHOIS AT HSP" + (whois-data->summary data))) + +(define (command-line-option? option args) + (> (length (or (member option args) + '())) + 0)) + +(define-syntax-rule (command-line-args-handle args default ((option ...) body ...) ...) + (let ((option? (lambda (o) (command-line-option? o args))) + (something-executed? #f)) + (when (or (option? option) ...) + (set! something-executed? #t) + body ...) ... + (when (not something-executed?) + default))) + +(define (main args) + (let ((whois-data (http-get-serialize-json whois-at-hsp-endpoint))) + (command-line-args-handle args + (begin (display (whois-data->summary whois-data)) + (newline)) + (("-h" "--help") + (display (string-append "-h, --help Help message\n" + "-n, --notify Notification massage with whois information.\n" + "-u Get users\n" + "-H Get head count\n" + "-U Get unknown devices\n"))) + (("-n" "--notify") + (notify whois-data)) + (("-u") + (display (whois-data->formated-users whois-data)) + (newline)) + (("-H") + (display (whois-data->head-count whois-data)) + (newline)) + (("-U") + (display (whois-data->unknown-devices whois-data)) + (newline))))) + -- cgit v1.2.3