Guest User

Untitled

a guest
Nov 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. function pass_to_bitwarden(){
  3. local path_to_pass="$1"
  4. local output_path="$2"
  5. #echo "searching path $path_to_pass for simple logins"
  6. local url
  7. local username
  8. local decrypted_stuff
  9. local password
  10. local notes
  11. #echo "Initialized the csv file header for bitwarden (individual account)."
  12. echo "folder,favorite,type,name,notes,fields,login_uri,login_username,login_password,login_totp" > "$output_path"
  13. for folder in "${path_to_pass%/}"/*; do
  14. if [ -d "$folder" ]; then
  15. #echo "found potential match for url: $folder"
  16. url="$(basename "$folder")"
  17. # best URL regex, I know...
  18. # comment this if-statement out, if you don´t name your folders after domains. the 'login_url' will still be set though...
  19. if [[ "$url" == *"."* ]]; then
  20. for file in "${folder%/}"/*; do
  21. #echo "found potential match for username: $file"
  22. username="$(basename --suffix ".gpg" "$file")"
  23. if [ -f "$file" ] ; then
  24. decrypted_stuff="$(pass "$url"/"$username" 2> /dev/null)"
  25. password="$(echo "$decrypted_stuff" | head -n +1)"
  26. notes="$(echo "$decrypted_stuff" | tail -n +2)"
  27. #echo "the AI has deterimed, that;"
  28. #echo "URL: $url"
  29. #echo "Username: $username"
  30. #echo "Notes: $notes"
  31. #echo "Password is BEEEEEEP!"
  32. #echo
  33. echo "passwordstore,0,login,$url,\"$notes\",,$url,$username,\"$password\"," >> "$output_path"
  34. mkdir -p "${path_to_pass%/}"/Archive
  35. pass mv "$url"/"$username" Archive/"$url"/"$username"
  36. fi
  37. done
  38. fi
  39. fi
  40. done
  41. }
  42. if [ -z "${1// }" ] || [ -z "${2// }" ]; then
  43. echo "Converts simple pass files to bitwarden(csv)."
  44. echo "Usage: pass_to_bitwarden <path to password store> <path to csv output>"
  45. exit -1
  46. fi
  47. # This script will scan the given path for password store logins in a simple format, and in this format only!
  48. # Simple logins are assumed to be '<directory>/<file>' with the file content being lines of text.
  49. # The directory name will be used as the 'login_uri', the file name as the 'login_username' and the first line of text as 'login_password'.
  50. # Additional lines of text will be stored as 'notes'.
  51. # Logins that do not fit this scheme will be ignored. Those that fit will be printed in CSV format that bitwarden understands.
  52. # Additionally, those logins that fit will be moved to an 'Archive' folder within pass, in order to ease migrating the rest of the logins manually.
  53. pass_to_bitwarden "$1" "$2"
Add Comment
Please, Sign In to add comment