Skip to content

Instantly share code, notes, and snippets.

@amir
Last active May 15, 2018 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amir/15f274afd1a71e2524dd3d10a53b685a to your computer and use it in GitHub Desktop.
Save amir/15f274afd1a71e2524dd3d10a53b685a to your computer and use it in GitHub Desktop.
Bash script for importing Gorilla passwords into pass
#!/usr/bin/env bash
insert () {
echo -e "$2" | pass insert --multiline -f "${1}" > /dev/null
}
sanitize () {
local res=$(echo "$1" | tr -d \'\"\!\(\))
echo "$res"
}
parse_line () {
IFS=',' read -r -a fields <<< "$1"
if [ "uuid" != "${fields[0]}" ]; then
group="$(sanitize "${fields[1]}")"
title="$(sanitize "${fields[2]}")"
url="$(sanitize "${fields[3]}")"
user="$(sanitize "${fields[4]}")"
password="$(sanitize "${fields[5]}")"
notes="$(sanitize "${fields[6]}")"
for (( i = 7; i<=${#fields[@]}; i+=1 )); do
notes="$notes "$(sanitize "${fields[i]}")""
done
notes=$(echo $notes | sed -e 's/^[[:space:]]*//')
prefix="$group/$title"
if [ ${#user} -gt 0 ]; then
insert "$prefix/user" "$user"
fi
if [ ${#url} -gt 0 ]; then
insert "$prefix/url" "$url"
fi
if [ ${#password} -gt 0 ]; then
insert "$prefix/password" "$password"
fi
if [ ${#notes} -gt 3 ]; then
insert "$prefix/notes" "$notes"
fi
fi
}
while read line
do
parse_line "$line"
done < "${1:-/dev/stdin}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment