Guest User

Untitled

a guest
May 18th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. insert () {
  4. echo -e "$2" | pass insert --multiline -f "${1}" > /dev/null
  5. }
  6.  
  7. sanitize () {
  8. local res=$(echo "$1" | tr -d \'\"\!\(\))
  9. echo "$res"
  10. }
  11.  
  12. parse_line () {
  13. IFS=',' read -r -a fields <<< "$1"
  14.  
  15. if [ "uuid" != "${fields[0]}" ]; then
  16. group="$(sanitize "${fields[1]}")"
  17. title="$(sanitize "${fields[2]}")"
  18. url="$(sanitize "${fields[3]}")"
  19. user="$(sanitize "${fields[4]}")"
  20. password="$(sanitize "${fields[5]}")"
  21. notes="$(sanitize "${fields[6]}")"
  22. for (( i = 7; i<=${#fields[@]}; i+=1 )); do
  23. notes="$notes "$(sanitize "${fields[i]}")""
  24. done
  25. notes=$(echo $notes | sed -e 's/^[[:space:]]*//')
  26. prefix="$group/$title"
  27.  
  28. if [ ${#user} -gt 0 ]; then
  29. insert "$prefix/user" "$user"
  30. fi
  31.  
  32. if [ ${#url} -gt 0 ]; then
  33. insert "$prefix/url" "$url"
  34. fi
  35.  
  36. if [ ${#password} -gt 0 ]; then
  37. insert "$prefix/password" "$password"
  38. fi
  39.  
  40. if [ ${#notes} -gt 3 ]; then
  41. insert "$prefix/notes" "$notes"
  42. fi
  43.  
  44. fi
  45. }
  46.  
  47. while read line
  48. do
  49. parse_line "$line"
  50. done < "${1:-/dev/stdin}"
Add Comment
Please, Sign In to add comment