pass-migrate/pass-migrate.sh
Git Commiter for 96-fromsofia.net 70c3333481 First commit
2023-02-27 01:34:56 +00:00

52 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Prompt to select an option
echo -e "Please select the action you want to perform.\nAllowed options are:\n[import|export]\n"
read -a option
## EXPORTING
if [[ "$option" == "export" ]]
then
# Locate the password store
if [ -z $PASSWORD_STORE_DIR ]
then
cd ~/.password-store
else
cd $(echo $PASSWORD_STORE_DIR)
fi
# File to save the exported contents to
touch ~/.exported-passwords.txt
echo -e "Your passwords will be saved to ~/.exported-passwords.txt\nPlease wait..\n"
# Export logic
for psw in $(find . -type f -name "*.gpg" | awk -F. '{print $2}' | tr '\n' ' ' ; echo);
do
echo -e "$psw $(pass $psw)" >> ~/.exported-passwords.txt
done
echo -e "Your passwords have been exported!\nYou can now restart the script with the import function to restore them into your new device.\n"
## IMPORTING
elif [[ "$option" == "import" ]]
then
# Get the location of the file to import
echo -e "Provide the full path of the file you wish to import:\n"
read -a psw_import
# Generate 2 separate files, one for names and one for passwords
echo -e "Importing passwords.\nPlease wait..\n"
# Importing logic
while IFS= read -r line; do
name=$(printf '%s\n' "$line" | awk '{print $1}')
new_psw=$(printf '%s\n' "$line" | awk '{print $2}')
printf "%s\n%s\n" "$new_psw" "$new_psw" | pass insert $name
done < "$psw_import"
echo -e "Your passwords have been imported!\nThis script will now exit.\n"
## INVALID, EXIT
else
echo -e "Unknown action specified!!\nExiting..\n"
fi