Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.6 KiB

  1. #!/bin/sh
  2. skey="$(bw unlock --raw)"
  3. export BW_SESSION="$skey"
  4. data="$(bw list items | jq -r -M \
  5. '.[]| select( .type | contains(1)) |.name,.folderId,(.login|.username,.password,.totp,(.uris|.[0]|.uri))')"
  6. echo "Fetched passwords from bitwarden."
  7. uri=""
  8. password=""
  9. name=""
  10. username=""
  11. totp=""
  12. fid=""
  13. echo "Cleaning previuos store"
  14. prev=$(pwd)
  15. cd $PASSWORD_STORE_DIR
  16. for f in *; do
  17. pass rm -rf "$f"
  18. done
  19. cd $prev
  20. strip_domain(){
  21. if [ "$1" = "null" ]; then
  22. echo "null"
  23. return 0
  24. fi
  25. echo "$1" | head -n 1 | sed 's~http[s]*://~~g' | cut -d"/" -f 1
  26. }
  27. get_folder(){
  28. if [ "$1" = "null" ]; then
  29. echo "No Folder"
  30. return 0
  31. fi
  32. bw get folder "$1" | jq -r -M ".name"
  33. }
  34. IFS="
  35. "
  36. for l in $data; do
  37. if [ "$name" = "" ]; then
  38. name=$l
  39. echo "$name"
  40. elif [ "$fid" = "" ]; then
  41. fid=$l
  42. elif [ "$username" = "" ]; then
  43. username=$l
  44. elif [ "$password" = "" ]; then
  45. password=$l
  46. elif [ "$totp" = "" ]; then
  47. totp=$l
  48. elif [ "$uri" = "" ]; then
  49. uri=$(strip_domain $l)
  50. folder=$(get_folder $fid)
  51. if [ "$uri" = "null" ]; then
  52. echo "$password" | pass insert -f -e "$folder/$name/$username" 2> /dev/null > /dev/null
  53. if [ ! "$totp" = "null" ]; then
  54. echo "$totp" | pass otp append -f -e "$folder/$name/$username" > /dev/null 2> /dev/null
  55. fi
  56. else
  57. echo "$password" | pass insert -f -e "$folder/$uri/$username" 2> /dev/null > /dev/null
  58. if [ ! "$totp" = "null" ]; then
  59. echo "$totp" | pass otp append -f -e "$folder/$uri/$username" > /dev/null 2> /dev/null
  60. fi
  61. fi
  62. uri=""
  63. fid=""
  64. password=""
  65. name=""
  66. username=""
  67. totp=""
  68. fi
  69. done