Skip to content

Instantly share code, notes, and snippets.

@ukazap
Last active December 2, 2018 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukazap/d56882579a5ffd261bf7878736339678 to your computer and use it in GitHub Desktop.
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)
# 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