summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2024-07-25 22:04:33 -0600
committerAlejandro Soto <alejandro@34project.org>2024-07-25 22:04:33 -0600
commit277e0c36a00e018a0090a984af934165be704aaa (patch)
tree5294d4cb7d044f95363fd9e57ec21317a37a1052
parent159da68b0a68d36fd07bdf833ab604711aebfef5 (diff)
home/pass: implement pass-bcr
Diffstat (limited to '')
-rw-r--r--home/pass.nix4
-rw-r--r--pkgs/default.nix1
-rwxr-xr-xpkgs/pass-bcr/bcr.bash25
-rw-r--r--pkgs/pass-bcr/completions/bash8
-rw-r--r--pkgs/pass-bcr/completions/zsh8
-rw-r--r--pkgs/pass-bcr/default.nix19
6 files changed, 64 insertions, 1 deletions
diff --git a/home/pass.nix b/home/pass.nix
index 54b3ff6..cc05869 100644
--- a/home/pass.nix
+++ b/home/pass.nix
@@ -2,12 +2,14 @@
with lib; {
config.programs.password-store = mkIf (!config.home.isolation.active) {
enable = true;
- package = pkgs.pass.withExtensions (exts: with exts; [
+ package = pkgs.pass.withExtensions (exts: (with exts; [
pass-audit
pass-genphrase
pass-otp
pass-tomb
pass-update
+ ]) ++ [
+ pkgs.local.pass-bcr
]);
settings = {
diff --git a/pkgs/default.nix b/pkgs/default.nix
index fa1a0e0..1c3bac2 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -9,6 +9,7 @@ in
kbuild-standalone = callPackage ./kbuild-standalone.nix { };
mssql-tools = callPackage ./mssql-tools.nix { };
oregano = callPackage ./oregano { };
+ pass-bcr = callPackage ./pass-bcr { };
rqlite = callPackage ./rqlite.nix { };
rv8 = callPackage ./rv8.nix { };
scripts = callPackage ./scripts { };
diff --git a/pkgs/pass-bcr/bcr.bash b/pkgs/pass-bcr/bcr.bash
new file mode 100755
index 0000000..5d02748
--- /dev/null
+++ b/pkgs/pass-bcr/bcr.bash
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+set -e
+set -o pipefail
+
+if [ $# -eq 0 ]; then
+ echo "Usage: $0 <challenge>..." >&2
+ exit 1
+fi
+
+function index_for_each() {
+ keys="$1"
+ shift
+
+ for entry in "$@"; do
+ if echo "$entry" | grep -vq "^[a-jA-J][1-5]$"; then
+ echo "Bad challenge: $entry" >&2
+ exit 1
+ fi
+
+ echo "$entry: $(echo "$keys" | tail -n+$(echo "$entry" | tail -c+2) | head -1 | cut -d' ' -f$((1 + $(echo "$entry" | head -c1 | tr 'a-jA-J' '0-90-9'))))"
+ done
+}
+
+index_for_each "$(pass show any/bank/bcr/default | grep -A6 '^Clave dinĂ¡mica:$' | tail -5 | sed 's/^[0-9]\s\+//g')" "$@"
diff --git a/pkgs/pass-bcr/completions/bash b/pkgs/pass-bcr/completions/bash
new file mode 100644
index 0000000..8fe1887
--- /dev/null
+++ b/pkgs/pass-bcr/completions/bash
@@ -0,0 +1,8 @@
+# pass-update completion file for bash
+
+PASSWORD_STORE_EXTENSION_COMMANDS+=(bcr)
+
+__password_store_extension_complete_bcr() {
+ local args=()
+ COMPREPLY+=($(compgen -W "${args[*]}" -- ${cur}))
+}
diff --git a/pkgs/pass-bcr/completions/zsh b/pkgs/pass-bcr/completions/zsh
new file mode 100644
index 0000000..9d120a5
--- /dev/null
+++ b/pkgs/pass-bcr/completions/zsh
@@ -0,0 +1,8 @@
+#compdef pass-bcr
+#description Clave dinĂ¡mica BCR
+
+_pass-ubcr () {
+ _arguments :
+}
+
+_pass-bcr "$@"
diff --git a/pkgs/pass-bcr/default.nix b/pkgs/pass-bcr/default.nix
new file mode 100644
index 0000000..6db814c
--- /dev/null
+++ b/pkgs/pass-bcr/default.nix
@@ -0,0 +1,19 @@
+{ stdenv, ... }:
+stdenv.mkDerivation {
+ pname = "pass-bcr";
+ version = "1.0";
+
+ src = ./.;
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out/{lib/password-store/extensions,share/{bash-completion/completions,zsh/site-functions}}
+ cp bcr.bash $out/lib/password-store/extensions
+ cp completions/zsh $out/share/zsh/site-functions/_pass-bcr
+ cp completions/bash $out/share/bash-completion/completions/pass-bcr
+ chmod +x $out/lib/password-store/extensions/bcr.bash
+
+ runHook postInstall
+ '';
+}