-
Notifications
You must be signed in to change notification settings - Fork 2
/
gorilla2pass.sh
executable file
·56 lines (49 loc) · 1.95 KB
/
gorilla2pass.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# Copyright (C) 2015 <pcre@gmx.de>. All Rights Reserved.
# This file is licensed under the GPLv3+. Please see LICENSE for more information.
gorillacontainer="$1"
#User is used as leaf containing the password
leafUser="TRUE"
#Append URL to multiline password (Debian universe only)
multilineURL="FALSE"
#Append notes to multiline password
multilineNOTES="TRUE"
#Add an own entry url
entryURL="FALSE"
### Test the password gorilla export file ###
# Password gorilla maintained by debian adds a header to the export file,
# because it also supports an import function. see (pass2gorilla).
# It also includes the url.
# There are two version of password gorilla export files:
# The debian universe and the rest of the unix universe.
yes="1!p"
no="p"
debianreg="uuid,group,title,url,user,password"
debian="uuid group title url user password notes"
rest="uuid group title user password notes"
#By default assume non Debian export file. Do not snip away the header.
snip="$no";
parse="$rest";
#Detect if debian header is set.
if egrep -q "$debianreg" <<< head -n1 "$gorillacontainer"; then
snip="$yes";
parse="$debian";
fi
### end of test ###
cat "$gorillacontainer" | sed -n "$snip" | while IFS="," read -r $parse; do
group="$(sed -e 's/\\\./#/g' -e 's/\./\//g' -e 's/#/./g' <<< "$group")"
title="$(sed -s 's/\s\{1,\}/_/g' <<< "$title")"
if [[ $url != "" && $multilineURL == "TRUE" ]]; then password="$password\n$url"; fi
if [[ $notes != "" && $multilineNOTES == "TRUE" ]]; then password="$password\n$notes"; fi
entry="$group/$title";
if [[ $user != "" && $leafUser == "TRUE" ]]; then
entry="$group/$title/$user"
fi
echo -e "$password" | pass insert --multiline --force "$entry"
test $? && echo "Added! $entry"
if [[ $url != "" && $entryURL == "TRUE" ]]; then
entry="$group/$title/url"
echo -e "$url" | pass insert --multiline --force "$entry"
test $? && echo "Added! $entry"
fi
done