Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Export Password Store (aka pass) passwords to a KeePass compatible imports file.
- # Note: this does not respect the folder structure (yet). Also, multiline notes are not exported correctly.
- #
- # Author: Karolis Kazlauskis
- # 2017
- entries='' # pass entries found
- # loop through every file in the dir
- FILES=()
- while read file; do
- password=''
- login=''
- user=''
- url=''
- notes=''
- # clean up the file name
- file=$(sed 's/.gpg//g' <<< $file)
- file=$(sed 's/.*\.password-store\///g' <<< $file)
- # set title of the key
- title=$(sed 's/.*\///g' <<< $file)
- echo "\n $title ($file)"
- info=($(pass "$file"))
- echo "${info[@]}"
- # extract the parts of the key
- password=${info[@]:0:1}
- info=("${info[@]:1}")
- shopt -s nocasematch
- if [ "${info[0]}" == 'login:' ]; then
- login=${info[1]}
- elif [ "${info[0]}" == 'UserName:' ]; then
- user=${info[1]}
- elif [ "${info[0]}" == 'Notes:' ]; then
- notes=${info[1]}
- elif [ "${info[0]}" == 'url:' ] || [ "${info[0]}" == 'URL:' ]; then
- url=${info[1]}
- fi
- info=("${info[@]:1}")
- info=("${info[@]:1}")
- if [ "${info[0]}" == 'login:' ]; then
- login=${info[1]}
- elif [ "${info[0]}" == 'UserName:' ]; then
- user=${info[1]}
- elif [ "${info[0]}" == 'Notes:' ]; then
- notes=${info[1]}
- elif [ "${info[0]}" == 'url:' ] || [ "${info[0]}" == 'URL:' ]; then
- url=${info[1]}
- fi
- info=("${info[@]:1}")
- info=("${info[@]:1}")
- if [ "${info[0]}" == 'login:' ]; then
- login=${info[1]}
- elif [ "${info[0]}" == 'UserName:' ]; then
- user=${info[1]}
- elif [ "${info[0]}" == 'Notes:' ]; then
- notes=${info[1]}
- elif [ "${info[0]}" == 'url:' ] || [ "${info[0]}" == 'URL:' ]; then
- url=${info[1]}
- fi
- info=("${info[@]:1}")
- info=("${info[@]:1}")
- if [ "${info[0]}" == 'login:' ]; then
- login=${info[1]}
- elif [ "${info[0]}" == 'UserName:' ]; then
- user=${info[1]}
- elif [ "${info[0]}" == 'Notes:' ]; then
- notes=${info[1]}
- elif [ "${info[0]}" == 'url:' ] || [ "${info[0]}" == 'URL:' ]; then
- url=${info[1]}
- fi
- # escape xml
- password=$(sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' <<< ${password})
- login=$(sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' <<< ${login})
- user=$(sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' <<< ${user})
- url=$(sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' <<< ${url})
- notes=$(sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' <<< ${notes})
- # add to the entries
- entries+=$(cat << EndOfMessage
- <Entry>
- <UUID>$(uuidgen)</UUID>
- <String>
- <Key>Title</Key>
- <Value>${title}</Value>
- </String>
- <String>
- <Key>UserName</Key>
- <Value>${user}</Value>
- </String>
- <String>
- <Key>Password</Key>
- <Value ProtectInMemory="True">${password}</Value>
- </String>
- <String>
- <Key>URL</Key>
- <Value>${url}</Value>
- </String>
- <String>
- <Key>Notes</Key>
- <Value>${notes}</Value>
- </String>
- </Entry>
- EndOfMessage
- )
- done <<< "$(find ~/.password-store/ -name '*.gpg' )"
- # write it to the file
- cat > exports.xml << EndOfMessage
- <?xml version="1.0" encoding="UTF-8"?>
- <KeePassFile>
- <Meta>
- <DatabaseName>Database</DatabaseName>
- </Meta>
- <Root>
- <Group>
- <UUID>$(uuidgen)</UUID>
- <Name>Imports</Name>
- ${entries}
- </Group>
- </Root>
- </KeePassFile>
- EndOfMessage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement