Last active
March 6, 2023 08:24
-
-
Save krichprollsch/767e35449b88009eb40312ef241b1a24 to your computer and use it in GitHub Desktop.
pass2bw import pass password into bitwarden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# pass2bw creates all pass items into bitwarden. | |
# All the pass items are set in the given <BW FOLDER> argument. | |
# Pass items imported can be filtered with <PASS PATH> argument. | |
# The bw items are created with the base pass path. | |
# usage: pass2bw <BW FOLDER> <PASS PATH> | |
# example: pass2bw import_from_path/work work | |
BW_FOLDER=$1 | |
PASS_PATH=$2 | |
PASS_BASE_DIR=${HOME}/.password-store | |
# force bw sync before starting. | |
bw sync | |
# retrieve bw id folder | |
bwfolder=`bw get folder $BW_FOLDER |jq -r .id` | |
cd $PASS_BASE_DIR | |
for pitem in `find ./${PASS_PATH} -name "*.gpg" |sort` | |
do | |
iname=`echo $pitem |sed 's/^\.//' |sed 's/.gpg$//'` | |
# ignore existing bw item | |
for ename in `bw list items --search ${iname} |jq -r .[].name` | |
do | |
if [ $ename == $iname ]; then | |
echo "$iname ignore, already exists" | |
continue 2 | |
fi | |
done | |
echo "$iname create" | |
# get password value from pass | |
ivalue=`pass $iname` | |
# prepare bw login item | |
bwlogin=`bw get template item.login | \ | |
jq --arg v "$ivalue" '.password=$v' | \ | |
jq "del(.username)" | \ | |
jq "del(.totp)"` | |
# prepare bw item | |
bwitem=`bw get template item | \ | |
jq --arg v "$iname" '.name=$v' | \ | |
jq --arg v "$bwfolder" '.folderId=$v' | \ | |
jq --arg v "imported from pass" '.notes=$v' | \ | |
jq ".login=${bwlogin}"` | |
# create bw item | |
echo $bwitem |bw encode|bw create item > /dev/null | |
if [ $? -eq 1 ]; then | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment