forked from lastpass/lastpass-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlpass-att-export.sh
executable file
·84 lines (68 loc) · 1.71 KB
/
lpass-att-export.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
##
## Usage: lpass-att-export.sh
##
##
usage() { echo "Usage: $0 [-l <email>] [-o <outdir>] [-i <id>]" 1>&2; exit 1; }
while getopts ":i:o:hl:" o; do
case "${o}" in
i)
id=${OPTARG}
;;
o)
outdir=${OPTARG}
;;
l)
email=${OPTARG}
;;
h)
usage
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${outdir}" ]; then
usage
fi
command -v lpass >/dev/null 2>&1 || { echo >&2 "I require lpass but it's not installed. Aborting."; exit 1; }
if [ ! -d ${outdir} ]; then
echo "${outdir} does not exist. Exiting."
exit 1
fi
if ! lpass status; then
if [ -z ${email} ]; then
echo "No login data found, Please login with -l or use lpass login before."
exit 1;
fi
lpass login ${email}
fi
if [ -z ${id} ]; then
ids=$(lpass ls | sed -n "s/^.*id:\s*\([0-9]*\).*$/\1/p")
else
ids=${id}
fi
for id in ${ids}; do
show=$(lpass show ${id})
attcount=$(echo "${show}" | grep -c "att-")
path=$(lpass show --format="%/as%/ag%an" ${id} | uniq | tail -1)
until [ ${attcount} -lt 1 ]; do
att=`lpass show ${id} | grep att- | sed "${attcount}q;d" | tr -d :`
attid=$(echo ${att} | awk '{print $1}')
attname=$(echo ${att} | awk '{print $2}')
if [[ -z ${attname} ]]; then
attname=${path#*/}
fi
path=${path//\\//}
mkdir -p "${outdir}/${path}"
out=${outdir}/${path}/${attname}
if [[ -f ${out} ]]; then
out=${outdir}/${path}/${attcount}_${attname}
fi
echo ${id} - ${path} ": " ${attid} "-" ${attname} " > " ${out}
lpass show --attach=${attid} ${id} --quiet > "${out}"
let attcount-=1
done
done