Last active
December 2, 2018 13:39
-
-
Save ukazap/d56882579a5ffd261bf7878736339678 to your computer and use it in GitHub Desktop.
Import passwords from a CSV file to password store (https://www.passwordstore.org)
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
# Put this script in ~/.password-store alongside import.csv | |
# This script requires the CSV to have these columns: | |
# `title`, `username`, `password`, `additional_secret` | |
require "csv" | |
require "fileutils" | |
require "gpgme" # gem install gpgme | |
gpg_recipients = "hello@ukazap.space" | |
csv_string = File.read("import.csv") | |
csv = CSV.parse(csv_string, headers: true, col_sep: ",") | |
crypto = GPGME::Crypto.new | |
csv.each do |row| | |
FileUtils.mkdir_p "sites/#{row["title"]}" unless File.exist? "sites/#{row["title"]}" | |
filename = "sites/#{row["title"]}/#{row["username"]}.gpg" | |
puts "writing #{filename}" | |
plaintext = "#{row["password"]}\n#{row["additional_secret"]}\n" | |
encrypted = crypto.encrypt plaintext, recipients: gpg_recipients | |
File.write(filename, encrypted) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment