Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk password insertion #2265

Closed
NuLL3rr0r opened this issue Jun 22, 2022 · 2 comments
Closed

Bulk password insertion #2265

NuLL3rr0r opened this issue Jun 22, 2022 · 2 comments

Comments

@NuLL3rr0r
Copy link

NuLL3rr0r commented Jun 22, 2022

Summary

This is not a bug, but a feature request. I want to import 1000s of user password from a CSV file using the following script:

#!/usr/bin/env bash

set -e

readonly AWK="$(which awk)"
readonly BASENAME="$(which basename)"
readonly CUT="$(which cut)"
readonly DIRNAME="$(which dirname)"
readonly GOPASS="$(which gopass)"

readonly SCRIPT="${BASH_SOURCE[0]}"
readonly SCRIPT_DIRECTORY=$(cd "$(${DIRNAME} -- "${0}")" >/dev/null 2>&1 ; pwd -P)
readonly SCRIPT_NAME="$(${BASENAME} -- "${SCRIPT}")"

readonly CSV_FILE="${SCRIPT_DIRECTORY}/tw-pwd.csv"
readonly USER_COLUMN=1
readonly PWD_COLUMN=2
readonly URL="twitter.com"

while IFS= read -r line
do
    USER=$(echo "${line}" | "${AWK}" -v c="${USER_COLUMN}" -F ',' '{gsub(/"/, "", $c); print $c}' | "${CUT}" -f1 -d":")
    PWD=$(echo "${line}" | "${AWK}" -v c="${PWD_COLUMN}" -F ',' '{gsub(/"/, "", $c); print $c}' | "${CUT}" -f1 -d":")

    if [[ -n "${USER}" ]] && [[ -n "${PWD}" ]]
    then
        echo -e "${PWD}\nurl: ${URL}\nusername: ${USER}" | "${GOPASS}" edit "websites/${URL}/${USER}"
    fi
done < "${CSV_FILE}"

Still not ideal, since I have to type :w per password, but I can pipe to Gopass/Neovim though upon saving it says "E32: No file name".

Steps To Reproduce

Run the script with a csv file, first column is user, seocnd one is password.

Expected behavior

I would like to build import passwords instead of manually copy pasting 1000s of user/passwords.

Environment

Linux

  • OS: Linux 5.15.48 Gentoo GNU/Linux
  • OS version: Linux mamadou-legion 5.15.48 # 32 SMP Tue Jun 21 04:18:24 CEST 2022 x86_64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz GenuineIntel GNU/Linux
  • gopass Version: 1.14.3 go1.18.2 linux amd64
  • Installation method: My own ebuilds

Additional context

@dominikschulz
Copy link
Member

Did you try gopass insert? That should work.

@NuLL3rr0r
Copy link
Author

Thank you very much sir! It did the trick and is exactly what I wanted.

#!/usr/bin/env bash

set -e

readonly AWK="$(which awk)"
readonly BASENAME="$(which basename)"
readonly CUT="$(which cut)"
readonly DIRNAME="$(which dirname)"
readonly GOPASS="$(which gopass)"

readonly SCRIPT="${BASH_SOURCE[0]}"
readonly SCRIPT_DIRECTORY=$(cd "$(${DIRNAME} -- "${0}")" >/dev/null 2>&1 ; pwd -P)
readonly SCRIPT_NAME="$(${BASENAME} -- "${SCRIPT}")"

readonly CSV_FILE="${SCRIPT_DIRECTORY}/tw-pwd.csv"
readonly USER_COLUMN=1
readonly PWD_COLUMN=2
readonly URL="twitter.com"

while IFS= read -r line
do
    USER=$(echo "${line}" | "${AWK}" -v c="${USER_COLUMN}" -F ',' '{gsub(/"/, "", $c); print $c}' | "${CUT}" -f1 -d":")
    PWD=$(echo "${line}" | "${AWK}" -v c="${PWD_COLUMN}" -F ',' '{gsub(/"/, "", $c); print $c}' | "${CUT}" -f1 -d":")

    if [[ -n "${USER}" ]] && [[ -n "${PWD}" ]]
    then
        echo "Creating gopass secret for '${USER}'..."
        echo -e "${PWD}\nurl: ${URL}\nusername: ${USER}" | "${GOPASS}" insert -m "websites/${URL}/${USER}"
    fi
done < "${CSV_FILE}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants