Export passwords to keepass
This commit is contained in:
parent
90ec8c21f0
commit
11fcfafb3b
|
@ -49,6 +49,7 @@ CURR_APP=
|
|||
REMOVE_APP=
|
||||
CURR_PASSWORD=""
|
||||
TESTS=
|
||||
EXPORT_FILENAME=
|
||||
|
||||
# If this file is present then don't store passwords
|
||||
NO_PASSWORD_STORE_FILE=~/.nostore
|
||||
|
@ -73,6 +74,7 @@ function pass_show_help {
|
|||
echo $' -u --user [name] Username'
|
||||
echo $' -a --app [name] Name of the application'
|
||||
echo $' -p --pass [password] The password to store'
|
||||
echo $' --export [filename] Export to KeepassX XML'
|
||||
echo ''
|
||||
echo $'To encrypt a password:'
|
||||
echo ''
|
||||
|
@ -145,6 +147,41 @@ function clear_passwords {
|
|||
exit 0
|
||||
}
|
||||
|
||||
function export_to_keepass {
|
||||
filename = "$1"
|
||||
|
||||
echo '<database>' > $filename
|
||||
echo ' <group>' >> $filename
|
||||
echo " <title>${PROJECT_NAME}</title>" >> $filename
|
||||
echo ' <icon>48</icon>' >> $filename
|
||||
|
||||
for d in /root/.passwords/*/ ; do
|
||||
USERNAME=$(echo "$d" | awk -F '/' '{print $4}')
|
||||
echo ' <group>' >> $filename
|
||||
echo " <title>$USERNAME</title>" >> $filename
|
||||
echo ' <icon>0</icon>' >> $filename
|
||||
for a in /root/.passwords/$USERNAME/*/ ; do
|
||||
APP_NAME=$(echo "$a" | awk -F '/' '{print $5}')
|
||||
app_password=$(${PROJECT_NAME}-pass -u $USERNAME -a $APP_NAME)
|
||||
echo ' <entry>' >> $filename
|
||||
echo " <title>$APP_NAME</title>" >> $filename
|
||||
echo " <username>$USERNAME</username>" >> $filename
|
||||
echo " <password>$app_password</password>" >> $filename
|
||||
echo ' <url/>' >> $filename
|
||||
echo ' <comment/>' >> $filename
|
||||
echo ' <icon>0</icon>' >> $filename
|
||||
echo ' <expire>Never</expire>' >> $filename
|
||||
echo ' </entry>' >> $filename
|
||||
done
|
||||
echo ' </group>' >> $filename
|
||||
done
|
||||
|
||||
echo ' </group>' >> $filename
|
||||
echo '</database>' >> $filename
|
||||
|
||||
echo $"Exported $filename"
|
||||
}
|
||||
|
||||
while [[ $# > 1 ]]
|
||||
do
|
||||
key="$1"
|
||||
|
@ -183,6 +220,10 @@ do
|
|||
shift
|
||||
CURR_APP="${1}"
|
||||
;;
|
||||
--export)
|
||||
shift
|
||||
EXPORT_FILENAME="${1}"
|
||||
;;
|
||||
-p|--pass|--password|--passphrase)
|
||||
shift
|
||||
CURR_PASSWORD="${1}"
|
||||
|
@ -211,6 +252,11 @@ if [ $TESTS ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
if [ $EXPORT_FILENAME ]; then
|
||||
export_to_keepass $EXPORT_FILENAME
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! $CURR_USERNAME ]; then
|
||||
echo $'Error: No username given'
|
||||
exit 1
|
||||
|
|
Loading…
Reference in New Issue