help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Convert CSV into structure of directories, subdirectories an


From: Csányi Pál
Subject: [Help-bash] Convert CSV into structure of directories, subdirectories and files
Date: Fri, 5 Aug 2016 15:44:46 +0200

Hi,

I have a problem that can be solved by using Bash programming language.

The problem.
I have used Gorilla password manager but want to leave it and use the
pass password manager on Gentoo Linux system.
I have installed Gorilla and just installed pass.
I want to transfer passwords from Gorilla into pass.

What I did so far.
I exported my passwords from Gorilla into csv file.

There is a bash shell script on the internet
<https://github.com/d4ndo/gorilla2pass> but it is buggy a little so I
want to improve it.
This script can convert the exported csv file into directories,
subdirectories and files.
Only it does this imperfectly.

Say, in a password created in Gorilla there is the "/" symbol and the
script converts it like eg.
the password: aserv/w

directory: aserv
file: w

but it should be
file: aserv/w

In Gorilla when one want to add a new Login, then
the following fields are there:
Group:
Title:
URL:
Username:
Password:
Notes:

What I expect from this script is that that it converts
Group, eventually SubGroup,
Title,
eventually URL,
Username

into directories / subdirectories

and only
password and
notes

to files ( one file to password and one for notes).

One line in the exported csv file look like this ( seen in Midnight Commander):
.e.a.7.c.f.2.1.6.-.a.d.d.c.-.4.2.9.0.-.4.1.2.6.-.2.4.c.9.3.a.7.3.d.e.9.b.,.3.D._.P.r.i.n.t.i.n.g.N
.y.o.m.t.a.t.a.s...F.o.r.u.m.,.R.e.p.R.a.p.
.F.o.r.u.m.,.c.s.a.n.y.i.p.a.l.,.9.m.j.V.3.i.#.T.l.U.G
.a.?.H./.W.,.

The script is this:
#!/usr/bin/env bash
# Copyright (C) 2015 <address@hidden>. All Rights Reserved.
# This file is licensed under the GPLv3+. Please see LICENSE for more
information.

gorillacontainer="$1"
#User is used as leaf containting the password
leafUser="TRUE"
#Append URL to multiline password
multilineURL="FALSE"
#Append notes to multiline password
multilineNOTES="TRUE"
#Add an own entry url
entryURL="FALSE"

#"uuid,group,title,url,user,password,notes"
cat "$gorillacontainer" | sed -n '1!p' | while IFS="," read -r uuid
group title url user password notes; do

        group="$(sed -e 's/\\\./#/g' -e 's/\./\//g' -e 's/#/./g' <<< "$group")"
        title="$(sed -s 's/\s\{1,\}/_/g' <<< "$title")"

        if [[ $url != "" && $multilineURL == "TRUE" ]]; then
password="$password\n$url"; fi
        if [[ $notes != "" && $multilineNOTES == "TRUE" ]]; then
password="$password\n$notes"; fi

        entry="$group/$title";
        if [[ $user != "" && $leafUser == "TRUE" ]]; then
            entry="$group/$title/$user"
        fi
        echo -e "$password" | pass insert --multiline --force $entry
        test $? && echo "Added! $entry"
        if [[ $url != "" && $entryURL == "TRUE" ]]; then
            entry="$group/$title/url"
            echo -e "$url" | pass insert --multiline --force $entry
            test $? && echo "Added! $entry"
        fi
done

So what should I change in it to works as I wish?

-- 
Best, Pali



reply via email to

[Prev in Thread] Current Thread [Next in Thread]