get-op-login 897 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env nix-shell
  2. #!nix-shell -p expect -i "expect -f"
  3. log_user 0
  4. set db_path "$::env(KEEPASS_FILE)"
  5. set db_entry "$::env(KEEPASS_OP_ENTRY)"
  6. stty -echo
  7. puts -nonewline stderr "Enter Password: "
  8. expect_user -re "(.*)\n"
  9. puts stderr ""
  10. stty echo
  11. set PASS $expect_out(1,string)
  12. set op_url [exec keepassxc-cli show -q $db_path "$db_entry" -a URL << $PASS]
  13. set op_username [exec keepassxc-cli show -q $db_path "$db_entry" -a UserName << $PASS]
  14. set op_password [exec keepassxc-cli show -q $db_path "$db_entry" -a Password << $PASS]
  15. set op_secretkey [exec keepassxc-cli show -q $db_path "$db_entry" -a "Secret Key" << $PASS]
  16. spawn op signin $op_url $op_username $op_secretkey
  17. expect "Enter the password for $op_username at $op_url:"
  18. expect -re $
  19. send "$op_password\r"
  20. expect eof
  21. set session $expect_out(buffer)
  22. log_user 1
  23. regsub -all {\r} $session {} stripped_session
  24. puts $stripped_session